Skip to content

Instantly share code, notes, and snippets.

@frangipane
Created May 8, 2020 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frangipane/a1acc38f57723ef1231896fec67dff75 to your computer and use it in GitHub Desktop.
Save frangipane/a1acc38f57723ef1231896fec67dff75 to your computer and use it in GitHub Desktop.
ffmpeg commands to convert gif to mp4, to rescale mp4 dimensions, to stack (vertically/horizontally) mp4s into a single video
# convert gif to mp4
ffmpeg -i gifts.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" gifts.mp4
# create mp4 from images (*_value.png) in current dir
ffmpeg -framerate 2 -pattern_type glob -i '*.png' -c:v libx264 -r 30 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" value.mp4
# create mp4 from images (*_policy.png) in current dir
ffmpeg -framerate 2 -pattern_type glob -i '*.png' -c:v libx264 -r 30 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" policy.mp4
# create vertically stacked single video from the individual value and policy videos (they have the same width)
ffmpeg -i value.mp4 -i policy.mp4 -filter_complex "[0:v][1:v]vstack[out]" -map "[out]" out.mp4
# rescale the vertically stacked output -- since we’re going to horizontally stack out.mp4 with gifts.mp4, rescale out.mp4 so its height is 480 pixels (the height of gifts.mp4). The -2 in “-2:480” says to set height to 480 and determine width by keeping original aspect ratio, but making it even for compatibility (with codec or something)
ffmpeg -i out.mp4 -vf scale="-2:480" out_small.mp4
# horizontally stack the two videos (first video has already been vertically stacked)
ffmpeg -i out_small.mp4 -i gifts.mp4 -filter_complex "[0:v][1:v]hstack[out]" -map "[out]" final.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment