1

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!

1

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.

  • 1
    Somewhat faster would be to apply drawbox twice. drawbox=iw:30:0:0:t=fill,drawbox=iw:30:0:ih-30:t=fill – Gyan Feb 13 at 6:06
  • Much faster is using fillborders filter. – Paul B. Mahol Jul 13 at 12:40

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.