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

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


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri May  3 11:14:26 2019 +0200| [5d23e0ed7866a10633a3228f5698711e3a5da657] | committer: Francois Cartegnie

mux: mp4: refactor and fix tkhd visible values

(cherry picked from commit e6582ad46232ecc8d1181e14d82bd4f1fc834d5b)

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

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

diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 95d3aef270..cda59612e7 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -1289,6 +1289,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_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, unsigned int i_tracks,
                          int64_t i_movie_duration,
                          bool b_fragmented, bool b_mov, bool b_64_ext, bool b_stco64 )
@@ -1423,34 +1433,24 @@ bo_t * mp4mux_GetMoovBox(vlc_object_t *p_obj, mp4mux_trackinfo_t **pp_tracks, un
             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.i_visible_width) << 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 < i_tracks; i++) {
-                mp4mux_trackinfo_t *tk = pp_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;
-                }
+            unsigned i_width = 320;
+            unsigned i_height = 200;
+            /* Find video track for SPU representation */
+            for (unsigned int i = 0; i < i_tracks; i++)
+            {
+                const mp4mux_trackinfo_t *tk = pp_tracks[i];
+                if (tk->fmt.i_cat != VIDEO_ES)
+                    continue;
+                i_width = ApplyARtoWidth(tk->fmt.video.i_visible_width);
+                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