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

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.

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

brew install ffmpeg
#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”

-r[:<stream_spec>] 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)

orce the frame rate of the output file to 24 fps: ffmpeg -i input.avi -r 24 output.mp4 what about -s?

5.5 Video Options

-r[:stream_specifier] fps (input/output,per-stream) Set frame rate (Hz value, fraction or abbreviation).

As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps. This is not the same as the -framerate option used for some input formats like image2 or v4l2 (it used to be the same in older versions of FFmpeg). If in doubt use -framerate instead of the input option -r.

As an output option:

video encoding Duplicate or drop frames right before encoding them to achieve constant output frame rate fps.

video streamcopy Indicate to the muxer that fps is the stream frame rate. No data is dropped or duplicated in this case. This may produce invalid files if fps does not match the actual stream frame rate as determined by packet timestamps. See also the setts bitstream filter.

-s[:stream_specifier] size (input/output,per-stream) Set frame size.

As an input option, this is a shortcut for the video_size private option, recognized by some demuxers for which the frame size is either not stored in the file or is configurable – e.g. raw video or video grabbers.

As an output option, this inserts the scale video filter to the end of the corresponding filtergraph. Please use the scale filter directly to insert it at the beginning or some other place.

The format is ‘wxh’ (default - same as source).

-vf filtergraph (output) Create the filtergraph specified by filtergraph and use it to filter the stream.

This is an alias for -filter:v, see the -filter option.

You can extract images from a video, or create a video from many images: For extracting images from a video:

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

If you want to extract just a limited number of frames, you can use the above command in combination with the -frames:v or -t option, or in combination with -ss to start extracting from a certain point in time.

For creating a video from many images:

ffmpeg -f image2 -framerate 12 -i foo-%03d.jpeg -s WxH foo.avi The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable.

When importing an image sequence, -i also supports expanding shell-like wildcard patterns (globbing) internally, by selecting the image2-specific -pattern_type glob option.

For example, for creating a video from filenames matching the glob pattern foo-*.jpeg:

ffmpeg -f image2 -pattern_type glob -framerate 12 -i ‘foo-*.jpeg’ -s WxH foo.avi You can put many streams of the same type in the output: ffmpeg -i test1.avi -i test2.avi -map 1:1 -map 1:0 -map 0:1 -map 0:0 -c copy -y test12.nut The resulting output file test12.nut will contain the first four streams from the input files in reverse order.

To force CBR video output: ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v The four options lmin, lmax, mblmin and mblmax use ’lambda’ units, but you may use the QP2LAMBDA constant to easily convert from ’q’ units: ffmpeg -i src.ext -lmax 21*QP2LAMBDA dst.ext

Force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps: ffmpeg -r 1 -i input.m2v -r 24 output.mp4

ffmpeg -i $filename.mov -r 1 "$filename_frames/$filename%03d.png"
ffmpeg -f image2 -i "$filename_frames/$filename%03d.png" -loop 0 $filename.gif

actual for LED blink

ffmpeg -f image2 -framerate 10 -start_number 091 -i these/%003d.png -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 blink_320.gif

ffmpeg -f image2 -framerate 10 -start_number 091 -i these/%003d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse” -loop 0 blink_10fps.gif

ffmpeg -f image2 -framerate 10 -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen=stats_mode=diff:reserve_transparent=0[p];[s1][p]paletteuse” -loop 0 touch_diff.gif

//unable to choose output for image2 //worked, didn’t loop? ffmpeg -r 10 -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos” -c:v pam
-f image2pipe - |
convert -delay 10 - -loop 0 -layers optimize output.gif

these/switch_smex%03d.png reserve_transparent=0

ffmpeg -f image2 -framerate 10 -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse” -loop 0 touch_320.gif

ffmpeg -r 10 -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos” -c:v pam
-f image2pipe - |
convert -delay 10 - -loop 0 -layers optimize output2.gif

//doesn’t loop convert -layers OptimizePlus -delay 10 these/switch_smex*.png -resize 320x240 -loop 0 output3.gif

magick mogrify -path smaller/ -resize 320x240 -quality 80 *.png

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

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 0.77 -t 1 -i IMG_1684.mov
-vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse”
-loop 0 take2.mov

https://stackoverflow.com/questions/3688870/create-animated-gif-from-a-set-of-jpeg-images

WORKED ffmpeg -f image2 -framerate 9 -start_number 091 -i these/%003d.png -loop 0 blink.gif

ffmpeg -f image2 -framerate 9 -i image_%003d.jpg -vf scale=531x299,transpose=1 out.gif

ffmpeg -f image2 -framerate 9 -i these/%003d.jpg -loop 0 blink.gif

ffmpeg -f image2 -framerate 9 start_number 091 -i %003d.png - -loop 0 blink.gif

ffmpeg -f image2 -framerate 18 -start_number 091 -i these/%003d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse” -loop 0 blink_18fps.gif

ffmpeg -f image2 -framerate 12 -start_number 091 -i these/%003d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse” -loop 0 blink_12fps.gif

ffmpeg -f image2 -framerate 10 -start_number 091 -i these/%003d.png -vf “fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse” -loop 0 blink_10fps.gif

#!/bin/sh

palette="/tmp/palette.png"

filters=“fps=15,scale=320:-1:flags=lanczos”

ffmpeg -v warning -i $1 -vf “$filters,palettegen=stats_mode=diff” -y $palette

ffmpeg -i $1 -i $palette -lavfi “$filters,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle” -y $2

#!/bin/sh

palette="/tmp/palette.png"

filters=“fps=15,scale=320:-1:flags=lanczos”

ffmpeg -v warning -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos,palettegen=stats_mode=diff:reserve_transparent=0” -y palette.png

ffmpeg -i these/switch_smex%03d.png -i palette.png -lavfi “fps=10,scale=320:-1:flags=lanczos,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle” -y output_p.gif

carlynorama@Carlyns-MBP for_movies % ffmpeg -v warning -i these/switch_smex%03d.png -vf “fps=10,scale=320:-1:flags=lanczos,palettegen=stats_mode=diff:reserve_transparent=0” -y palette.png [Parsed_palettegen_2 @ 0x600003c3c210] The input frame is not in sRGB, colors may be off Last message repeated 2 times [image2 @ 0x136606f10] The specified filename ‘palette.png’ does not contain an image sequence pattern or a pattern is invalid. [image2 @ 0x136606f10] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.

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

https://stackoverflow.com/questions/3211595/renaming-files-in-a-folder-to-sequential-numbers

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

https://ffmpeg.org/ffmpeg-filters.html#paletteuse

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

https://www.baeldung.com/linux/convert-videos-gifs-ffmpeg https://shotstack.io/learn/convert-video-gif-ffmpeg/