How to put border around video to prevent clipping of content
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.
Related videos on Youtube
AmadeusDrZaius
Updated on September 18, 2022Comments
-
AmadeusDrZaius almost 2 years
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:
to this:
But I want to do that with a video (in mp4 format).
-
Psycogeek over 9 yearsIs it an option to just adjust the size any way desired during playback? that way the video does not have to be re-encoded. What is the OS that it is being played back with? or is this dvd bluray or something?
-
AmadeusDrZaius over 9 yearsThe file is being accessed over the DLNA protocol. I'm using the Plex server to serve the files to my Sony media player (a TV top box) over Wi-Fi. Unfortunately, my TV does not have a setting for scaling or moving the video, and the only setting that my SONY player has is to fix the aspect ratio to 4:3.
-
krowe over 9 yearsCan you give some more information about the TV? The type and model would really help. Also, tell us about your video card please.
-
Psycogeek over 9 yearsSorry dont know FFMpeg but in virtualDub and other video programs it is often found in the resize options, as you resize the video and plop it on the specified size "canvas" , Framing options.
-
-
AmadeusDrZaius over 9 yearsMy file is an mp4 and I got this message when running your method 2:
The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
I tried adding the-strict -2
to the end, but it didn't change the error message. Any ideas? -
Rajib over 9 years@AmadeusDrZaius I added the -strict -2 parameter.
-
AmadeusDrZaius over 9 yearsThat worked! I tried adding the
-strict -2
everywhere else, but it didn't work. Thank you so much. Any good resources for this other than the manpage or the ffmpeg.org website? -
AmadeusDrZaius over 9 yearsI just took a look at your other answers and you have a lot of knowledge about ffmpeg. Are you an ffmpeg contributor/developer? Either way, thanks again.
-
Rajib over 9 years@AmadeusDrZaius No far from it. Just a happy user. Look here for filters. Stackexchange Superuser and StackOverflow are great resources.
-
slhck over 9 years@AmadeusDrZaius trac.ffmpeg.org/wiki, blog.superuser.com/2012/02/24/… (shameless plug), otherwise, just ask a question here. We have a handful of people around here who know their way around ffmpeg.
-
Elisa Cha Cha over 9 years@AmadeusDrZaius If the input audio is compatible with the output container format, then consider stream copying it with
-c:a copy
instead of re-encoding.