The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Getting Individual Frames And Matching Thumbnails From A Video With ffmpeg

TODO: Pull subtitle into page object TODO: Pull subtitle into page object

Notes

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

Code
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:

Code
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"

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title 

Getting Individual Frames And Matching Thumbnails From A Video With ffmpeg

-- subtitle

Or, An Easier Way To Make Animate GIFs

-- todo

[] 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)
  

-- notes

- 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


-- p 

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


-- code
-- shell

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



-- p


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:


-- code

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"



-- notes

- The `scale=220:-2` 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 `%d` to something like `%05d` where `5` determines the 
number of leading zeros to add

- For the single image output the `select` number is 
zero based. I'm using `60-1` 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.
  

-- blurb

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

-- categories
-- ffmpeg

-- metadata
-- date: 2022-12-05 14:11:05
-- id: 2ivww2aa
-- site: aws
-- type: post
-- status: published