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
This commit is contained in:
Sebastian Dröge 2016-10-20 20:07:19 +03:00
parent 5a889647ba
commit 727fa1c7c3

View file

@ -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;
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);
}
while (rate < 1000)
rate *= 10;
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);