Log in

View Full Version : StaxRip cut one pixel border


Flyk3
9th March 2024, 11:35
Hi all,

I have videos where there are black borders one pixel thick at the top and bottom. Normally I would leave these in when I encode, but I wonder if there might be a solution after all.

When I try to remove a pixel at the top and bottom with the crop function in StaxRip, I get the following error message:

Crop: YUV image can only be cropped by Mod 2 (top)

Is there another option? Adding a bar with one pixel and then cutting 2 pixels doesn't work either.

Maybe it is possible to move the video up one pixel without the bars
and then cut 2 pixels at the bottom?

Atak_Snajpera
9th March 2024, 12:18
ConvertToRGB
Crop(0,1,0,-1)
ConvertToYv12

Flyk3
6th October 2024, 22:09
Thank you very much, worked fine for me.

Do you also have an idea how to crop 10bit videos? ConvertToRGB leads to the error message "ConvertToRGB: conversion is allowed only from 8 or 16 bit colorspaces"

poisondeathray
7th October 2024, 02:36
Do you also have an idea how to crop 10bit videos? ConvertToRGB leads to the error message "ConvertToRGB: conversion is allowed only from 8 or 16 bit colorspaces"


ConvertToYUV444()
Crop(0,1,0,-1)
ConvertToYUV420() #assuming you want 4:2:0

hello_hello
7th October 2024, 07:10
You can use a resizer to crop a single pixel or less, although the dimensions would still need to be at least mod2.
I'm not sure it'd remove the lines completely though. It'd depend on the value of the chroma samples at the edges. Then again, the same probably applies to converting to YUV444 or RGB and back in order to crop.

If the source video was 1280x720, for example.
Spline36Resize(1280,718, 0,1,0,-1)

Depending on the resizer, the luma (Y) seems to remain untouched either way.

A = ConvertToYUV444().Crop(0,1,0,-1).ConvertToYUV420().ExtractY()
B = Spline36Resize(1280,718, 0,1,0,-1).ExtractY()
Compare(A, B)

https://imgur.com/fE57hPI.png

The result for the chroma would be different, as if you're not converting to YUV444 and back it would only be resampled once.

A = ConvertToYUV444().Crop(0,1,0,-1).ConvertToYUV420().ExtractU()
B = Spline16Resize(1280,718, 0,1,0,-1).ExtractU()
Compare(A, B)

https://imgur.com/h4Tlrsa.png

Out of curiosity though, does anyone know why not every resizer appears to leave the luma intact, namely GaussResize with a "P" value less than 100 and also BicubicResize? I would've thought that if you're cropping whole pixels and the output dimensions are the same as the cropped dimensions, the resizers should always leave it alone.

A = ConvertToYUV444().Crop(0,1,0,-1).ConvertToYUV420().ExtractY()
B = BicubicResize(1280,718, 0,1,0,-1).ExtractY()
Compare(A, B)

https://imgur.com/sFpBBAW.png


Or maybe to be certain the luma is only cropped? :)
Once again assuming a 1280x720 source.

Video = last
Y = Video.ExtractY().Crop(0,1,0,-1)
U = Video.ExtractU().BicubicResize(640,359, 0, 0.5, 0, -0.5)
V = Video.ExtractV().BicubicResize(640,359, 0, 0.5, 0, -0.5)
CombinePlanes(Y, U, V, planes="YUV", source_planes="YYY", pixel_type="YUV420")

