0

I am trying to convert a large number of files from many sources into a standard format of 426x240 using ffmpeg with the following arguments:

-y -i input.mov -ac 2 -ab 96k -ar 44100 -vcodec libx264 -pix_fmt yuv420p -preset medium -threads 0 -level 1.3 -max_muxing_queue_size 1024 -b:v 438k -r 30000/1001 -s 426x240 output.mp4

Even though this command worked in the previous version of ffmpeg I was using (from many years ago) in the new version I am using (4.2.3), video is stretched to 16:9. While attempting to fix it, I found this answer with the arguments: -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black". This appears to work, though I am concerned that I am scaling the result twice, once to 1280:720, then down to 426:240. To prevent this, I found the aspect argument for pad in the documentation, but when I try to use it I get the following error:

[Parsed_pad_0 @ 00000130808eec80] Negative values are not acceptable.
[Parsed_pad_0 @ 00000130808eec80] Failed to configure input pad on Parsed_pad_0
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0

The arguments used to get this error (though I have tried numerous versions):

-y -i input.mov -ac 2 -ab 96k -ar 44100 -filter:v "pad=x=-1:y=-1:color=black:aspect=16\:9" -vcodec libx264 -pix_fmt yuv420p -preset medium -threads 0 -level 1.3 -max_muxing_queue_size 1024 -b:v 438k -r 30000/1001 -s 426x240 output.mp4

Can some please provide a working example of how to use the aspect parameter of the pad filter?

Additional details:

  • The video is from an iPhone X. The video was taken with the phone in portrait orientation. The video, when analyzed with ffprobe indicates that the rotation is 90.
  • I cannot update to the latest version due to the later versions having a dependency on MFPlat.DLL which is not available in my working environment. The new versions from gyan.dev do not have this issue.
Trisped
  • 432

2 Answers2

1

The aspect value is ideally specified as X/Y; avoid : as it is a syntax element in filtergraphs.

Your particular set of videos have an invalid sample aspect ratio. Insert setsar=1 before pad.


The easiest solution, however, is below

Add

-vf "scale=426:240:force_original_aspect_ratio=decrease,pad=426:240:-1:-1:color=black"

and remove -s 426x240

Gyan
  • 38,955
1

Imho, subfunction pad:aspect works from width for the first step, so:

ffmpeg -hide_banner -i "input 1.mp4" -filter:v "scale='if(gte(dar,16/9),426,-2)':'if(gte(dar,16/9),-2,240)', pad=426:240:'if(gte(dar,16/9),-1,(ow-iw)/2)':'if(gte(dar,16/9),-1,0)'" "output.mkv"

if greater 16/9 then "scale=426:-2, pad=426:240:-1:-1" else "scale=-2:240, pad=426:240:(ow-iw)/2:0"

edit add:

for example: width=16, height=7

pad=aspect=16/9 will evaluate height from width, pad=9-7=2, positive value

if width=16, height=12

this will evaluate pad=9-12=-3 negative value, cause of error