Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast seeking ffmpeg multiple times for screenshots

Tags:

ffmpeg

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.


1 Answers

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)

like image 89
Aravind NC Avatar answered Oct 22 '25 03:10

Aravind NC