[vlc-commits] mux: mp4: refactor and fix tkhd visible values

Francois Cartegnie git at videolan.org
Fri May 3 13:50:13 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri May  3 11:14:26 2019 +0200| [33ad85ac64195b98c38123a3e18e702799bc1b2c] | committer: Francois Cartegnie

mux: mp4: refactor and fix tkhd visible values

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

 modules/mux/mp4/libmp4mux.c | 46 ++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index f99a346336..8b9849d412 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -1612,6 +1612,16 @@ static bo_t *GetStblBox(vlc_object_t *p_obj, mp4mux_trackinfo_t *p_track, bool b
     return stbl;
 }
 
+static unsigned ApplyARtoWidth(const video_format_t *vfmt)
+{
+    if (vfmt->i_sar_num > 0 && vfmt->i_sar_den > 0)
+    {
+        return (int64_t)vfmt->i_sar_num *
+               (int64_t)vfmt->i_visible_width / vfmt->i_sar_den;
+    }
+    else return vfmt->i_visible_width;
+}
+
 bo_t * mp4mux_GetMoov(mp4mux_handle_t *h, vlc_object_t *p_obj, vlc_tick_t i_duration)
 {
     bo_t            *moov, *mvhd;
@@ -1746,34 +1756,24 @@ bo_t * mp4mux_GetMoov(mp4mux_handle_t *h, vlc_object_t *p_obj, vlc_tick_t i_dura
             bo_add_32be(tkhd, 0);                 // width (presentation)
             bo_add_32be(tkhd, 0);                 // height(presentation)
         } else if (p_stream->fmt.i_cat == VIDEO_ES) {
-            int i_width = p_stream->fmt.video.i_width << 16;
-            if (p_stream->fmt.video.i_sar_num > 0 && p_stream->fmt.video.i_sar_den > 0) {
-                i_width = (int64_t)p_stream->fmt.video.i_sar_num *
-                          ((int64_t)p_stream->fmt.video.i_width << 16) /
-                          p_stream->fmt.video.i_sar_den;
-            }
             // width (presentation)
-            bo_add_32be(tkhd, i_width);
+            bo_add_32be(tkhd, ApplyARtoWidth(&p_stream->fmt.video) << 16);
             // height(presentation)
-            bo_add_32be(tkhd, p_stream->fmt.video.i_height << 16);
+            bo_add_32be(tkhd, p_stream->fmt.video.i_visible_height << 16);
         } else {
-            int i_width = 320 << 16;
-            int i_height = 200;
-            for (unsigned int i = 0; i < vlc_array_count(&h->tracks); i++) {
+            unsigned i_width = 320;
+            unsigned i_height = 200;
+            /* Find video track for SPU representation */
+            for (unsigned int i = 0; i < vlc_array_count(&h->tracks); i++)
+            {
                 const mp4mux_trackinfo_t *tk = vlc_array_item_at_index(&h->tracks, i);
-                if (tk->fmt.i_cat == VIDEO_ES) {
-                    if (tk->fmt.video.i_sar_num > 0 &&
-                        tk->fmt.video.i_sar_den > 0)
-                        i_width = (int64_t)tk->fmt.video.i_sar_num *
-                                  ((int64_t)tk->fmt.video.i_width << 16) /
-                                  tk->fmt.video.i_sar_den;
-                    else
-                        i_width = tk->fmt.video.i_width << 16;
-                    i_height = tk->fmt.video.i_height;
-                    break;
-                }
+                if (tk->fmt.i_cat != VIDEO_ES)
+                    continue;
+                i_width = ApplyARtoWidth(&tk->fmt.video);
+                i_height = tk->fmt.video.i_visible_height;
+                break;
             }
-            bo_add_32be(tkhd, i_width);     // width (presentation)
+            bo_add_32be(tkhd, i_width << 16);     // width (presentation)
             bo_add_32be(tkhd, i_height << 16);    // height(presentation)
         }
 



More information about the vlc-commits mailing list