<h2>Adding Bars</h2>

<p>You can do it with a combination of the <em><a href="https://ffmpeg.org/ffmpeg-filters.html#crop" rel="noreferrer">crop</a></em> &amp; <em><a href="https://ffmpeg.org/ffmpeg-filters.html#pad" rel="noreferrer">pad</a></em> video filters:</p>

<pre><code>-filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30"
</code></pre>

<p>Both filters use the same format: <em>width:height:x-offset:y-offset</em></p>

<p>In the <em>crop</em> filter, you want width to be same as the video's input width (you can use the variable <strong><em>in_w</em></strong>). You want to crop 60 pixels (30*2) from the input height (<em>in_h-60</em>). X offset stays at zero so nothing is changed horizontally. And set the Y offset to 30 so that 30 pixels are cropped from the top &amp; bottom each. Otherwise, it will just crop 60 pixels from the bottom.</p>

<p>In the <em>pad</em> filter, the <strong><em>in_w</em></strong> &amp; <strong><em>in_h</em></strong> variables will be whatever is output from the <em>crop</em> filter (you can just replace these with the actual video dimensions if you prefer). Use <strong><em>in_w</em></strong> again to preserve horizontal dimension. Add 60 black pixels back to the vertial dimension (<em>in_h+60</em>). Leave the X offset at <em>0</em> &amp; set Y offset to <em>-30</em> so pixels are added at top &amp; bottom. Otherwise, it will just add 60 pixels to bottom.</p>

<p>The other option, as I think @Quertiy was pointing out, is to create a PNG image the same dimensions as your video with black bars at the top &amp; bottom, &amp; transparent in the middle, then overlay it onto the image:</p>

<pre><code>ffmpeg -i video.mp4 -i overlay.png -filter_complex "overlay" -c:v libx264 "out.mp4"
</code></pre>

<p>It may be wise to list the streams in the filter arguments: <code>-filter_complex "[0:0][1:0]overlay"</code></p>

<hr>

<h2>Multiple Files</h2>

<p>If you were using a Unix shell (I believe this is what MacOS uses), you could use a <em>for</em> loop to convert all videos in a directory:</p>

<pre><code>for V in *; do ffmpeg -i "$V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-$V"; done
</code></pre>

<p>But I'm not sure what the equivalent is using the Windows command prompt.</p>

<p><strong>Edit:</strong> <a href="http://www.informit.com/articles/article.aspx?p=1154761&amp;seqNum=10" rel="noreferrer">Windows command prompt has a <em>for</em> loop as well</a>. So it should be something like:</p>

<pre><code>for %V in (*) do ffmpeg -i "%V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-%V"
</code></pre>

<p>But, I haven't tested it.</p>

<p><strong>Note:</strong> Use <strong><em>%%V</em></strong> within batch files, <strong><em>%V</em></strong> if using the command prompt directly.</p>

<p><strong>Edit:</strong> According to <a href="https://www.mssqltips.com/sqlservertip/2754/parsing-all-the-files-in-a-directory-using-powershell/" rel="noreferrer">this article</a>, you should be able to do it in Windows PowerShell like this:</p>

<pre><code>foreach ($V in Get-ChildItem .\) {ffmpeg -i "$V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-$V"}
</code></pre>

<p>Again, I haven't fully tested it.</p>

CC BY-SA 4.0
2019-02-13T06:06:49.950Z
Somewhat faster would be to apply drawbox twice. `drawbox=iw:30:0:0:t=fill,drawbox=iw:30:0:ih-30:t=fill`
Gyan
CC BY-SA 4.0
2022-01-06T09:45:26.073Z
This really helped blacking out subtitles when I needed to re-sub. in another language.
mbx
CC BY-SA 4.0
2019-02-13T04:13:00.140Z
2019-02-13T05:04:08.280Z
2019-02-13T05:04:08.280Z
AntumDeluge
<p>I have about 100 videos. I would like to add a 30 pixel horizontal black bar to the top and bottom of each video without ruining the dimenions(so even if they go over the video). How can I achieve this? Also what's the command to have it run on every video in the folder without doing it for each one? I'm a complete beginner and I'm lost. Any help would be really appreciated!</p>

CC BY-SA 4.0
2019-02-12T12:35:58.013Z
https://video.stackexchange.com/q/12105/21971
Qwertiy
CC BY-SA 4.0
2019-02-12T12:52:29.727Z
OS - Windows, macOS?
Gyan
<ffmpeg><command-line>
FFMPEG - How can I add black bars to top and bottom of my video?
Bob Milon
# FFMPEG - How can I add black bars to top and bottom of my video?

(Asked by: username_0 on 2019-02-12)

I have about 100 videos. I would like to add a 30 pixel horizontal black bar to the top and bottom of each video without ruining the dimenions(so even if they go over the video). How can I achieve this? Also what's the command to have it run on every video in the folder without doing it for each one? I'm a complete beginner and I'm lost. Any help would be really appreciated!

**Tags:** ffmpeg, command-line

> **Comments:**
> **username_1**: https://video.stackexchange.com/q/12105/21971  
> **username_2**: OS - Windows, macOS?  

---

## 1 answers

### Answer by username_3 on 2019-02-13. Score: 6

Adding Bars
You can do it with a combination of the crop & pad video filters:
-filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30"

Both filters use the same format: width:height:x-offset:y-offset
In the crop filter, you want width to be same as the video's input width (you can use the variable in_w). You want to crop 60 pixels (30*2) from the input height (in_h-60). X offset stays at zero so nothing is changed horizontally. And set the Y offset to 30 so that 30 pixels are cropped from the top & bottom each. Otherwise, it will just crop 60 pixels from the bottom.
In the pad filter, the in_w & in_h variables will be whatever is output from the crop filter (you can just replace these with the actual video dimensions if you prefer). Use in_w again to preserve horizontal dimension. Add 60 black pixels back to the vertial dimension (in_h+60). Leave the X offset at 0 & set Y offset to -30 so pixels are added at top & bottom. Otherwise, it will just add 60 pixels to bottom.
The other option, as I think @Quertiy was pointing out, is to create a PNG image the same dimensions as your video with black bars at the top & bottom, & transparent in the middle, then overlay it onto the image:
ffmpeg -i video.mp4 -i overlay.png -filter_complex "overlay" -c:v libx264 "out.mp4"

It may be wise to list the streams in the filter arguments: -filter_complex "[0:0][1:0]overlay"

Multiple Files
If you were using a Unix shell (I believe this is what MacOS uses), you could use a for loop to convert all videos in a directory:
for V in *; do ffmpeg -i "$V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-$V"; done

But I'm not sure what the equivalent is using the Windows command prompt.
Edit: Windows command prompt has a for loop as well. So it should be something like:
for %V in (*) do ffmpeg -i "%V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-%V"

But, I haven't tested it.
Note: Use %%V within batch files, %V if using the command prompt directly.
Edit: According to this article, you should be able to do it in Windows PowerShell like this:
foreach ($V in Get-ChildItem .\) {ffmpeg -i "$V" -c:v libx264 -filter:v crop="in_w:in_h-60:0:30",pad="in_w:in_h+60:0:-30" "padded-$V"}

Again, I haven't fully tested it.

> **Comments:**
> **username_2**: Somewhat faster would be to apply drawbox twice. `drawbox=iw:30:0:0:t=fill,drawbox=iw:30:0:ih-30:t=fill`  
> **username_4**: This really helped blacking out subtitles when I needed to re-sub. in another language.  

---

