It is confusing about the audio track parameters, in your sample, 
    AP4_Track* track = new AP4_Track(AP4_Track::TYPE_AUDIO,
                                     sample_table,
                                     0,                 // track id
                                     sample_rate,       // movie time scale
                                     sample_count*1024, // track duration
                                     sample_rate,       // media time scale
                                     sample_count*1024, // media duration
                                     language,          // language
                                     0, 0);             // width, height

If I used it directly in my own code, it usually causes unexpected long duration(exp. 1 minute video shows 40 minutes duration). Hence I modified the code above to

	m_nAudioSamples = Audio_Sample_table->GetSampleCount();
	AP4_UI64 movie_timescale = 1000;// since video track also uses 1000 as movie_timescale
	AP4_UI64 AudioTrackDuration = m_nAudioSamples * movie_timescale;
	AP4_UI64 MediaDuration = m_nAudioSamples * movie_timescale;
	AudioTrackDuration = AP4_ConvertTime(movie_timescale * m_nAudioSamples, m_sample_rate, movie_timescale);
	AP4_Track* track = new AP4_Track(AP4_Track::TYPE_AUDIO,
		Audio_Sample_table,
		2, //0,                 // assume video track id = 1, then audio track id = 2
		movie_timescale,        // movie time scale
		AudioTrackDuration, // track duration              
		m_sample_rate,       // media time scale
		MediaDuration, // media duration
		"und",             // language
		0, 0);             // width, height

       Now in this way, the muxer sometimes works, sometimes only have video track, and when probe with ffmpeg, it told me "invalid STSD entries 0".

        In order to match video track, what will be the right way to set the following parameters?
movie time scale
track duration
media time scale
media duration

Thanks.
Eric

Add audio track causes the mp4 file to have "invalid stsd entries 0"
This is a GitHub Issue
repo:Bento4
owner:axiomatic-systems
Title : Add audio track causes the mp4 file to have "invalid stsd entries 0"
Issue date:

--- start body ---
It is confusing about the audio track parameters, in your sample, 
    AP4_Track* track = new AP4_Track(AP4_Track::TYPE_AUDIO,
                                     sample_table,
                                     0,                 // track id
                                     sample_rate,       // movie time scale
                                     sample_count*1024, // track duration
                                     sample_rate,       // media time scale
                                     sample_count*1024, // media duration
                                     language,          // language
                                     0, 0);             // width, height

If I used it directly in my own code, it usually causes unexpected long duration(exp. 1 minute video shows 40 minutes duration). Hence I modified the code above to

	m_nAudioSamples = Audio_Sample_table->GetSampleCount();
	AP4_UI64 movie_timescale = 1000;// since video track also uses 1000 as movie_timescale
	AP4_UI64 AudioTrackDuration = m_nAudioSamples * movie_timescale;
	AP4_UI64 MediaDuration = m_nAudioSamples * movie_timescale;
	AudioTrackDuration = AP4_ConvertTime(movie_timescale * m_nAudioSamples, m_sample_rate, movie_timescale);
	AP4_Track* track = new AP4_Track(AP4_Track::TYPE_AUDIO,
		Audio_Sample_table,
		2, //0,                 // assume video track id = 1, then audio track id = 2
		movie_timescale,        // movie time scale
		AudioTrackDuration, // track duration              
		m_sample_rate,       // media time scale
		MediaDuration, // media duration
		"und",             // language
		0, 0);             // width, height

       Now in this way, the muxer sometimes works, sometimes only have video track, and when probe with ffmpeg, it told me "invalid STSD entries 0".

        In order to match video track, what will be the right way to set the following parameters?
movie time scale
track duration
media time scale
media duration

Thanks.
Eric

--- end body ---
