Skip to content

Instantly share code, notes, and snippets.

@lg3bass
Last active May 31, 2022 11:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lg3bass/878a5cef3f69a08e9748 to your computer and use it in GitHub Desktop.
Save lg3bass/878a5cef3f69a08e9748 to your computer and use it in GitHub Desktop.
ffmpeg to pad videos to 16:9
//source: https://lists.ffmpeg.org/pipermail/ffmpeg-user/2011-July/001746.html
//source: http://ffmpeg.org/ffmpeg-filters.html#pad
//works
ffmpeg -i PAN_17-1_Final.m4v -filter:v 'pad=max(iw\,ih*(16/9)):ow/(16/9):(ow-iw)/2:(oh-ih)/2' -aspect 16:9 PAN_17-1_Final_auto1.m4v
//works but calculates manually (pad=<width output>:<height output>:<x upper-left-corner>:<y upper-left-corner>
ffmpeg -i PAN_17-1_Final.m4v -filter:v 'pad=939:528:22:0' PAN_17-1_Final_PADTEST2.m4v
//do all the files
for FILENM in *; do ffmpeg -i $FILENM -filter:v 'pad=max(iw\,ih*(16/9)):ow/(16/9):(ow-iw)/2:(oh-ih)/2' -aspect 16:9 ${FILENM/.m4v/}_pad.m4v; done;
//Update courtesy of eric.strom AT Pearson
//changed to '-preset slow' source: http://ubuntuforums.org/showthread.php?t=1760877
for FILENM in *; do ffmpeg -i $FILENM -filter:v 'pad=max(iw\,ih*(16/9))+mod(max(iw\,ih*(16/9))\,2):ow/(16/9)+mod(ow/(16/9)\,2):(ow-iw)/2:(oh-ih)/2' -aspect 16:9 -acodec copy -vcodec libx264 -preset slow -crf 18 ${FILENM/.m4v/}_pad.m4v; done;
//this seems to match the output to input
ffmpeg -i Pagodas-B.mov -filter:v 'pad=max(iw\,ih*(16/9))+mod(max(iw\,ih*(16/9))\,2):ow/(16/9)+mod(ow/(16/9)\,2):(ow-iw)/2:(oh-ih)/2' -aspect 16:9 -acodec copy -c:v libx264 -crf 5 -maxrate 2000k -bufsize 1835k Pagodas-B_pad.m4v;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment