diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c index f99a346336c289df401829b2235e5f4c4ac6dffb..8b9849d4123e4e393f9e17c17ebf3bf5c6407bb5 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) }