Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Getting Individual Frames And Matching Thumbnails From A Video With ffmpeg

Or, An Easier Way To Make Animate GIFs

[] Look into this

https : //ffmpeg.org/ffmpeg - filters.html#select _ 002c - aselect

maybe you can do the select based off frames (thought something else made that seem like it would be slower since it's an output filter instead of an input filter. something to check)

- Probably better to use the timestamp based approach. (I'm not seeing a way to seek to a frame without moving to the time and that can be tricky with variable frame rates)

- Need to figure out what that timestamp thing is a reference to since I didn't write it down here

This is how to generate the initial set of thumbnails (one per frame)

ffmpeg -i "input.mp4" -vf "scale=800:-2" -y "frames/%d.jpg"

Then you can access an individual frame based of the numbers with this (which is zero indexed subtract one to get the frame number your after :

export INPUT=Prince-Sexy-MF-bfHsF6FKgb4.mp4 && \
export FRAME=2952&& \
ffmpeg -i "$INPUT" -vf "select=eq(n\,$FRAME-1)" -vframes 1 -y "frame-$FRAME.png"

- The [TODO: Code shorthand span ] in the initial thumbnail generation resizes the images to be 220 pixels wide and fits the height to match the aspect ratio (with an even number of pixels). It's not required for the generation. Without it, images will be the same size as the source video

- Leading zeros can be added to the thumbnail names by changing [TODO: Code shorthand span ] to something like [TODO: Code shorthand span ] where [TODO: Code shorthand span ] determines the number of leading zeros to add

- For the single image output the [TODO: Code shorthand span ] number is zero based. I'm using [TODO: Code shorthand span ] here to get to frame 59. That's easier for me to parse and makes generating commands easier since you can let ffmpeg do the calculation for you.

Generate a set of numbered thumbnails for each frame in a video then use those numbers to access that frame