Skip to content

Instantly share code, notes, and snippets.

@hn-88
Forked from benbjohnson/videogen.sh
Last active December 21, 2023 09:27
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 hn-88/95dbd59767dcdff23eab2f2be5880c2f to your computer and use it in GitHub Desktop.
Save hn-88/95dbd59767dcdff23eab2f2be5880c2f to your computer and use it in GitHub Desktop.
Generate a video of frame numbers.
#!/bin/bash
# Generate the frames
for i in {0..1800}
do
echo "Generating frame $i"
convert -background black -fill white -size 480x320 -pointsize 48 -gravity center label:${i} frame${i}.png
done
# Combine frames into H.264 MP4 video. (29.97fps & 30fps)
ffmpeg -i frame%d.png -t 60.06 -codec:v libx264 -r 30000/1001 29_97fps.mp4
ffmpeg -r 30 -i frame%d.png -t 60 -codec:v libx264 -r 30 30fps.mp4
# Clean up frames.
rm frame*.png
@hn-88
Copy link
Author

hn-88 commented Dec 13, 2023

On windows, we have to use the command "magick" instead of "convert" according to
https://stackoverflow.com/questions/4481573/how-to-override-windows-convert-command-by-imagemagicks-one

@hn-88
Copy link
Author

hn-88 commented Dec 20, 2023

Found some frames are being duplicated. Investigating. Something related to
https://superuser.com/questions/1255380/ffmpeg-duplicating-frames
?

@hn-88
Copy link
Author

hn-88 commented Dec 21, 2023

ffmpeg says
encoded 433 frames in 4.02s (107.71 fps), 70.96 kb/s, Avg QP:35.13
for command
ffmpeg -i frame%d.png -codec:v libx265 -r 30 30fps.mp4
even tho there are only 360 frames in the input.

Every 5 frames, it's adding a duplicate frame.

@hn-88
Copy link
Author

hn-88 commented Dec 21, 2023

Just giving ffmpeg -i frame%d.png default.mp4
results in a 25fps mp4.

For getting the desired result, we have to put the -r before the -i, like
ffmpeg -r 30 -i frame%d.png thisis30fps.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment