Extracting frames from MP4/FLV?

2019-01-30 11:37发布

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?

2条回答
你好瞎i
2楼-- · 2019-01-30 11:56

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.

查看更多
三岁会撩人
3楼-- · 2019-01-30 12:12

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.

查看更多
登录 后发表回答