0

I am trying to generate mp4 file from mpeg4-es video frames. So far, I can use mp4parser to generate mp4 file from H264 video frames without problem.

But I can't sure if we can output mpeg4-es video frames to mp4 with mp4parser as well? (It seems no any example about this way.) or I should looking for another way to make it in Android?

Any comment or suggestion would be appreciated. Thanks

Chir
  • 1
  • 1

1 Answers1

0

See this Post. It has the Answer you need to understand. Your MPEG elementary stream is in AVCC. This means to make it like usual H.264 (Annex B) you must replace each of the 4-bytes that represent a NAL Unit's size (in MP4) with a start code like 00 00 00 01. Then you can use MPEG-es same as H.264 in your MP4Parser tool. Maybe my Answer here can help you recognise the NALUs.

Get a hex editor and check the difference between the raw H.264 and then check same H264 data when now contained inside an MP4 file (find "mdat" in MP4 then onwards it will your H.264 bytes). See how the NALU's have changed from starting with 00 00 00 01 to having (hex) numbers D8 9C 00 00 for bytes size?

PS: If you know FFmpeg, I recommend you convert 1 picture into an H.264 video frame then also codec copy the H264 into an MP4 container. Now you can find H.264 easily in MP4 file (like it was copy/pasted into there). Once you can convert a small 1-frame MPEG-es back into H264 then try longer files.

VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Thanks for your kind reply. So far we can pack H264(AVC) frames into MP4 file without problem, the method is almost the same as you mentioned. But what we have problem is about MPEG4 (video/mpeg4-es) frames (Not AVC), So you will suggest us to change the start code of MPEG4 frame as `00 00 00 01` ? Thanks al lot. – Chir Aug 29 '19 at 13:02
  • What are the first 16 bytes (in hex format) of your MPEG-es? – VC.One Aug 29 '19 at 13:07
  • Hi, It is a sample: `00 00 01 B6 52 E0 33 FD EB E9 1A 7C 1F 79 47 BE ....`. Any suggestion would be appreciated. Thanks – Chir Aug 29 '19 at 13:22
  • If you select (or skip) 438 bytes starting from byte `52` onwards what does the **next 4 bytes** look like (at position/offset 442)? I can't see if `00 00 01` is your start code, or else (b) the bytes `00 00 01 B6` means **size** of the NALU (which is why I want you to check ahead 483 bytes to see if that gives a new NALU after this **size** of jump. – VC.One Aug 29 '19 at 13:59
  • At the position 442: `0E B1 4C EC 00 91 28 7D C0` At the position 483: `AF 86 41 87 81 08 1B 40 3D` I also don't found anything like a new NALU. These MPEG4 frames are generated by VLC, and we use LIVE555 to receive the frames. We can feed these frames to MediaCodec of Android to decode as video/mpeg4-es without problem. But the problem is how to save these frame as a MP4 file. Although we done it with H264(AVC) frames and mp4parser tool, but I can't sure if it is right way for MPEG4(video/mpeg4-es) frames to try to use mp4parser as well. :( – Chir Aug 29 '19 at 14:35
  • I thin it'll be better if you use [**Pastebin.com**](https://pastebin.com/). Paste as much of the bytes as you can fit on the space given. If you share the link of your _"paste"_ then I can check and also recreate the file. – VC.One Aug 29 '19 at 16:18
  • 1
    Hi, VC.One Thanks for your suggestion, I will paste full bytes as your advisement. Please wait for a while. Thanks. – Chir Sep 04 '19 at 10:47