FFmpeg Generate Thumbnail Efficiently - ffmpeg

I am using FFmpeg for generating timeline thumbnail preview (image preview when your hover over seekbar in video player , like youtube player)
I need generating thumbnail for every 20s .
Here is code i use :
ffmpeg -i vide.mp4 -vf "fps=4/60 ,scale=260:150,tile=10*10" -qscale:v 10 thumbnail_%d.jpg
Code Work's Fine , only problem i have it's slow , for a movie with 3 hour long it's take more than 6 minute to generate thumbnail.
My System spec : Max os x 10.12 , Core i5 6600 , 16GB Ram.
I want's know there's a better way to do this ?

I think you might be looking for this:
https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
And more spefically -vframes parameter.

Related

How to zoom out image from and to specified dimensions using ffmpeg or python?

I have an image 3600x3600, and I want to start zooming it smoothly, beginning from 1717x1080 size, and by some designed time (f.e. 5 secs) get the size of 3600x2264. This is almost the same ratio as input (0.4 pixel of difference).
I need clean code, just can't find it. There's plenty of not working solutions.
EDIT
According to this topic: FFmpeg zoom not smooth-centered (but zigzag) I tried doing something
ffmpeg -loop 1 -i e:/gals/img.jpg -vf "zoompan=z='min(zoom-0.0320,5)':d=125:x='(iw-(iw/zoom))*(3600/-1883)':y='(ih-(ih/zoom))*(2265/-2520)',scale=1717x1018" -t 5 e:/vid.mp4
But it doesn't work. If I change parameters, I get bad ratio - the whole image of 3.6kx3.6k is stretched to my dimensions.
EDIT 2
Thanks to some other answers I found working code:
ffmpeg -loop 1 -i e:/gals/Esk04.jpg -vf "zoompan=z='if(lte(zoom,1.0),1.8,max(1.001,zoom-0.005))':d=125:x='(iw-(iw/zoom))/2':y='(ih-(ih/zoom))/2'" -t 5 e:/vid.mp4
but it saves the video in 1280x720 dimensions, while I need to save in 1717x1080 without changing image content ratio. Now I only need to crop it and keep the ratio - ideally with one command. Adding -s "1717x1080" causes some errors, depending on other parameters i set.

Video frame extraction using ffmpeg

I am stuck at a problem of frame extraction using ffmpeg. I am pointing out a given frame duration in video editors like filmora and shotkut (both coherent upto 2 places of milliseconds) and then I am using that duration in ffmpeg to extract all the frames at the native framerate. However, I don't get the perfect coherence when I see the first frame extracted and the corresponding image in editors(vlc, wondershare, filmora all same) both are different.
Please find an example of the command below :
ffmpeg -i "/mnt/sda1/Downloaded_Videos/25mm_Videos/24-12_21/0840.mp4" -ss 00:09:50.18 -to 00:10:49.22 /mnt/sda1/ExtractedFrames/25mm/24Dec_test/frame%5d_0r_0840_00095018_00095018.png
The extracted frame frame_0_0r_0840_00095018_00095018.png is different from the image or frame loaded in editors and vlc player when going to timestamp : 00:09:50.18.
Thanks for the valuable comment #Gyan. The framecount does the trick for ex.
00:00:10:20 -> signifies the 20th frame of the 10th second in the video
whereas
00:00:10.20 -> signifies the frame at the 200th milli-second for the 10th second of the video.
Conversion : Know the video fps : 00:00:10:20 = 00:00:10.(20 * 1000)/fps

Extracting thumbnails from a video for creating sprite is really slow on large videos

