<p>I have got it working through this way:</p>

<pre><code>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
</code></pre>

<p>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.</p>

CC BY-SA 4.0
2020-06-12T08:58:22.617Z
2020-06-12T08:58:22.617Z
Khawar Raza
<p>If your output resolution is AxB, then your filters would be</p>

<pre><code>-vf "scale=A:B:force_original_aspect_ratio=decrease,pad=A:B:-1:-1"
</code></pre>

CC BY-SA 4.0
2020-06-10T09:45:07.807Z
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
CC BY-SA 4.0
2020-06-10T16:44:20.817Z
Are A or B odd values?
Gyan
CC BY-SA 4.0
2020-06-10T18:44:08.493Z
no, both are even like 720 | 1280
Khawar Raza
CC BY-SA 4.0
2020-06-10T18:45:23.950Z
Add -report and share report.
Gyan
CC BY-SA 4.0
2020-06-12T08:59:08.190Z
Gyan, I have found the solution. You can review my answer.
Khawar Raza
CC BY-SA 4.0
2020-06-12T12:26:39.653Z
It does the same thing as my answer.
Gyan
CC BY-SA 4.0
2020-06-10T05:55:49.177Z
2020-06-10T05:55:49.177Z
Gyan
<p>I am using below command to create a slideshow using ffmpeg:</p>

<pre><code>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
</code></pre>

<p>I had to add <code>pad=ceil(iw/2)*2:ceil(ih/2)*2</code> 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?</p>

<p><strong>Edit:</strong>
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.</p>

<ffmpeg>
ffmpeg - Apply padding to input images while combining multiple images and audio track
Khawar Raza
# ffmpeg - Apply padding to input images while combining multiple images and audio track

(Asked by: username_0 on 2020-06-09)

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.

**Tags:** ffmpeg


---

## 2 answers

### Answer by username_0 on 2020-06-12. Score: 0 | Accepted answer

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.


---

### Answer by username_1 on 2020-06-10. Score: 1

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"

> **Comments:**
> **username_0**: 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  
> **username_1**: Are A or B odd values?  
> **username_0**: no, both are even like 720 | 1280  
> **username_1**: Add -report and share report.  
> **username_0**: username_1, I have found the solution. You can review my answer.  
> **username_1**: It does the same thing as my answer.  

---

