6

I need to batch-process a bunch of videos to scale their height to 240 keeping the aspect ratio same. The command that gets the job almost done is:

$ 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 on videos where the scaled output width turns out to be an even number. Otherwise, I get the following error message:

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

How do I overcome this?

Edit: As per this link, I tried using -vf "scale=trunc(oh/a/2)*2:240" which outputs a movie but the resulting video quality is really poor.

Edit #2: This is not a duplicate as it's wrongly marked. This question was posted much earlier than the other one.

S B
  • 8,134
  • 10
  • 54
  • 108
  • As for the duplicate it doesn't really matter which question is older. Typically, the question with fewer votes gets marked as the duplicate. – llogan Dec 08 '16 at 03:56
  • @LordNeckbeard That makes sense too, but contradicts SO's own definition in the box above, particularly - "marked as duplicate... This question has been asked before and already has an answer". – S B Dec 08 '16 at 06:03
  • The intention was to understand SO's guidelines, not argue who is first. But if it sounded so, I'll stop here. – S B Dec 08 '16 at 20:52

1 Answers1

8

Update; you can now use:

-vf scale=-2:240

Is there a good list of mp4 supported resolutions and a way to have ffmpeg calculate the width after modifying by set height ratio?


The link actually says:

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

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

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

Math behind it:

iw   ow
-- = --
ih   oh

ow = (iw * oh) / ih
ow = oh * a
Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407