How to add black borders to video

佐手、 提交于 2019-12-24 12:09:39

问题


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 :)


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/46671252/how-to-add-black-borders-to-video

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!