diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2016-10-20 20:07:19 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-11-01 20:11:12 +0200 |
commit | 727fa1c7c378874f06eb2a998921be0a042c299f (patch) | |
tree | 13d48ac6d31b23511c887e2c859424d76c10770c | |
parent | 5a889647ba202d1fe8d902eef4251ca6ed1283bd (diff) |
qtmux: Be more clever with the default video track timescale
Use the number of milliframes per second for integral and drop-frame
framerates, as suggested by the QT file format specification and other
places. We already did that for integral framerates before, but not for
drop-frame framerates. This now keeps precision better.
For all other framerates, check if it's close to a well-known framerate
and use that instead.
https://bugzilla.gnome.org/show_bug.cgi?id=769041
-rw-r--r-- | gst/isomp4/gstqtmux.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c index 27f90906d..9a18fa063 100644 --- a/gst/isomp4/gstqtmux.c +++ b/gst/isomp4/gstqtmux.c @@ -3882,20 +3882,21 @@ refuse_renegotiation: } } -/* scale rate up or down by factor of 10 to fit into [1000,10000] interval */ -static guint32 -adjust_rate (guint64 rate) +/* return number of centiframes per second */ +static guint +adjust_rate (gint n, gint d) { - if (rate == 0) + if (n == 0) return 10000; - while (rate >= 10000) - rate /= 10; - - while (rate < 1000) - rate *= 10; + if (d != 1 && d != 1001) { + /* otherwise there are probably rounding errors and we should rather guess + * if it's close enough to a well known framerate */ + gst_video_guess_framerate (gst_util_uint64_scale (d, GST_SECOND, n), &n, + &d); + } - return (guint32) rate; + return gst_util_uint64_scale (n, 100, d); } static gboolean @@ -3973,7 +3974,7 @@ gst_qt_mux_video_sink_set_caps (GstQTPad * qtpad, GstCaps * caps) /* bring frame numerator into a range that ensures both reasonable resolution * as well as a fair duration */ rate = qtmux->trak_timescale ? - qtmux->trak_timescale : adjust_rate (framerate_num); + qtmux->trak_timescale : adjust_rate (framerate_num, framerate_den); GST_DEBUG_OBJECT (qtmux, "Rate of video track selected: %" G_GUINT32_FORMAT, rate); |