user3786834
user3786834

Reputation:

Fast seeking ffmpeg multiple times for screenshots

I have come across https://askubuntu.com/questions/377579/ffmpeg-output-screenshot-gallery/377630#377630, it's perfect. That has done exactly what I wanted.

However, I'm using remote URLs to generate the screenshot timeline. I do know it's possible to fast seek with remote files using https://trac.ffmpeg.org/wiki/Seeking%20with%20FFmpeg (using -ss before the -i) but this only runs the once.

I'm looking for a way to use the

./ffmpeg -i input -vf "select=gt(scene\,0.4),scale=160:-1,tile,scale=600:-1" \
-frames:v 1 -qscale:v 3 preview.jpg

command but using the fast seek method as it's currently very slow when used with a remote file. I use PHP but I am aware that a C method exists by using av_seek_frame, I barely know C so I'm unable to implement this into a PHP script I'm writing. So hopefully, it is possible to do this directly with ffmpeg in the PHP system() function.

Currently, I run seperate ffmpeg commands (with the -ss method) and then combine the screenshots together in PHP. However, with this method it will be refetching the metadata each time and a more optimized method would be to have it all happen in the same command line because I want to reduce the amount of requests made to the remote url so I can run more scripts in sequence with each other.

Thank you for your help.

Upvotes: 4

Views: 4318

Answers (3)

Aravind NC
Aravind NC

Reputation: 812

Yes it's because -ss is not before -i and you need to add that before each input.

So here's a working example that takes it out super fast.

ffmpeg -ss 10 -i test.avi -frames:v 1 -f image2 -map 0:v:0 thumbnails/output_0.png \
      -ss 800 -i test.avi -frames:v 1 -f image2 -map 1:v:0 thumbnails/output_1.png \
     -ss 2400 -i test.avi -frames:v 1 -f image2 -map 2:v:0 thumbnails/output_2.png

So the 0 : v : 0 means 1st input, and select video streams, first videostream 1 : v : 0 means 2nd input, and select video streams, first videostream (0) 2 : v : 0 means 2nd input, and select video streams, first videostream (0)

Upvotes: 7

ax.falcon
ax.falcon

Reputation: 43

$ffmpeg = "ffmpeg.exe";
$cmd = "$ffmpeg -ss 20 -i $Filename -frames:v 1 mjpeg -map 0:v:0 $Thumbnail";
$Return = `$cmd`;

Makes extremely fast thumbnails of videos. $Filename is the file and path of your video e.g. C:\videos\video_1.mp4

And $Thumbnail is the file path AND filename to where you want your thumbnail stored e.g. C:\Thumbnails\Thumbnail_1.jpg

Upvotes: 0

Lovely2
Lovely2

Reputation: 21

The main reason why this is slow is because "select=gt(scene\,0.4)" requires every frame to be decoded and compared to the next so that scene changes can be detected.

I don't believe it is possible to do what you are doing any faster than you are doing with the scene change detector. You could provide n screenshot from video_duration/n steps through the video, additionally you could also check each frame isn't black by checking the image intensity is above a threshold.

Upvotes: 1

Related Questions