Total Pageviews

Google Ads

Monday, September 9, 2013

The thumbnail too slow with ffmpeg

I have a project with video Encode in this month. I have a trouble with respone of ffmpeg thumbnail too long. But I have fixed it today. Now. I will show the problem.

The command I used :
ffmpeg -itsoffset -40 -i BG.mp4 -vframes 1 output.jpg
See in this command. It's will take a snapshoot at frame 40 from the start frame. And by this way, you have to wait for ffmpeg seek to the frame's Index 40. That's find. But thinking about offset 100,000 or more?. I see it's take long time.
You can this command for "little exactly" but much faster.
ffmpeg -ss 00:00:50 -i BG.mp4 -vframes 1 output.jpg
the ss parameter is time seek of video. That's make thumbnail much faster than seek by frame. You can calculate the -ss parameter by:
ssTimeInSec = FrameOffset / FramePerSecond
I write a PHP code to translate TimeInSec to time in -ss parameter.

 function translateSecToString($sec){  
  $sec = intval($sec);  
  $h = intval($sec / 3600);  
  $m = intval(($sec - ($h * 3600))/60);  
  $s = $sec - ($h * 3600) - ($m * 60);  
  if($h < 10){$h = '0'.$h;}  
  if($m < 10){$m = '0'.$m;}  
  if($s < 10){$s = '0'.$s;}  
  return $h.':'.$m.':'.$s;  
 }  

Hope it can help :D

No comments:

Post a Comment