Extract a keyframe from a video with FFMpeg

December 3, 2009 at 9:07 pm Leave a comment

If you want to extract a particular frame from a video, you can use the following ffmpeg command:

ffmpeg -i INPUTPATH -vframes 1 -ss TIMESTAMP -f image2 -vcodec mjpeg OUTPUTPATH.jpg

where TIMESTAMP is in the format hh:mm:ss.ff

If you have the frame number instead of the timestamp, you can use the following Ruby script to convert the frame number to the timestamp (for a framerate of 25fps) – there’s probably a better way for formatting a number to have two digits though :-):

def self.profile_thumbnail(frame_nr = nil)
#calculate timestamp
begin
  if frame_nr.nil?
    framenr = 25*60*2
  else
    framenr = frame_nr.to_i
  end

rescue
  framenr = 25*60*2
end

uur = (framenr/(60*60*25))
min = ((framenr-uur*60*60*25)/(60*25))
sec = ((framenr-uur*60*60*25-min*60*25)/25)
frame = ((framenr-uur*60*60*25-min*60*25-sec*25))
uur_s = uur.to_s
if uur<10
  uur_s = '0'+uur_s
end
min_s = min.to_s
if min<10
  min_s = '0'+min_s
end
sec_s = sec.to_s
if sec<10
  sec_s='0'+sec_s
end
frame_s = frame.to_s
if frame<10
  frame_s = '00'+frame_s
elsif frame<100
  frame_s = '0'+frame_s
end

stamp = uur_s+':'+min_s+':'+sec_s+'.'+frame_s
return  ' -vframes 1 -ss '+stamp+' -f image2 -vcodec mjpeg '

end
Advertisements

Entry filed under: Uncategorized. Tags: , , , .

Using Hudson for a Ruby project Use Google Docs for generating live reports on your Ruby scripts

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Feeds

Articles to be written…

Twitter – kr3l

my del.icio.us

RSS Google Reader Shared Stuff

  • An error has occurred; the feed is probably down. Try again later.

RSS Listening to..

  • An error has occurred; the feed is probably down. Try again later.

%d bloggers like this: