简体   繁体   中英

How to add black borders to video

So I'm using ffmpeg to convert a video to 1920*1080 px, I found two ways to do so, the first one would be to stretch the video to 1920*1080, but then it looks kinda stretched. I used this command for this:

./ffmpeg_darwin -i SRC -vf scale=1920:1080,setdar=16:9 DEST

The other option is the same without setdar but this just adapts the resolution to the one it started from (1728*1080).

I would like to fill the 192 pixels of the width with a black border. Is there some kind of option to do so? Or is there maybe another command line that could achieve this?

Thanks for your help:)

Use

-vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1"

The scale will ensure that its output fits within 1920x1080. The pad then fills that out.

Add border to all side of video with you set your padding that you want

here in input one video and add padding=20 all side left,right,top and bottom

"-i",path1,"-filter_complex","[0]pad=w=20+iw:h=20+ih:x=10:y=10:color=red; output

[0]pad=w=20+iw:h=20+ih:x=10:y=10:color=red

  1. Here, w=20+iw means your video width + 20 because you want add border so we need to add padding 20 for 10 right side pad and 10 left side pad
  2. and same as in height h=20+ih so +20 to video height for 10 for top pad and 10 for bottom pad

  3. x=10:y=10 is use for if x=0,y=0 so border is not show at left and top side and show border at right and bottom side of 20;

  4. if we want to add border 20 so width + 40 and height + 40 and x,y = 20
  5. color=red is used for border color

在此处输入图片说明

Thanks to everyone. Adapted your answers to a batch file placed in directory with the files I wanted to convert.

setlocal enabledelayedexpansion

GOTO :EndComment
  For low resolution videos that look worse when the display automatically
  makes them full screen.  This script upscales the video using horizontal 
  and vertical padding (black bars).       
:EndComment

set ffmpegExe="C:\Utilities\ffmpeg\bin\ffmpeg.exe"
set "oldScale=848:480"
set "newScale=1920:1080"


for %%f in (*.mp4) do (
  set str=%%f
  %ffmpegExe% -i "%%f" -vf "scale=%oldScale%:force_original_aspect_ratio=decrease,pad=%newScale%:(ow-iw)/2:(oh-ih)/2,setsar=1" "!str:.mp4=_new.mp4!"
  )
endlocal

Goal: make a 1728x1080 video a 1920x1080 video by filling 192 pixels of width.

Solution: add 96-pixel wide black bars to each side of the video.

Solution, command:
ffmpeg -i input.mp4 -filter_complex "[0]pad=w=1920:h=ih:x=96:y=0:color=black" output.mp4

Solution, command, explanation: w=1920 is the output width, h=ih is the output height (unchanged), x=96 and y=0 means the original video will be placed 96 pixels to the right of the top left of the output layout; think of the output layout as a 1920x1080 rectangle which is black due to color=black.

The answer of @Gyan did not work for me, no matter if I used single or double quotes.

The answer of @Sanjay Hadiya did not really address OP's problem. Also, Sanjay Hadiya's answer is poorly written and confusing (but it did kinda help me); I am curious if he is an ESL speaker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM