From 194dcd91e08fd23d5a5f036d58f91a58812e5eaf Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Mon, 19 Sep 2022 21:11:39 +0200 Subject: [PATCH] qtmux: For video with N/1001 framerates use N as timescale instead of centiframes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is recommended by various specifications for such framerates, while for integer framerates we continue using centiframes to allow for some more accuracy. Using N means that no rounding error accumulates, eventually leading to outputting a packet with a different duration. Some tools such as MediaInfo determine that a stream is variable framerate if any packet has a different duration than the others, and there is no reason I can see for not using the full 4 bytes of resolution that the mp4 timescale offers. Example problematic pipeline: ``` videotestsrc num-buffers=5001 ! video/x-raw,framerate=60000/1001,width=320,height=240 ! \ videoconvert ! x264enc bitrate=80000 speed-preset=1 tune=zerolatency ! h264parse ! \ video/x-h264,profile=high-10 ! mp4mux ! filesink location="result2.mp4" ``` This results in a media file that MediaInfo detects as variable framerate because the 5000th packet has duration 99 instead of 100. With this patch, the timescale is 60000 and all packets have duration 1001. Related issue for context: https://bugzilla.gnome.org/show_bug.cgi?id=769041 Co-authored-by: Sebastian Dröge Part-of: --- subprojects/gst-plugins-good/gst/isomp4/atoms.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/isomp4/atoms.c b/subprojects/gst-plugins-good/gst/isomp4/atoms.c index 829d0e5..cb9de63 100644 --- a/subprojects/gst-plugins-good/gst/isomp4/atoms.c +++ b/subprojects/gst-plugins-good/gst/isomp4/atoms.c @@ -3948,7 +3948,11 @@ atom_trak_add_audio_entry (AtomTRAK * trak, AtomsContext * context, return mp4a; } -/* return number of centiframes per second */ +/* Compute a timescale, rounding framerates when the denominator is not + * well-known (1001, 1). + * + * Returns 10000 for variable framerates. + */ guint atom_framerate_to_timescale (gint n, gint d) { @@ -3962,7 +3966,11 @@ atom_framerate_to_timescale (gint n, gint d) &d); } - return gst_util_uint64_scale (n, 100, d); + if (d == 1001) { + return n; + } else { + return gst_util_uint64_scale (n, 100, d); + } } static SampleTableEntryTMCD * -- 2.7.4