Error scaling video using libav filters

I need to batch process a bunch of videos to increase their height to 240, while maintaining aspect ratio. The team that almost completed the job:

$ avconv -threads 4 -ss 0.0 -i input.avi \ -map 0:0,0:0 -map 0:1,0:1 -vf "scale=-1:240" -y -f mpegts \ -async -1 -vcodec libx264 -vcodec libx264 -flags2 +fast \ -flags +loop -g 30 -bufsize 1024k \ -b 200k -bt 220k -qmax 48 -qmin 2 -r 20 -acodec libmp3lame \ -ab 44k -ar 44100 -ac 2 output.ts 

The interesting part, as you can see, is -vf "scale=-1:240"

This works with video where the scaled width of the output image is even. Otherwise, you receive the following error message:

 [libx264 @ 0x7fc4f8821e00] width not divisible by 2 (341x240) 

How can I overcome this?

Edit: According to this link , I tried to use -vf "scale=trunc(oh/a/2)*2:240" , which displays the movie, but as a result the video quality is very poor.

Edit # 2: This is not a duplicate because it is incorrectly marked. This question was published much earlier than another.

+6
source share
1 answer

Update; now you can use:

 -vf scale=-2:240 

Is there a good list of supported mp4 permissions and a way for ffmpeg to calculate the width after changing from a given height ratio?


The link actually says:

 scale="854:trunc(ow/a/2)*2" 

which scales the height correctly to an even number, if you want to scale the width you should use this idiom:

 -vf scale="trunc(oh*a/2)*2:240" # ^ # / # notice --- 

The math behind her:

 iw ow -- = -- ih oh ow = (iw * oh) / ih ow = oh * a 
+8
source

Source: https://habr.com/ru/post/944366/


All Articles