qtmux: For video with N/1001 framerates use N as timescale instead of centiframes

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 <sebastian@centricular.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3683>
This commit is contained in:
Mathieu Duponchelle 2022-09-19 21:11:39 +02:00 committed by Tim-Philipp Müller
parent 49dccf42b6
commit 903289613b

View file

@ -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 *