Uhg, How do I post a blinking LED image again?
Every time I have to look this up… I have a longer page of notes to go through, but at least I can post the links.
- Official docs: https://ffmpeg.org/ffmpeg.html
- https://ffmpeg.org/ffmpeg.html#toc-Video-and-Audio-file-format-conversion
- https://ffmpeg.org/ffmpeg-formats.html#image2-1
Link Dump
-
https://stackoverflow.com/questions/42980663/ffmpeg-high-quality-animated-gif
-
https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers
-
https://stackoverflow.com/questions/3688870/create-animated-gif-from-a-set-of-jpeg-images
-
https://cassidy.codes/blog/2017/04/25/ffmpeg-frames-to-gif-optimization/
-
https://mattj.io/posts/2021-02-27-create-animated-gif-and-webp-from-videos-using-ffmpeg/
-
https://gist.github.com/devadvance/f2ad3cfe38afe3eeef64c72c46692158
-
https://www.paulirish.com/2021/video-stabilization-with-ffmpeg-and-vidstab/
-
framerate
: Set the frame rate for the video stream. It defaults to 25. -
loop
: If set to 1, loop over the input. Default value is 0. -
start_number
: Set the index of the file matched by the image file pattern to start to read from. Default value is 0. -
start_number_range
: Set the index interval range to check when looking for the first image file in the sequence, starting from start_number. Default value is 5. -
video_size
: Set the video size of the images to read. If not specified the video size is guessed from the first image file in the sequence -
-r[:<stream_spec>] <rate>
: override input framerate/convert to given output framerate (Hz value, fraction or abbreviation) -
-vf <filter_graph>
: alias for -filter:v (apply filters to video streams)
get ffmpeg
brew install ffmpeg
Use ffmpeg for creating a video from the images in the file sequence img-001.jpeg, img-002.jpeg, …, assuming an input frame rate of 10 frames per second:
ffmpeg -framerate 10 -i 'img-%03d.jpeg' out.mkv
As above, but start by reading from a file with index 100 in the sequence:
ffmpeg -framerate 10 -start_number 100 -i 'img-%03d.jpeg' out.mkv
Read images matching the “*.png” glob pattern , that is all the files terminating with the “.png” suffix:
ffmpeg -framerate 10 -pattern_type glob -i "*.png" out.mkv
#-video_size 320x240
## destination folder must already exist.
ffmpeg -i $filename.mov -r 1 "$filename_frames/$filename%03d.png"
## edit frames...
ffmpeg -f image2 -i "$filename_frames/$filename%03d.png" -loop 0 $filename.gif
ffmpeg -i IMG_1703.mov -r 12 "all_frames2/switch_press%03d.png"
ffmpeg -i $filename.mov -r 1 "$filename_frames/$filename%03d.png"
ffmpeg -f image2 -i "$filename_frames/$filename%03d.png" -loop 0 $filename.gif
# Change these placeholders:
# * $INPUT_START_TIME - number of seconds in the input video to start from.
# * $LENGTH - number of seconds to convert from the input video.
# * $INPUT_FILENAME - path to the input video.
# * $OUTPUT_FPS - ouput frames per second. Start with `10`.
# * $OUTPUT_WIDTH - output width in pixels. Aspect ratio is maintained.
# * $NUMBER_OF_LOOPS - use `0` to loop forever, or a specific number of loops.
# * $OUTPUT_FILENAME - the name of the output animated GIF.
ffmpeg -ss $INPUT_START_TIME -t $LENGTH -i $INPUT_FILENAME \
-vf "fps=$OUTPUT_FPS,scale=$OUTPUT_WIDTH:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop $NUMBER_OF_LOOPS $OUTPUT_FILENAME
ffmpeg -f image2 -framerate 12 -start_number 085 -i these/switch_press%003d.png -vf "fps=12,scale=240:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 touch_12fps.gif
num=298; for i in *; do mv "$i" "$(printf 'switch_press%003d' $num).${i#*.}"; ((num++)); done
ffmpeg -f image2 -i "these5/switch_press%003d.png" -loop 0 touchc.gif
ffmpeg -f image2 -framerate 12 -i these/switch_press%003d.png -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 toucha_12to10fps.gif
ffmpeg -i IMG_1706.mov -vf "palettegen" palette.png
ffmpeg -i IMG_1706.mov -loop 0 -filter_complex "fps=10, scale=-1:240[s]; [s]split[a][b]; [a]palettegen[palette]; [b][palette]paletteuse" final_a.gif