Recently, a 3GP/MP4 Player uses FFMPEG to extract MPEG4 raw data from the Demux file of 3GP/MP4, which cannot be directly used for decoding. You need to add the vol header before the first frame. I copied the implementation of FFMPEG's encode_vol_header, and many files (especially qvga files) cannot be decoded.
Finally, we learned that this vol does not need to be generated by ourselves. We only need to copy the data in avctx-> extradata_size to the front of your first frame.
Although FFMPEG has a ready-made vol header, I would like to summarize the file format of MPEG4 SP by the way. See section 6.2 of mpeg-4-14496-2. Use ue to open a. m4v file. The 44-byte header. bit stream syntax is as follows:
A) global configuration information, indicating the entire video object group visualobjectsequence () to be decoded by the decoder ()
B) object configuration information, which represents a single video object. Visualobject ().
C) the object Layer configuration information to characterize the videoobjectlayer () of a video object ().
D) es stream data, including the data in the entire Video Object layer.
Related code: mpeg4_encode_visual_object_header and mpeg4_encode_vol_header in FFMPEG/libavcodec/h263.c. There are several points to note.
-Write the VOS and VO headers first. The vos start code is 0x1b0 and the vo start code is 0x1b5.
-Value of profile_and_level_indication. The Simple Profile value is generally 0x3.
-Vol starts with 00 00 01 00 00 0120
-Vol_width and vol_height are consistent with the image size, which can be obtained from = (* formatctx). Streams [videostream]-> codec.
-Zero must be set for less than 8 digits.
By the way, we recommend a mp4ui software that can dump audio and video from 3GP and MP4 files, which is very useful. It is also open-source and helpful for analyzing the 3GP format!