wonderful library, thanks for putting this out for everyone to use.
I am able to create MP4 files, containing H264 encoded content, using
the MP4V2 library:
#define BASELINE_PROFILE_14496_10_ANNEX_A 66
#define PROFILE_COMPAT_NO_CONSTRAINTS_FOLLOWED 0
#define PROFILE_COMPAT_LEVEL_192 192
#define DVR104_LEVEL_NUMBER 30
#define NAL_UNIT_LENGTH_FIELD 3
MP4FileHandle m_hFile = MP4Create(m_fileName.c_str(), 2,
MP4_CREATE_64BIT_TIME );
MP4TrackId m_videoTrackID = MP4AddH264VideoTrack( m_hFile, 90000,
MP4_INVALID_DURATION, 720, 480, BASELINE_PROFILE_14496_10_ANNEX_A,
PROFILE_COMPAT_NO_CONSTRAINTS_FOLLOWED, DVR104_LEVEL_NUMBER,
NAL_UNIT_LENGTH_FIELD );
MP4TrackId m_audioTrackID = MP4AddAudioTrack( m_hFile, 90000,
MP4_INVALID_DURATION, MP4_MPEG2_AAC_LC_AUDIO_TYPE );
// then for each video frame i get: (setting 'isSyncSample' true for
every IFrame
bool ret = MP4WriteSample( m_hFile, m_videoTrackID, frameBuffer,
frameBufferSize, sampleDuration, 0, isSyncSample );
// and for each audio sample i get:
bool ret = MP4WriteSample( m_hFile, m_audioTrackID, frameBuffer,
frameBufferSize, sampleDuration);
// when done adding audio/video:
MP4Close(m_hFile);
I am able to view the content fine when i play using an Elecard
player.
Note, the 00000001 which starts each frame has been replaced by the
frame-size, per an email in this group.
I have had this file analysed by M4scene, and i got these errors for
**each frame** in the test.mp4 file that was generated:
--------------------------------------------
<message name="This profile is currently unsupported" value=""
id="SD777" type="error"/>
<message name="NALUnitLength read too large for remaining sample size
(sampleId=1)" value="" id="SD780" type="error"/>
--------------------------------------------
When i asked M4scene support about these errors, i got this response:
"We've dug into the file a bit. In the decoder info the
NumOfSequenceParameterSets and numOfPictureParameterSets are both zero
which was not handled correctly in SceneScope, so it didn't recognize
it as baseline.
An error in the file however is that every sample has a nalUnitLength
the same as the sample size. This should be, at most, sample size
minus the 4 bytes of the nalUnitLength."
Am i using the library wrongly? Or are these known issues within
MP4V2?
Thanks a lot for looking into these issues,
Ken
You're pretty much using the library correctly; basically, you should
be appending the Sequence Parameter Set and Picture Parameter Set (SPS
and PPS, respectively) to the file. You can do that using:
void MP4AddH264SequenceParameterSet (MP4FileHandle hFile, MP4TrackId
trackId, const uint8_t *pSequence, uint16_t sequenceLen)
void MP4AddH264PictureParameterSet (MP4FileHandle hFile, MP4TrackId
trackId, const uint8_t *pPict, uint16_t pictLen)
...you should be able to either ask your H.264 encoder for this
information, or you can search for it in-stream (you'll have to
examine the NALU header type to figure this out). Chances are the
file still plays back correctly because this information is in the H.
264 stream itself.
Thank you very much for your assistance, I have added those 2
calls to each of MP4AddH264_XYZ_ParameterSet(), and i no longer see
the 'profile unsupported' error from m4scene. I was surprised to
see that each frame delivered from the encoder has the following
format:
NAL_START_CODE, PPS-data, NAL_START_CODE, SPS-data, NAL_START_CODE, Frame-data
I am still seeing the error reported from m4scene:
"NALUnitLength read too large for remaining sample size"
Note __size="8351"__ and __"NALUnitLength" value="8351"__
are the same size, which m4scene support says:
is that every sample has a nalUnitLength
the same as the sample size.
This should be, at most, sample size
minus the 4 bytes of the nalUnitLength.
Is this related to the last parameter of "MP4AddH264VideoTrack(
....... ) which is ' uint8_t sampleLenFieldSizeMinusOne)' ?
I am setting this field to '3', should it perhaps be '0'? I'm not
really sure what i should be doing with this...
thanks;
A sample of what m4scene has parsed is:
<track name="1" value="" type="vide">
<sampleInfo name="" value="">
<sample name="1" value="" track="1"
fileOffset="8633" size="8351" timestamp="0" duration="3000"
avgBitrate="66808" type="?">
<property name="NALUnitLength" value="8351"
bitoffset="0" bitlength="32" nodeid="126915728" errorids="-1" />
<messages name="Sample property errors" value="">
<message name="NALUnitLength read too large
for remaining sample size (sampleId=1)" value="" id="SD780"
type="error" />
</messages>
</sample>
...etc..repeated N samples...
> --
> You received this message because you are subscribed to the Google Groups
> "mp4v2" group.
> To post to this group, send email to mp...@googlegroups.com.
> To unsubscribe from this group, send email to
> mp4v2+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mp4v2?hl=en.
>
>