Tuesday 2 April 2019

ffmpeg - How to put border around video to prevent clipping of content


My TV is old and for some reason clips some content off of the left edge. I'm trying to show a video on it in which the left edge is vital to the presentation.


Is there some way (with iMovie/ffmpeg/Gimp etc) that I can shrink the video size and surround it with a thick black border, so that this border is clipped when viewing it on my TV, rather than the content?


In other words, I want to go from this:


enter image description here


to this:


enter image description here


But I want to do that with a video (in mp4 format).



Answer



Method 1: Fixed size scale with padding:


ffmpeg -i inputfile.mov -filter_complex 'scale=578:462, pad=720:576:71:57' outputfile.mp4

This assumes SD PAL size input and output. This simply uses a fixed size pad.


Method 2: Percentage scaling with overlay on top of black generated by filter:


ffmpeg -y -i inputfile.mov -f lavfi -i color=c=black:s=1920x1080 \
-filter_complex "[0:v]scale=w=0.80*iw:h=0.80*ih[scaled]; \
[1:v][scaled]overlay=x=0.10*main_w:y=0.10*main_h:eof_action=endall[out]; \
[0:a]anull[aud]" \
-map "[out]" -map "[aud]" \
-strict -2 \
outputfile.mp4

This assumes input and output size to be full HD (1920x1080). The scaling is by 80 percent. So the overlay position is 20 percent inside- but since this 20 is divided on both sides equally, the overlay uses 10 percent of main width and adds that to x position.


The eof_action is required so that when the video file ends processing can stop. Else the generated black (background) from -f lavfi will just keep on going.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...