83
61
FFmpeg can capture images from videos that can be used as thumbnails to represent the video. Most common ways of doing that are captured in the FFmpeg Wiki.
But, I don't want to pick random frames at some intervals. I found some options using filters on FFmpeg to capture scene changes:
The filter thumbnail
tries to find the most representative frames in the video:
ffmpeg -i input.mp4 -vf "thumbnail,scale=640:360" -frames:v 1 thumb.png
and the following command selects only frames that have more than 40% of changes compared to previous (and so probably are scene changes) and generates a sequence of 5 PNGs.
ffmpeg -i input.mp4 -vf "select=gt(scene\,0.4),scale=640:360" -frames:v 5 thumb%03d.png
Info credit for the above commands to Fabio Sonnati. The second one seemed better as I could get n images and pick the best. I tried it and it generated the same image 5 times.
Some more investigation led me to:
ffmpeg -i input.mp4 -vf "select=gt(scene\,0.5)" -frames:v 5 -vsync vfr out%02d.png
-vsync vfr
ensures that you get different images. This still always picks the first frame of the video, in most cases the first frame is credits/logo and not meaningful, so I added a -ss
3 to discard first 3 seconds of the video.
My final command looks like this:
ffmpeg -ss 3 -i input.mp4 -vf "select=gt(scene\,0.5)" -frames:v 5 -vsync vfr out%02d.jpg
This was the best I could do. I have noticed that since I pick only 5 videos , all of them are mostly from beginning of the video and may miss out on important scenes that occur later in the video
I would like to pick your brains for any other better options.
My approach is to generate perhaps a dozen jpeg thumbnails at different times, and choose the one with the largest file size. The largest file tends to be more "complex" and interesting, it would seldom be a blurry image, and it will never be a boring image such as a plain black frame. This approach might not be ideal for you, but perhaps you can use it together with other methods. – Sam Watkins – 2015-08-06T12:24:44.187
These are great commands, but is there anyway to reduce the quality further? I like the dimensions, but its still 400KB to download. Maybe something 100KB in size would be nice. – chovy – 2015-12-30T11:16:20.210
I'm looking for an opposite solution: select more frames from periods where camera is more stable and not moving? (where the difference between successive frames are less, not higher). Is there a way to do that? – Tina J – 2018-07-05T13:49:30.997
Nice command examples. FWIW, I didn't run into any issues with FFmpeg-generated JPEG pictures on OS X (10.8, FFmpeg 1.1 and below). Your second to last command works fine for me—so does the last—and none of these results in blank JPG files. I did compile with
libopenjpeg
.. not sure if that makes a difference. – slhck – 2013-01-18T08:46:10.940Thanks slhck. Edited the question with ffmpeg config/version details. I have not upgraded to 1.1 on this machine. I will do that and see if it changes any results. – d33pika – 2013-01-18T08:51:56.970
1
So you're on Ubuntu? Can you try the latest Git Master version from a static build or compiling yourself and running again? Or the latest stable. I just checked, it uses the
– slhck – 2013-01-18T08:59:43.813mjpeg
encoder for me as well, and I also checkedjpegoptim
andexiv2
, both of which work fine for me with all the JPG results from your example commands.1I updated, and it works now! I guess the previous version had some bugs. – d33pika – 2013-01-18T09:37:29.457
Can you go ahead and post the solution- new version, preferably with link to changelog showing the bug you encountered and subsequently fixed with new version? – Lizz – 2013-03-16T07:15:56.287
Hi @Lizz ,The same commands above were returning blank images in the older version of FFmpeg. No, I am on the latest versions and all the commands work! – d33pika – 2013-03-18T02:04:22.050