Log in

View Full Version : Odd width or height


Toguro
2nd March 2020, 20:37
Hello,

I’ve got many video files with an odd resolution (e. g: 1168 x 863), either width or height, or just only one of those.
I barely can create a single avisynth script to a video in order to resize it to a mod4 or mod16 resolution.

The question is: Is there a tool or batch script to resize lots of videos to an even resolution? (I mean, without have to interact with every single video)

X265 and others codecs don’t accept odd width or height.

Thanks in advance

Regards
:script:

videoh
2nd March 2020, 21:39
OK, I'll bite... What are these videos and where are you getting them?

FranceBB
2nd March 2020, 21:51
Is there a tool or batch script to resize lots of videos without have to interact with every single video?

Yes there is, if you know in advance which resolution you wanna go to (i.e you want all your videos to be resized to 1280x720), I strongly suggest you FrostyBorders (https://forum.doom9.org/showthread.php?p=1824455) made by hello_hello.
If you don't know which resolution you're gonna go to and you just wanna round them up according to their native resolution, you can round them up to the closest even resolution by doing something like:


clip=ColorBars(width=848, height=479)

my_initial_width=clip.Width()
my_initial_heigth=clip.Height()

i_width = my_initial_width / 2 * 2
i_height = my_initial_heigth / 2 * 2

Spline64Resize(clip, i_width, i_height)



It should work fine: Image (https://i.imgur.com/tBYcL6n.png)

As a side note for those who "know" me here on Doom9, if you take a sneaky peek at my AVSPmod tabs you can see that although I'm a broadcast encoder and I use Avisynth at work on a daily basis, whenever I'm at home I still do some pretty bad things once in a while, like fansubbing

Again, Avisynth is a wonderful frameserver for those things. *_*


OK, I'll bite... What are these videos and where are you getting them?

I wonder whether there are some crappy chinese mobile phones that record at weird resolutions...
Dunno, now I'm curious about where he's getting them as well. xD

StainlessS
3rd March 2020, 01:17
Maybe dont bother with resize, just crop to multiple of required.

Untested

AviSource("...")
XMOD=4 # Req X multiple
YMOD=4 # Req Y multiple
W=Width/XMOD*XMOD
H=Height/YMOD*YMOD
Crop(0,0,W,H) # Spline36Resize(W,H)
return Last

hello_hello
3rd March 2020, 08:41
Yes there is, if you know in advance which resolution you wanna go to (i.e you want all your videos to be resized to 1280x720), I strongly suggest you FrostyBorders (https://forum.doom9.org/showthread.php?p=1824455) made by hello_hello.

Thanks for the plug, but I should point out... the borders won't be frosty unless they're at least 16 pixels wide. It'll add plain borders instead. Or you can specify Frosty=false and it'll always add plain borders.

You can also do it with CropResize (https://forum.doom9.org/showthread.php?t=176667). If you specify just the width it'll resize the height accordingly (and crop a little if need be). The default is mod4. Or you can specify just the height. Either way if you specify a width (or height), you must make sure they're the correct mod yourself. The script only uses the mod option when they're un-specified.

Based on the example in the OP (1168x863), this would give you an output of 976x720.
CropResize(0,720, Mod=8)
This would give you 1280x944 (using the default of Mod=4 for the height).
CropResize(1280,0)
If you're happy to resize down to the nearest mod height, with the width resized to match (and cropped a little if need be), this would give you 1152x848.
CropResize(Mod=16)
Or for cropping-only you get 1168x848.
CropResize(Mod=16, NoResize=true)

Unless you want to check each source, only specify the width, or only specify the height. If you specify both and they don't match the source aspect ratio, such as 640x480 for a source that's 16:9, the script will crop it to 4:3 before resizing to 640x480, so you'd lose a lot of picture (unless you enable borders).

Toguro
3rd March 2020, 13:49
clip=ColorBars(width=848, height=479)

my_initial_width=clip.Width()
my_initial_heigth=clip.Height()

i_width = my_initial_width / 2 * 2
i_height = my_initial_heigth / 2 * 2

Spline64Resize(clip, i_width, i_height)


It should work fine: Image (https://i.imgur.com/tBYcL6n.png)



Maybe dont bother with resize, just crop to multiple of required.

Untested

AviSource("...")
XMOD=4 # Req X multiple
YMOD=4 # Req Y multiple
W=Width/XMOD*XMOD
H=Height/YMOD*YMOD
Crop(0,0,W,H) # Spline36Resize(W,H)
return Last


It works!. Sorry, I didn't know that an avisynth script could do that, mathematical operations like those. I suposse that the mark (/) return the leftover (module) of the division, like Python...

By the way, this script is only possible with AviSource? And LWLibavVideoSource or DirectShowSource? I get errors with LWLibavVideoSource...

I got these video clips from recording my screen with third party software, and that software uses some kind buggy codec.

Thank you all, guys. Problem solved :thanks:

hello_hello
3rd March 2020, 15:41
It works!. Sorry, I didn't know that an avisynth script could do that, mathematical operations like those. I suposse that the mark (/) return the leftover (module) of the division, like Python...

/ is division. When you divide integers, Avisynth returns an integer (rounded down), so when you multiply the result by the same integer you get the desired mod. ie If you want mod16.

1276 / 16 = 79
79 × 16 = 1264

If the numbers aren't integers, you can do the same thing this way:

floor(1276.0 / 16.0) * 16

Avisynth math functions:
http://avisynth.nl/index.php/Internal_functions#Numeric_functions

For some reason only the FMod function is listed there. There's a mod function for integers that uses "%".

17 % 2 = 1

Ah... apparently it's an operator rather than a function.
http://avisynth.nl/index.php/Operators

By the way, this script is only possible with AviSource? And LWLibavVideoSource or DirectShowSource? I get errors with LWLibavVideoSource...

It should work for any source. What's the error?

StainlessS
3rd March 2020, 16:09
As Hello_Hello said.

when you first learnt how to divide, you did not produce fractional numbers, but something like

1276 / 16 = 79 remainder 12

so for integers

1276 / 16 = 79
1276 % 16 = 12

If either one of the numbers is a float, then the other one is also converted to float, where result is a float. [goes for +, -, *, and /]

Toguro
5th March 2020, 13:53
As Hello_Hello said.

when you first learnt how to divide, you did not produce fractional numbers, but something like

1276 / 16 = 79 remainder 12

so for integers

1276 / 16 = 79
1276 % 16 = 12

If either one of the numbers is a float, then the other one is also converted to float, where result is a float. [goes for +, -, *, and /]

Thanks StainlessS

/ is division. When you divide integers, Avisynth returns an integer (rounded down), so when you multiply the result by the same integer you get the desired mod. ie If you want mod16.

1276 / 16 = 79
79 × 16 = 1264

If the numbers aren't integers, you can do the same thing this way:

floor(1276.0 / 16.0) * 16

Avisynth math functions:
http://avisynth.nl/index.php/Internal_functions#Numeric_functions

For some reason only the FMod function is listed there. There's a mod function for integers that uses "%".

17 % 2 = 1

Ah... apparently it's an operator rather than a function.
http://avisynth.nl/index.php/Operators



It should work for any source. What's the error?

x265 [warning]: Source height < 720p; disabling lookahead-slices
avs [error]: Filter Error: Attempted to request a planar frame that wasn't mod2 in height! occurred while reading frame 0

LWLibavVideoSource(Clip+".avi", format="YUV420P8")

XMOD=4 # Req X multiple
YMOD=4 # Req Y multiple
W=Width/XMOD*XMOD
H=Height/YMOD*YMOD
Crop(0,0,W,H) # Spline36Resize(W,H)

return Last

In AviSource, works like a charm...
Thanks

hello_hello
6th March 2020, 07:56
avs [error]: Filter Error: Attempted to request a planar frame that wasn't mod2 in height! occurred while reading frame 0

It's probably because the height is mod1, and you're asking Lsmash to convert to YV12, which requires mod2. I assume the source is RGB? Try this instead:

LWLibavVideoSource(Clip+".avi")

XMOD=4 # Req X multiple
YMOD=4 # Req Y multiple
W=Width/XMOD*XMOD
H=Height/YMOD*YMOD
Crop(0,0,W,H) # Spline36Resize(W,H)

ConvertToYV12(matrix="rec709")
return Last

ConvertToYV12(matrix="rec709") assumes the source is RGB and high definition. If it's YUV or SD, or the conversion changes the colors a little, try ConvertToYV12() instead.
http://avisynth.nl/index.php/Convert

AviSource or DirectshowSource could be doing something you're not seeing because you're cropping, such as displaying the bottom line of the picture as green and/or duplicating it for mod2.

wonkey_monkey
6th March 2020, 10:47
AviSource or DirectshowSource could be doing something you're not seeing

Or it could just be returning RGB.

StainlessS
6th March 2020, 13:36
I should perhaps have included the ConvertToYV12(Matrix="???"), after either crop or resize,
if doing convert before crop/resize, then there would likely be another prob because YV12 requires at least mod 2 [4 vertical for interlaced].

Toguro
6th March 2020, 14:39
I don't know if it's RGB. Regarding MediaInfo:

Video
ID : 0
Format : FICV
Codec ID : FICV
Duration : 39 s 317 ms
Bit rate : 25.9 Mb/s
Width : 1 680 pixels
Height : 1 050 pixels
Display aspect ratio : 16:10
Frame rate : 60.000 FPS
Bits/(Pixel*Frame) : 0.245
Stream size : 121 MiB (95%)

So, I assume it is RGB...I used to stick up with

AviSource(Clip+".avi", pixel_type="+FULL", fourCC="FICV")

Anyway, ConvertToYV12(matrix="rec709") works flawlessly.
I very appreciate it, guys. Thank you all
:thanks:

StainlessS
6th March 2020, 15:19
Never heard of FOURCC 'FICV', but according to K-Lite is Mirillis FIC.
You can insert a "return Info" immediately after avisource to show some clip details.

Toguro
6th March 2020, 18:16
That's correct, it's mirillis action.

AviSOurce(Clip+".avi")
# LWLibavVideoSource(Clip+".avi")
return Info #before Convert in order to know color space

ConvertToYV12(matrix="rec709")

returns

avs [info]: AviSynth+ 3.4 (r2923, 3.4, i386)
avs [warning]: Converting input clip to YV12
avs [info]: Video resolution: 1400x960
avs [info]: Video framerate: 60/1
avs [info]: Video framecount: 3689

Nevermind, ConvertToYV12(matrix="rec709") works.