Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

FFMPEG add black bars to a image if the video input is not 16:9

So I'm playing with ffmpeg and I have the command currently:

"ffmpeg_path?-ss?seek_time?-i?input_video_path?-vframes?1?-f?mjpeg?output_image_path?2<&1"

The issue that I'm facing is that for example I have a vertical video from a mobile phone the output image will be streched to 16:9, what I would like to do is to add black bars to the side of the image if the input is not in a 16:9 format.

Any suggestions or ideas on how I could do that?

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the pad filter. The same documentation includes an exact example of what you want:

  • Pad the input to get a final w/h ratio of 16:9:
pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2"

The filter can be specified using the -vf option:

ffmpeg -ss <time> -i <input> -vframes 1 -f mjpeg -vf pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" <output>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...