0

I am using below command to create a slideshow using ffmpeg:

ffmpeg -r 1 -i IMG_%04d.jpeg -i audio.mp3 -c:v libx264 -c:a aac -pix_fmt yuv420p -r 24 -y output.mp4 -vf pad=ceil(iw/2)*2:ceil(ih/2)*2

I had to add pad=ceil(iw/2)*2:ceil(ih/2)*2 to make width or height even number because if one of the input image width/height is odd, ffmpeg throws error. Now my problem is; input images can be of different resolution and aspect ratio. I want to add padding (left/right or top/bottom) to all images to make them of equal size before they are converted into video frames. How can I achieve this in efficient way?

Edit: It would be nice if I can specify output resolution and all images are either scaled down or up keeping their aspect ratio intact according to that resolution.

0

If your output resolution is AxB, then your filters would be

-vf "scale=A:B:force_original_aspect_ratio=decrease,pad=A:B:-1:-1"
| improve this answer | |
  • Getting this error in logs: Getting Negative values are not acceptable. Failed to configure input pad on Parsed_pad_1. Error reinitializing filters! Failed to inject frame into filter network: Invalid argument. rror while processing the decoded data for stream #0:0 – Khawar Raza Jun 10 at 9:45
  • Are A or B odd values? – Gyan Jun 10 at 16:44
  • no, both are even like 720 | 1280 – Khawar Raza Jun 10 at 18:44
  • Add -report and share report. – Gyan Jun 10 at 18:45
  • Gyan, I have found the solution. You can review my answer. – Khawar Raza Jun 12 at 8:59
0

I have got it working through this way:

ffmpeg -r 1 -i image%4d.png -i audio.mp3 -filter_complex scale=w=%d:h=%d:force_original_aspect_ratio=1,pad=%d:%d:(ow-iw)/2:(oh-ih)/2 -c:v libx264 -c:a aac -pix_fmt yuv420p -r 1 -y output.mp4

This way aspect ratio of input images remain intact and also it solves odd image width/height issue. I hope this answer would help other users facing same issue.

| improve this answer | |

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.