1

I'm developing an C# tool to extract mp4 frames to images. ( Without using ffmpeg )

I use a tool named ISO Viewer 2.0.2 and i see all my mp4 video frames (145 frames for 5 seconds, each frames is called as sample) in Tracks tab.

ISO Viewer 2.0.2 screen shot

On each frames/samples I can get it data byte[]. So how it convert this data to image in C# ?

Gyan
  • 85,394
  • 9
  • 169
  • 201
Giang Nguyễn
  • 105
  • 1
  • 9

1 Answers1

1

You most likely want to use some library to do this. This can get quite complex, if you are planning to do this yourself. I will try to illustrate by listing the steps needed to do that.

  • First you will need to figure out what video codec is used on the MP4. If you are lucky, it is H.264, but MP4 files can contain a lot of different video codecs. You can find the H.264 spec here: https://www.itu.int/rec/T-REC-H.264-201704-I/en (it is over 700 pages)

  • Then you need to actually use the extracted frame, and decode it according to the H.264 spec

  • If the frame is not an I-frame, you might need to look at prior frames to decode it. You might need to look at more than one prior frame.

  • If you are unlucky enough that the video contains B frames, you might need to look at future frames in addition to prior frames in order to decode it.

You are looking at a very large project to do this with just H.264 files, and then that only covers some MP4 files, and far from all. You will be much better off using something like ffmpeg, or a similar framework to do this.

If for some reason you are unable to use ffmpeg, then you might look into https://msdn.microsoft.com/en-us/library/windows/desktop/dd940436 (the usage of C# implies that you are using Windows).

colde
  • 3,192
  • 1
  • 15
  • 26