Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg extend (not resize) video size by adding box or border

Say I have a video of a peculiar resolution such as 1280x718 and I want to change this to 1280x720.

But instead of interpolating 718 pixels vertically to 720, I'd rather just add one line at the top and bottom.

So basically, I'm looking for a way to tell ffmpeg to create an output video of 1280x720, where input video of 1280x718 covers up the center, and all uncovered area is black or whatever.

I guess we could call this the opposite of cropping. I know how to resize a video (with interpolation) but in this case I don't want to rescale or mess with the original content, just add a small border.

like image 464
RocketNuts Avatar asked Jan 28 '18 11:01

RocketNuts


1 Answers

Found the answer, posting it here for reference:

ffmpeg -i input.mp4 -vcodec libx264 \
-vf "pad=width=1280:height=720:x=0:y=1:color=black" -acodec copy result.mkv

width and height are the intended output resolution, x and y are the top left coordinates (within the new output) where to place the input. color (optional) is the border color, can also use color=0xff00ff notation.

like image 50
RocketNuts Avatar answered Oct 16 '22 16:10

RocketNuts