Extracting frames from MP4/FLV?
Asked Answered
V

2

40

I know it's possible with FFMPEG, but what to do if I have a partial file (like without the beginning and the end). Is is possible to extract some frames from it?

Variscite answered 27/11, 2011 at 18:9 Comment(0)
C
90

The command

ffmpeg -ss 00:00:25 -t 00:00:00.04 -i YOURMOVIE.MP4 -r 25.0 YOURIMAGE%4d.jpg

will extract frames

  • beginning at second 25 [-ss 00:00:25]
  • stopping after 0.04 second [-t 00:00:00.04]
  • reading from input file YOURMOVIE.MP4
  • using only 25.0 frames per second, i. e. one frame every 1/25 seconds [-r 25.0]
  • as JPEG images with the names YOURIMAGE%04d.jpg, where %4d is a 4-digit autoincrement number with leading zeros

Check you movie for the framerate before applying option [-r], same applicable for [-t], unless you want to extract the frames with the custom rate.

Never tried this with the cropped (corrupted?) input file though. Worth to try.

Checkers answered 15/12, 2011 at 17:42 Comment(5)
How can we specify the quality of the extracted JPG images?Bidarka
Thanks dawg, this has made it in to my mediadrop plugin (github.com/docdawning/mediadrop-handbrake-bot).Cortie
use -q:v 2 to get the best quality (#10225903)Disorderly
consider using YOURIMAGE%4d.bmp if disk space is plentiful and you plan on further manipulating the frames.Neumark
you can check the video's attributes, including framerate, with 'ffprobe -v error -show_format -show_streams input.mp4' [trac.ffmpeg.org/wiki/FFprobeTips]Inunction
U
2

This could be VERY difficult. The MP4 file format includes an 'moov' atom which has pointers to the audio and video 'samples'. If the fragment of the mp4 file you have does not have the moov atom, your job would be much more complicated. You'd have to develop logic to examine the 'mdat' atom (which contains all the audio and video samples) and use educated guesses to find the audio and video boundaries.

Even worse, without the moov atom, you won't have the SPS and PPS needed to decode the slices. You'd have to synthesize replacements; if you know the codec used to create the MP4, then you might be able to copy the SPS and PPS from a similarly encoded file; if not, it could be a painful process of trial and error, because the syntax of the slices (the H.264 encoded pictures) is dependent upon values specified in the SPS and PPS.

Uzial answered 19/12, 2011 at 20:42 Comment(2)
Although your answer is well informed, it is in fact very simple to extract frames and / or edit videos, using tools like FFMPEG.Hushhush
Dayne, reread the part of the question about the source file missing the beginning or end.Uzial

© 2022 - 2024 — McMap. All rights reserved.