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.

2 Answers 2


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


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

and remove -s 426x240

  • Hi Gyan, Thanks for the answer. I am actually looking for a way to use just pad with the aspect parameter. Do you have an example on how to do that?
    – Trisped
    Oct 13, 2020 at 18:53
  • pad with aspect can't be made to reliably work here since your w and h are iw and ih (by default). It can only reliably work if your output frame is guaranteed to be larger than the input after adjusting for aspect.
    – Gyan
    Oct 13, 2020 at 19:18
  • If I understand you correctly, the aspect parameter of pad will not add padding until the image fits the indicated aspect ratio. This is confusing to me since the documentation states "Pad to aspect instead to a resolution."
    – Trisped
    Oct 13, 2020 at 19:35
  • You can consider it a defect. pad can only add pixels to the source frame not remove them. With aspect specified, ffmpeg adjusts the pad target dimensions to satisfy the aspect ratio. But it does this by reducing target dimension values. If either one or both of the adjusted values are smaller than the source, then pad will error out. You can avoid that by specifying a larger target e.g. pad=iw+6:ih+6:-1:-1:aspect=16/9
    – Gyan
    Oct 13, 2020 at 19:57
  • Hmm, that command fails with the same error, as does -vf "pad=aspect=16/9" and -vf "pad=iw+600:ih+600:-1:-1:aspect=16/9"
    – Trisped
    Oct 13, 2020 at 23:55

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

  • This works for my case, but does not answer the question "How to use aspect parameter of pad in ffmpeg?" Also, what does the -2 mean? I know the -1 means to center the image in the padding. I assume gte is greater than or equal to, dar is display aspect ratio, ow is out width, and iw is in width.
    – Trisped
    Oct 15, 2020 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.