Created
May 8, 2020 02:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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