[vlc-commits] mux: mp4: add code path for mehd

Francois Cartegnie git at videolan.org
Sun Aug 14 14:39:56 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Aug 14 13:38:40 2016 +0200| [c118b0cb04d035b8525cd5178da796874e51b6ac] | committer: Francois Cartegnie

mux: mp4: add code path for mehd

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c118b0cb04d035b8525cd5178da796874e51b6ac
---

 .../demux/smooth/playlist/ForgedInitSegment.cpp    |  7 ++-
 modules/mux/mp4/libmp4mux.c                        | 57 +++++++++++++---------
 modules/mux/mp4/libmp4mux.h                        |  3 +-
 modules/mux/mp4/mp4.c                              |  2 +-
 4 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/modules/demux/smooth/playlist/ForgedInitSegment.cpp b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
index 3a9b3e0..af48521 100644
--- a/modules/demux/smooth/playlist/ForgedInitSegment.cpp
+++ b/modules/demux/smooth/playlist/ForgedInitSegment.cpp
@@ -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);
 
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index e5d482f..dcb2294 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -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)
diff --git a/modules/mux/mp4/libmp4mux.h b/modules/mux/mp4/libmp4mux.h
index 93d3050..91e6995 100644
--- a/modules/mux/mp4/libmp4mux.h
+++ b/modules/mux/mp4/libmp4mux.h
@@ -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);
diff --git a/modules/mux/mp4/mp4.c b/modules/mux/mp4/mp4.c
index c7d98e0..5d10d6c 100644
--- a/modules/mux/mp4/mp4.c
+++ b/modules/mux/mp4/mp4.c
@@ -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;



More information about the vlc-commits mailing list