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.
aspectspecified, 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 '20 at 19:57-vf "pad=aspect=16/9"and-vf "pad=iw+600:ih+600:-1:-1:aspect=16/9"– Trisped Oct 13 '20 at 23:55setsar=1before pad. No need to add any offset in pad so iw / ih are fine with aspect. – Gyan Oct 22 '20 at 06:16