6

I want to take a frame of a video at a certain percentage of time (for example, 25%, 50% and 75%) and save it somewhere.

I need this to be done from the command-line so I can automate it. Also, this needs to be done in Windows.

Does anyone know how to do this?

Pylsa
  • 30,630
  • 16
  • 89
  • 116
brott
  • 137
  • 1
  • 5
  • Which file format is the video(s) encoded in? – iglvzx Jan 30 '12 at 19:34
  • Oh, sorry. They're in XviD (in AVI) and h264 (in MKV) mostly, they're videos from different TV series. Thanks! – brott Jan 30 '12 at 19:39
  • possible duplicate of [Take a screen shot from command line in Windows](http://superuser.com/questions/75614/take-a-screen-shot-from-command-line-in-windows) – Ƭᴇcʜιᴇ007 Jan 30 '12 at 20:15
  • 2
    @techie007 NOT a duplicate... This is basically about taking a frame from a video file and saving it as an image... Not about taking a screen shot of the entire screen. – Pylsa Jan 30 '12 at 21:09

1 Answers1

4

You might want to use ffmpeg for Windows with the following command:

ffmpeg -i <INPUT FILE> -ss 10 -f image2 -r 25 <OUTPUT FILE>
  • -i <INPUT FILE> Specifies the input file. E.g. movie.mp4.
  • -ss <TIME> Specifies time position in seconds. "hh:mm:ss[.xxx]" is also supported.
  • -f image2 Force/Set format.
  • -r 25 Set frame rate (in Hz. Can either be a fraction or a number, default = 25).
  • <OUTPUT FILE> Set output file. E.g. image1.jpg.

If your source video has a fixed frame rate, you can capture a specific frame using this formula:

<FRAME NUMBER> / <FRAME RATE> = <NUMBER OF SECONDS>

So if you want to capture frame 250 at a 25Hz frame rate, you set -ss to 10.

slhck
  • 223,558
  • 70
  • 607
  • 592
Pylsa
  • 30,630
  • 16
  • 89
  • 116
  • 1
    You can probably use wmi to pull the time length property from the video file, do some division on the output, then use that as the input for -ss. – Anthony Miller Jan 30 '12 at 21:26
  • 1
    Thank you very much! Although it didn't quite work (I got this and it never stopped: http://pastebin.com/raw.php?i=2nA04Uua), it pointed me here: http://stackoverflow.com/questions/3827611/ffmpeg-to-capture-screenshot-from-a-video-file-in-a-fine-time-unit and that worked. Thanks! @Mechaflash What is wmi? It sounds very useful! Thanks! – brott Jan 30 '12 at 22:03
  • 1
    @brott wmi is apart of the windows envrionmement that deals with windows objects and their properties. In your case the object is the video file and the property is the time length of the video. Information on WMI: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582%28v=vs.85%29.aspx. Information on using WMI in windows batch-file scripting: http://technet.microsoft.com/en-us/library/bb742610.aspx – Anthony Miller Jan 30 '12 at 22:26
  • Try the following command on your video file: `wmic datafile where name='C:\\Path\\To\\Video.xvid' > WMIoutput.txt` Please note the double \ and single quotes. Check the WMIoutput.txt file that it created and see if it shows some sort of time or duration of the video. I tested this on a mp3 file and it didn't return that sort of field for me. – Anthony Miller Jan 30 '12 at 22:54
  • It didn't give me that info, unfortunately. Anyway, the episodes are always the same length so it's no problem in my case. But if anyone knows how to do it, it'd be useful, indeed. Thanks! – brott Jan 30 '12 at 23:03