Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd March 2020, 20:37   #1  |  Link
Toguro
Registered User
 
Join Date: Jul 2013
Posts: 9
Odd width or height

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
Toguro is offline   Reply With Quote
Old 2nd March 2020, 21:39   #2  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,668
OK, I'll bite... What are these videos and where are you getting them?
videoh is offline   Reply With Quote
Old 2nd March 2020, 21:51   #3  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Metropolitan City of Milan, Italy
Posts: 2,119
Quote:
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 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:

Code:
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

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. *_*


Quote:
Originally Posted by videoh View Post
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

Last edited by FranceBB; 2nd March 2020 at 21:59.
FranceBB is offline   Reply With Quote
Old 3rd March 2020, 01:17   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,080
Maybe dont bother with resize, just crop to multiple of required.

Untested
Code:
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
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 3rd March 2020, 08:41   #5  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,610
Quote:
Originally Posted by FranceBB View Post
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 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. 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).

Last edited by hello_hello; 3rd March 2020 at 08:56.
hello_hello is offline   Reply With Quote
Old 3rd March 2020, 13:49   #6  |  Link
Toguro
Registered User
 
Join Date: Jul 2013
Posts: 9
Quote:
Originally Posted by FranceBB View Post
Code:
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
Quote:
Originally Posted by StainlessS View Post
Maybe dont bother with resize, just crop to multiple of required.

Untested
Code:
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
Toguro is offline   Reply With Quote
Old 3rd March 2020, 15:41   #7  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,610
Quote:
Originally Posted by Toguro View Post
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/Interna...eric_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

Quote:
Originally Posted by Toguro View Post
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?

Last edited by hello_hello; 3rd March 2020 at 15:52.
hello_hello is offline   Reply With Quote
Old 3rd March 2020, 16:09   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,080
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 /]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 3rd March 2020 at 16:13.
StainlessS is offline   Reply With Quote
Old 5th March 2020, 13:53   #9  |  Link
Toguro
Registered User
 
Join Date: Jul 2013
Posts: 9
Quote:
Originally Posted by StainlessS View Post
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

Quote:
Originally Posted by hello_hello View Post
/ 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/Interna...eric_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

Quote:
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
Toguro is offline   Reply With Quote
Old 6th March 2020, 07:56   #10  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,610
Quote:
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:

Quote:
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.

Last edited by hello_hello; 6th March 2020 at 08:00.
hello_hello is offline   Reply With Quote
Old 6th March 2020, 10:47   #11  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,369
Quote:
Originally Posted by hello_hello View Post
AviSource or DirectshowSource could be doing something you're not seeing
Or it could just be returning RGB.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 6th March 2020, 13:36   #12  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,080
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].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 6th March 2020, 14:39   #13  |  Link
Toguro
Registered User
 
Join Date: Jul 2013
Posts: 9
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

Quote:
AviSource(Clip+".avi", pixel_type="+FULL", fourCC="FICV")
Anyway, ConvertToYV12(matrix="rec709") works flawlessly.
I very appreciate it, guys. Thank you all
Toguro is offline   Reply With Quote
Old 6th March 2020, 15:19   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,080
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.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 6th March 2020, 18:16   #15  |  Link
Toguro
Registered User
 
Join Date: Jul 2013
Posts: 9
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

Quote:
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.
Toguro is offline   Reply With Quote
Reply

Tags
odd

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:05.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.