I would like to generate a gif preview for my application and made it on my server using FFMPEG.

It should generate a gif getting 10 frames for each video but without using a temp dir(or temp files relating each frame) if it's possible.

Regarding this answer on superuser.com, it should generate a gif using each frame, this is not I need.

Seems to be strange but the effect I need is something you can see on many porn websites (I don't remember what of these)


If I understand you correctly, this article on FFmpeg's Wiki named "Create a thumbnail image every X seconds of the video" shows that FFmpeg can't do what you want it to do (without some automated calculations).

The wiki says that -vf "fps=fps=XYZ" is your best shot - it will create one thumbnail/frame every XYZ frames of the original video. If you really want 10 pictures per video and they all have different lengths, you could first read out the total frame-count and then calculate the needed fps with a script:


with wanted_frames_times_actual_fps being e.g. 10*25 (PAL) or 10*30 (NTSC) in your case and total_frames_of_vid=(hh*3600+mm*60+ss)*25+ff, where hh means hours, mm means minutes, ss means seconds, and ff means frames (after the last counted second). Calculation example: a timecode of 01:35:45:24 (or 01:35:45.960 in FFmpeg's terms, as FFmpeg doesn't use frames but milliseconds) at 25 frames per second resembles 143649 frames total.

This solution could well work - you just need to find a way to get the total time of the video (e.g. via ffprobe) and its fps (if you can't get a proper timecode) and then store that info as a variable named $total_frames_of_vid.

I found another approach on this in the Wiki's "Also see"-section, linking to a superuser-question named "Meaningful thumbnails for a Video using FFmpeg" which suggests using:

ffmpeg -hide_banner -i <YOUR_VIDEO> -vf "select=gt(scene\,0.8)" -frames:v 10 -vsync vfr -vf "fps=fps=1/200" -y out%03d.png

(I modified the code a bit - changed image codec to PNG and changed values for -frames:v and fps. Also changed the output images to have three digits in their names.)

and then re-coding them to your GIF.

This solution also needs some computation or manual labor, as the values of all options (and especially fps need changing according to the length of the video. I.e. I tried the original code from superuser with a 35min video - and only got 5 frames out of it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.