Answers.Body: <p>There is a way to achieve this result that may be more relevant to your interests:</p>
  
  <p><strong>Problem</strong>: Resize videos centering them in the middle of a pre-determined rectangle, letterboxing if needed. </p>
  
  <p><strong>Answer</strong>: <a href="https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player">https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player</a></p>
  
  <p>The key line from the answer:</p>
  
  <pre><code>ffmpeg -i input -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-27T22:57:03.583Z
Answers.LastActivityDate: 2018-12-27T22:57:03.583Z
Answers.UserDisplayName: Boris Yakubchik
Answers.Body: <p>First, setup a color filter of the same height, and then add it to the hstack</p>
  
  <pre><code>-filter_complex "color=black:5x240[c];[v1][c][v2]hstack=inputs=3:shortest=1[videoout]"
  </code></pre>
  
  <p>See the options for the color filter <a href="https://ffmpeg.org/ffmpeg-utils.html#Color" rel="nofollow">here</a>.</p>
  
  <hr>
  
  <p>Alternate method is</p>
  
  <pre><code>-filter_complex "[0]pad=iw+5:ih:color=black[0v];[0v][v2]hstack[videoout]"
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T11:44:16.013Z
Answers.Text: I added this filter, and now my video grows endlessly. Before I had a 20 second video, and now I had to interrupt the process, because it grew without limit...
Answers.UserDisplayName: Enrique Moreno Tent
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T11:56:42.320Z
Answers.Text: Now I get a "Option 'shortest' not found"
Answers.UserDisplayName: Enrique Moreno Tent
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T12:03:24.063Z
Answers.Text: `shortest=1` works here. Recheck for typos..etc.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T12:05:41.973Z
Answers.Text: It does not... ffmpeg version? Mine is 2.8.6
Answers.UserDisplayName: Enrique Moreno Tent
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T12:07:13.023Z
Answers.Text: You need a build from Dec 2015 or later. Use alt method instead.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T13:25:29.047Z
Answers.Text: The 2nd option "pad" seems to work alright, but just makes the padding on the bottom or the right. How would it be, if I wanted to pad the top or the left side? Or all at the same time?
Answers.UserDisplayName: Enrique Moreno Tent
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T13:33:25.887Z
Answers.Text: The syntax of pad is `W:H:x:y:color`, where W and H set the size of the new canvas, and x,y defines where the original video is placed in the canvas, measured from the top-left. Default for x,y is 0. So, `pad=iw+10:ih+12:4:7` creates a canvas 10 pixels wider and 12 pixels taller than the input and leaves padding of 4 pixels on the left, 6 on the right, 7 on the top and 5 on the bottom. Default color is black.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-14T11:17:16.770Z
Answers.LastActivityDate: 2016-05-14T12:00:23.467Z
Answers.LastEditDate: 2016-05-14T12:00:23.467Z
Answers.UserDisplayName: Gyan
Body: <p>I am using the following <code>filter_complex</code> to put 2 videos of resolution <code>320 x 240</code>, one right next to the other:</p>
  
  <pre><code>-filter_complex "[v1][v2]hstack=inputs=2[videoout]"
  </code></pre>
  
  <p>This works great, but now I was wondering how could I do it, so that I could add a small padding between them. Let's say for instance 5 black pixels (even though I would love to be able to customize the color or at least the distance).</p>
  
  <p>How could I do that?</p>
  
Tags: <ffmpeg>
Title: Add black (or other color) padding when doing vstack (or hstack)
UserDisplayName: Enrique Moreno Tent
ThreadText: # Add black (or other color) padding when doing vstack (or hstack)
  
  (Asked by: username_0 on 2016-05-14)
  
  I am using the following `filter_complex` to put 2 videos of resolution `320 x 240`, one right next to the other:
  
  ```
  -filter_complex "[v1][v2]hstack=inputs=2[videoout]"
  
  ```
  
  This works great, but now I was wondering how could I do it, so that I could add a small padding between them. Let's say for instance 5 black pixels (even though I would love to be able to customize the color or at least the distance).
  
  How could I do that?
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-05-14. Score: 4 | Accepted answer
  
  First, setup a color filter of the same height, and then add it to the hstack
  
  ```
  -filter_complex "color=black:5x240[c];[v1][c][v2]hstack=inputs=3:shortest=1[videoout]"
  
  ```
  
  See the options for the color filter [here](https://ffmpeg.org/ffmpeg-utils.html#Color).
  
  ---
  
  Alternate method is
  
  ```
  -filter_complex "[0]pad=iw+5:ih:color=black[0v];[0v][v2]hstack[videoout]"
  
  ```
  
  > **Comments:**
  > **username_0**: I added this filter, and now my video grows endlessly. Before I had a 20 second video, and now I had to interrupt the process, because it grew without limit...  
  > **username_0**: Now I get a "Option 'shortest' not found"  
  > **username_2**: `shortest=1` works here. Recheck for typos..etc.  
  > **username_0**: It does not... ffmpeg version? Mine is 2.8.6  
  > **username_2**: You need a build from Dec 2015 or later. Use alt method instead.  
  > **username_0**: The 2nd option "pad" seems to work alright, but just makes the padding on the bottom or the right. How would it be, if I wanted to pad the top or the left side? Or all at the same time?  
  > **username_2**: The syntax of pad is `W:H:x:y:color`, where W and H set the size of the new canvas, and x,y defines where the original video is placed in the canvas, measured from the top-left. Default for x,y is 0. So, `pad=iw+10:ih+12:4:7` creates a canvas 10 pixels wider and 12 pixels taller than the input and leaves padding of 4 pixels on the left, 6 on the right, 7 on the top and 5 on the bottom. Default color is black.  
  
  ---
  
  ### Answer by username_1 on 2018-12-27. Score: 1
  
  There is a way to achieve this result that may be more relevant to your interests:
  
  **Problem**: Resize videos centering them in the middle of a pre-determined rectangle, letterboxing if needed.
  
  **Answer**: <https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player>
  
  The key line from the answer:
  
  ```
  ffmpeg -i input -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output
  
  ```
  
  
  ---
  
  