tormento
7th October 2024, 18:15
Out of curiosity though, does anyone know why not every resizer appears to leave the luma intact
If I am not wrong, I read something about color space and gamma support, such as ResampleHQ (http://avisynth.nl/index.php/ResampleHQ).

hello_hello
11th October 2024, 21:56
I don't think it'd be that, because the Avisynth resizers don't mess with the color space or gamma, they just resize as far as I know.

This is what it says on the Avisynth wiki:
http://avisynth.nl/index.php/Resize#Notes
AviSynth has completely separate vertical and horizontal resizers. If input is the same as output on one axis, that resizer will be skipped. The resizer with the smallest downscale ratio is called first; this is done to preserve maximum quality, so the second resizer has the best possible picture to work with.

The "resizer will be skipped" part seems to be correct, except for BicubicResize and GaussResize, although if P=100 for GaussResize, then it does seem leave the video untouched when it's not having to resize.

tormento
12th October 2024, 10:43
I don't think it'd be that, because the Avisynth resizers don't mess with the color space or gamma, they just resize as far as I know.
If so, why has that script ever made?

hello_hello
12th October 2024, 13:37
Do you mean ResampleHQ?
Because it's possibly technically more correct to resize in linear light, so RessampleHQ would (I assume) convert from gamma-compressed YUV to linear light RGB, do the resizing, then convert back to gamma‐compressed YUV.
Avisynth's resizers just resize without doing any of that. Is that what you're asking?

tormento
14th October 2024, 11:52
Avisynth's resizers just resize without doing any of that.
And is it correct? If not, wouldn't be better to always resize like that?

hello_hello
15th October 2024, 08:55
I never downscale enough to worry about it myself, plus is does involve converting to RGB and back, which isn't lossless even if you weren't resizing.
I did experiment a bit with linear light resizing quite a while ago. I managed to find the post at VideoHelp where I uploaded some screenshots, so I'll repost the images as links here.
The 1440x1080 source was downscaled to 480x360 with various resizers and then upscaled to 1440x1080 again using Spline36Resize. One thing I did notice was linear light resizing tended to make the lines more jagged after the video was upscaled again. I don't know why, although I did find a setting using DitherTools that seemed to help with that. It's animation, and the main difference is in the high contrast areas, such as the white lines used to show the smoke from the pitcher's cigar in this example.

Source
https://forum.videohelp.com/attachment.php?attachmentid=61901

CropResize(480,360, 242,0,-242,0, Resizer="Spline36")
Spline36Resize(1440,1080)
https://forum.videohelp.com/attachment.php?attachmentid=61902

CropResize(480,360, 242,0,-242,0, Resizer="DitherToolsLinear")
Spline36Resize(1440,1080)
https://forum.videohelp.com/attachment.php?attachmentid=61903

CropResize(480,360, 242,0,-242,0, Resizer="FMTConvLinear")
Spline36Resize(1440,1080)
https://forum.videohelp.com/attachment.php?attachmentid=61904

CropResize(480,360, 242,0,-242,0, Resizer="ResampleHQ")
Spline36Resize(1440,1080)
https://forum.videohelp.com/attachment.php?attachmentid=61907

Not much difference between the linear light resizing methods above, but they do retain detail in high contrast areas more then just downscaling with Spline26Resize.

The DitherTools settings that didn't make the lines more jagged than downscaling with Spline36Resize were:

CropResize(480,360, 242,0,-242,0, Resizer="DitherToolsLinear", RStr=""" SigmoidS=true, CurveS="1886" """)
Spline36Resize(1440,1080)
https://forum.videohelp.com/attachment.php?attachmentid=61942

I think you'd really do need to downscale quite a lot to care about linear light resizing.

For the record, these are the DitherTools and FMTConv functions I used.

function DitherToolsLinear(clip Source, \
int Width, int Height, float "src_left", float "src_top", float "src_width", float "src_height", \
string "Kernel", string "CurveS", string "CurveD", float "GCorS", float "GCorD", \
bool "SigmoidS", bool "SigmoidD", float "ThrS", float "ThrD", float "ContS", float "ContD", \
bool "LSBIn", bool "LSBOut") {

Kernel = default(Kernel, "Spline36")
CurveS = default(CurveS, "709")
CurveD = default(CurveD, CurveS)
GCorD = default(GCorD, GCorS)
SigmoidS = default(SigmoidS, false)
SigmoidD = default(SigmoidD, SigmoidS)
ThrD = default(ThrD, ThrS)
ContD = default(ContD, ContS)
LSBIn = default(LSBIn, false)
LSBOut = default(LSBOut, LSBIn)

Input = !LSBIn ? Source.Dither_convert_8_to_16() : Source

Resized = Input\
.Dither_y_gamma_to_linear(curve=CurveS, gcor=GCorS, sigmoid=SigmoidS, thr=ThrS, cont=ContS)\
.Dither_resize16(Width, Height, src_left, src_top, src_width, src_height, kernel=Kernel)\
.Dither_y_linear_to_gamma(curve=CurveD, gcor=GCorD, sigmoid=SigmoidD, thr=ThrD, cont=ContD)

Resized = !LSBOut ? Resized.DitherPost() : Resized

return Resized }

function FMTConvLinear(clip Source, int Width, int Height, \
float "src_left", float "src_top", float "src_width", float "src_height", \
string "Kernel", string "CurveS", string "CurveD") {

Kernel = default(Kernel, "Spline36")
CurveS = default(CurveS, "709")
CurveD = default(CurveD, CurveS)

Resized = Source\
.fmtc_bitdepth(bits=16)\
.fmtc_resample(css="444")\
.fmtc_matrix(mat=CurveS)\
.fmtc_transfer(transs=CurveS, transd="Linear")\
.fmtc_resample(Width, Height, sx=src_left, sy=src_top, sw=src_width, sh=src_height, kernel=Kernel)\
.fmtc_transfer(transs="Linear", transd=CurveD)\
.fmtc_matrix(mat=CurveD)\
.fmtc_resample(css="420")\
.fmtc_bitdepth(bits=8)

return Resized }