I have to create 'preview' on video progress hover. I'm doing with a sprite image and WebVTT file. Using ffmpeg and imagemagick. However generating thumbnails from a mp4 video is really damn slow (20-30 minutes for 2hrs and 20 min long video). The video is Full HD, H246 encoded, 2GB big. The command used
"ffmpeg.exe -i largevideo.mp4 -f image2 -bt 20M -vf fps=1/5 thumbs-%03d.jpg"
Which means thumb for every 5 secs of the video. Is there a way to make it faster? Videos in prod can be even bigger.
OS: Win10, ImageMagick is used later to create the sprite from all the thumbnails created with ffmpeg.
Skip everything except keyframes:
ffmpeg -skip_frame nokey -i input.mp4 -vsync passthrough thumbs-%03d.jpg
Also see:
Get keyframe intervals
Control JPG quality

ffmpeg: concatenating mp4 files. Video freezes for few seconds on first frame on output mp4

I created several MP4 files using ffmpeg. All of the videos have same settings and codec. Only difference is frames per second and duration. I then concatenated the videos using command below.
ffmpeg -f concat myList.txt -c copy output.mp4
I notice that when launching/opening the output.mp4 file in windows media player, it stops/freezes on the first frame of the video for about three four seconds and then starts playing, rest of the videos has correct fps and runs smoothly. Has anyone encountered this issue. I would like the video to start as soon as it is launched. Any suggestions to mitigate this issue?
Update: So far, I have found that the video length is exactly what I expect it to be.
ffprobe -i output.mp4
When i ffplay the video, it runs smoothly, but when I use windows media player, it gets stuck in first frame for about 4-5 seconds then plays smoothly. So I am going to assume that this issue is related to media players (buffers/loading before playing). Can't be sure though.
I solved this problem by converting my input files to avi and resizing them to the same size.
And then run
ffmpeg -i "concat:file1.avi|file2.avi|" -c copy out.avi

FFmpeg fade effects between frames

I want to create a slideshow of my images with fade in & fade out transitions between them and i am using FFmpeg fade filter.
If I use command:
ffmpeg -i input.mp4 "fade=in:5:8" output.mp4
To create the output video with fade effect, then it gives output video with first 5 frames black and than images are shown with fade in effect but i want fade:in:out effect between frame change.
How can i do that?
Please tell a solution for Centos server because i am using FFmpeg on this server only
To create a video with fade effect, just break the video into parts and create separate videos for each image. For instance, if you have 5 images then firstly, create 50-60 copies of each image and obtain a video for that:
$command= "ffmpeg -r 20 -i images/%d.jpg -y -s 320x240 -aspect 4:3 slideshow/frame.mp4";
exec($command." 2>&1", $output);
This will allow you to create 5 different videos. Then, you need 10-12 different copies of those five images and again create separate videos with fade effects.
ffmpeg -i input.mp4 "fade=in:5:8" output.mp4
After this you will have videos like: video for image 1 and its fade effect then for image 2 and its fade effect and so on. Now combine those videos in respective order to get the whole video.
For combining the videos you need:
$command = "cat pass.mpg slideshow/frame.mpg > final.mpg";
This means to join the videos using cat and then you need to convert them to mpg, join them and again reconvert them to mp4 or avi to view them properly. Also the converted mpg videos will not be proper so do not bother. When you convert them to mp4, it will be working fine.
You can make a slideshow with crossfading between the pictures, by using the framerate filter. In the following example 0.25 is the framerate used for reading in the pictures, in this case 4 seconds for each picture. The parameter fps sets the output framerate. The parameters interp_start and interp_end can be used for changing the fading effect: interp_start=128:interp_end=128 means no fading at all. interp_start=0:interp_end=255 means continuous fading. When one picture has faded out and the next picture has fully faded in, the third picture will immediately begin to fade in. There is no pause for showing the second picture. interp_start=64:interp_end=191 means half of the time is pause for showing the pictures and the other half is fading. Unfortunately it won't be a full fading from 0 to 100%, but only from 25% to 75%. That's not exactly what you might want, but better than no fading at all.
ffmpeg -framerate 0.25 -i IMG_%3d.jpg -vf "framerate=fps=30:interp_start=64:interp_end=192:scene=100" test.mp4
You can use gifblender to create the blended, intermediary frames from your images and then convert those to a movie with ffmpeg.

Resources