2

I want to create an animated .gif file as a thumbnail for a video. I used this command line to grab 20 frames from a video:

ffmpeg -i input.mkv -ss 00:05:14.435 -vframes 20 ./thumbs/out%02d.png

Which worked well to get a sample that I can create a .gif from. But in a longer video there are multiple scenes, obviously, and I wanted to get another 20 frames from another part and so on several more times to get a few scenes. Of course that presents a problem of how to decide where to grab the frames from.

I searched and found this question the answer to which really seems close to what I want - Meaningful thumbnails for a Video using FFmpeg. In that answer they offer the command:

ffmpeg -ss 3 -i input.mkv -vf "select=gt(scene\,0.4)" -frames:v 5 -vsync vfr -vf fps=fps=1/600 ./thumbs/out%02d.jpg

which gets a single frame at the beginning of each of five scene changes. I was exited because grabbing 10 or 20 frames from each of those scenes would be awesome and just want I want.

I could not tell how to combine the two concepts of finding the places where the scene changes are and grabbing multiple frames from each location. -frames:v and -vframes seem to be the same parameter and in one command they tell ffmpeg to grab 10 consecutive frames and in the other they say limit the grabbing fro frames from the scene breaks to 5.

How can I create a command that will grab n frames from each scene break up to y scene breaks? Heck I would take not being able to control how may scene breaks the n frames were grabbed for.

Ian Leslie
  • 121
  • 4
  • 1
    This can be done by combining an approach similar to [this](https://superuser.com/a/1389062/48078) with the scene function. Basically, you store a variable whenever you're immediately after a scene change, keep extracting frames at a particular rate until you've reached the next scene cut *or* the number of frames per scene is reached. Rinse and repeat. – slhck Jan 03 '19 at 15:32
  • 1
    Another possibility would be using [this Python script](https://github.com/slhck/scenecut-extractor) that I wrote, which extracts the scene cuts in a parsable manner, then scripting the extraction points using this info, feeding them to the `select` filter as particular frame numbers, or using a `trim` command to get the right portions. Obviously not posting an answer since I don't have time to program any of these solutions at this point. – slhck Jan 03 '19 at 15:32
  • Your pointer to the answer to "select filter to pick 8 frames every 5 seconds" looks very promising since I basically want to collect 10 frames but ever scene break. I have to admit that my attempts to splice the scene command into that expression have not been successful but I am sure that is because I am not getting how the pick every 5 seconds expression is setup in the first place. I am not finding the ffmpeg documentation on select to illuminating enough. – Ian Leslie Jan 03 '19 at 22:08
  • 1
    No, it's not very easy to understand, but behind it, there's quite a lot of potential. The expressions use several functions defined here: https://ffmpeg.org/ffmpeg-utils.html – maybe I'll find some time on the weekend. – slhck Jan 04 '19 at 13:52

0 Answers0