Commit c118b0cb authored by François Cartegnie's avatar François Cartegnie 🤞

mux: mp4: add code path for mehd

parent c9e1c0b8
......@@ -209,8 +209,9 @@ block_t * ForgedInitSegment::buildMoovBox()
mp4mux_trackinfo_t trackinfo;
mp4mux_trackinfo_Init(&trackinfo);
const Timescale &trackTimescale = inheritTimescale();
trackinfo.i_track_id = 0x01; /* Will always be 1st and unique track; tfhd patched on block read */
trackinfo.i_timescale = inheritTimescale();
trackinfo.i_timescale = (uint64_t) trackTimescale;
trackinfo.i_read_duration = duration.Get();
trackinfo.i_trex_default_length = 1;
trackinfo.i_trex_default_size = 1;
......@@ -276,7 +277,9 @@ block_t * ForgedInitSegment::buildMoovBox()
bo_t *box = NULL;
if(mp4mux_CanMux( NULL, &trackinfo.fmt ))
box = mp4mux_GetMoovBox(NULL, &p_tracks, 1, true, false, false, false);
box = mp4mux_GetMoovBox(NULL, &p_tracks, 1,
trackTimescale.ToTime(duration.Get()),
true, false, false, false);
mp4mux_trackinfo_Clear(&trackinfo);
......
......@@ -1475,19 +1475,19 @@ static bo_t *GetStblBox(vlc_object_t *p_obj, mp4mux_trackinfo_t *p_track, bool b
}
bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, unsigned int i_tracks,
bool b_fragmented, bool b_mov, bool b_64_ext, bool b_stco64)
int64_t i_movie_duration,
bool b_fragmented, bool b_mov, bool b_64_ext, bool b_stco64 )
{
bo_t *moov, *mvhd;
uint32_t i_movie_timescale = 90000;
int64_t i_movie_duration = 0;
int64_t i_timestamp = get_timestamp();
moov = box_new("moov");
if(!moov)
return NULL;
/* Create general info */
if ( !b_fragmented )
if( i_movie_duration == 0 && !b_fragmented )
{
for (unsigned int i = 0; i < i_tracks; i++) {
mp4mux_trackinfo_t *p_stream = pp_tracks[i];
......@@ -1498,8 +1498,6 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
i_movie_duration = i_movie_duration * i_movie_timescale / CLOCK_FREQ;
}
else
i_movie_duration = 0;
/* *** add /moov/mvhd *** */
if (!b_64_ext) {
......@@ -1849,28 +1847,43 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
if ( b_fragmented )
{
bo_t *mvex = box_new("mvex");
for (unsigned int i_trak = 0; mvex && i_trak < i_tracks; i_trak++)
if( mvex )
{
mp4mux_trackinfo_t *p_stream = pp_tracks[i_trak];
/* Try to find some defaults */
if ( p_stream->i_entry_count )
if( i_movie_duration )
{
// FIXME: find highest occurence
p_stream->i_trex_default_length = p_stream->entry[0].i_length;
p_stream->i_trex_default_size = p_stream->entry[0].i_size;
bo_t *mehd = box_full_new("mehd", b_64_ext ? 1 : 0, 0);
if(mehd)
{
if(b_64_ext)
bo_add_64be(mehd, i_movie_duration * i_movie_timescale / CLOCK_FREQ);
else
bo_add_32be(mehd, i_movie_duration * i_movie_timescale / CLOCK_FREQ);
box_gather(mvex, mehd);
}
}
for (unsigned int i_trak = 0; mvex && i_trak < i_tracks; i_trak++)
{
mp4mux_trackinfo_t *p_stream = pp_tracks[i_trak];
/* *** add /mvex/trex *** */
bo_t *trex = box_full_new("trex", 0, 0);
bo_add_32be(trex, p_stream->i_track_id);
bo_add_32be(trex, 1); // sample desc index
bo_add_32be(trex, (uint64_t)p_stream->i_trex_default_length * p_stream->i_timescale / CLOCK_FREQ); // sample duration
bo_add_32be(trex, p_stream->i_trex_default_size); // sample size
bo_add_32be(trex, 0); // sample flags
box_gather(mvex, trex);
/* Try to find some defaults */
if ( p_stream->i_entry_count )
{
// FIXME: find highest occurence
p_stream->i_trex_default_length = p_stream->entry[0].i_length;
p_stream->i_trex_default_size = p_stream->entry[0].i_size;
}
/* *** add /mvex/trex *** */
bo_t *trex = box_full_new("trex", 0, 0);
bo_add_32be(trex, p_stream->i_track_id);
bo_add_32be(trex, 1); // sample desc index
bo_add_32be(trex, (uint64_t)p_stream->i_trex_default_length * p_stream->i_timescale / CLOCK_FREQ); // sample duration
bo_add_32be(trex, p_stream->i_trex_default_size); // sample size
bo_add_32be(trex, 0); // sample flags
box_gather(mvex, trex);
}
box_gather(moov, mvex);
}
box_gather(moov, mvex);
}
if(moov->b)
......
......@@ -85,4 +85,5 @@ void box_gather (bo_t *box, bo_t *box2);
bool mp4mux_CanMux(vlc_object_t *, const es_format_t *);
bo_t *mp4mux_GetFtyp(vlc_fourcc_t, uint32_t, vlc_fourcc_t[], size_t i_fourcc);
bo_t *mp4mux_GetMoovBox(vlc_object_t *, mp4mux_trackinfo_t **pp_tracks, unsigned int i_tracks,
bool b_fragmented, bool b_mov, bool b_64ext, bool b_stco64);
int64_t i_movie_duration,
bool b_fragmented, bool b_mov, bool b_64ext, bool b_stco64);
......@@ -1190,7 +1190,7 @@ static bo_t *BuildMoov(sout_mux_t *p_mux)
for(unsigned int i=0; i<p_sys->i_nb_streams; i++)
pp_infos[i] = &p_sys->pp_streams[i]->mux;
}
bo_t *p_moov = mp4mux_GetMoovBox(VLC_OBJECT(p_mux), pp_infos, p_sys->i_nb_streams,
bo_t *p_moov = mp4mux_GetMoovBox(VLC_OBJECT(p_mux), pp_infos, p_sys->i_nb_streams, 0,
p_sys->b_fragmented, p_sys->b_mov, p_sys->b_64_ext, b_stco64);
free(pp_infos);
return p_moov;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment