qtmux: Make sure timecode uses the same timescale as video
Don't blindly derive it from the frame rate, but try to get the per-pad
configured timescale first (if it exists)
https://bugzilla.gnome.org/show_bug.cgi?id=792680
diff --git a/gst/isomp4/atoms.c b/gst/isomp4/atoms.c
index 9be74ac..eb90b79 100644
--- a/gst/isomp4/atoms.c
+++ b/gst/isomp4/atoms.c
@@ -3813,17 +3813,18 @@
static SampleTableEntryTMCD *
atom_trak_add_timecode_entry (AtomTRAK * trak, AtomsContext * context,
- GstVideoTimeCode * tc)
+ guint32 trak_timescale, GstVideoTimeCode * tc)
{
AtomSTSD *stsd = &trak->mdia.minf.stbl.stsd;
SampleTableEntryTMCD *tmcd = sample_entry_tmcd_new ();
+ g_assert (trak_timescale != 0);
+
trak->mdia.hdlr.component_type = FOURCC_mhlr;
trak->mdia.hdlr.handler_type = FOURCC_tmcd;
g_free (trak->mdia.hdlr.name);
trak->mdia.hdlr.name = g_strdup ("Time Code Media Handler");
- trak->mdia.mdhd.time_info.timescale =
- atom_framerate_to_timescale (tc->config.fps_n, tc->config.fps_d);
+ trak->mdia.mdhd.time_info.timescale = trak_timescale;
tmcd->se.kind = TIMECODE;
tmcd->se.data_reference_index = 1;
@@ -3832,9 +3833,10 @@
tmcd->tc_flags |= TC_DROP_FRAME;
tmcd->name.language_code = 0;
tmcd->name.name = g_strdup ("Tape");
- tmcd->timescale =
- atom_framerate_to_timescale (tc->config.fps_n, tc->config.fps_d);
- tmcd->frame_duration = 100;
+ tmcd->timescale = trak_timescale;
+ tmcd->frame_duration =
+ gst_util_uint64_scale (tmcd->timescale, tc->config.fps_d,
+ tc->config.fps_n);
if (tc->config.fps_d == 1001)
tmcd->n_frames = tc->config.fps_n / 1000;
else
@@ -3991,7 +3993,7 @@
SampleTableEntryTMCD *
atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context,
- GstVideoTimeCode * tc)
+ guint32 trak_timescale, GstVideoTimeCode * tc)
{
SampleTableEntryTMCD *ste;
AtomGMHD *gmhd = trak->mdia.minf.gmhd;
@@ -4000,7 +4002,7 @@
return NULL;
}
- ste = atom_trak_add_timecode_entry (trak, context, tc);
+ ste = atom_trak_add_timecode_entry (trak, context, trak_timescale, tc);
gmhd = atom_gmhd_new ();
gmhd->gmin.graphics_mode = 0x0040;
diff --git a/gst/isomp4/atoms.h b/gst/isomp4/atoms.h
index 37b1906..f73cb9f 100644
--- a/gst/isomp4/atoms.h
+++ b/gst/isomp4/atoms.h
@@ -1039,7 +1039,7 @@
SubtitleSampleEntry * entry);
SampleTableEntryTMCD *
-atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context, GstVideoTimeCode * tc);
+atom_trak_set_timecode_type (AtomTRAK * trak, AtomsContext * context, guint trak_timescale, GstVideoTimeCode * tc);
void atom_trak_update_bitrates (AtomTRAK * trak, guint32 avg_bitrate,
guint32 max_bitrate);
diff --git a/gst/isomp4/gstqtmux.c b/gst/isomp4/gstqtmux.c
index e972285..12a654e 100644
--- a/gst/isomp4/gstqtmux.c
+++ b/gst/isomp4/gstqtmux.c
@@ -2588,7 +2588,8 @@
qpad->trak->tref = atom_tref_new (FOURCC_tmcd);
atom_tref_add_entry (qpad->trak->tref, qpad->tc_trak->tkhd.track_ID);
- atom_trak_set_timecode_type (qpad->tc_trak, qtmux->context, tc);
+ atom_trak_set_timecode_type (qpad->tc_trak, qtmux->context,
+ qpad->trak->mdia.mdhd.time_info.timescale, tc);
atom_trak_add_samples (qpad->tc_trak, 1, 1, 4,
qtmux->mdat_size, FALSE, 0);
@@ -4086,7 +4087,8 @@
pad->trak->tref = atom_tref_new (FOURCC_tmcd);
atom_tref_add_entry (pad->trak->tref, pad->tc_trak->tkhd.track_ID);
- atom_trak_set_timecode_type (pad->tc_trak, qtmux->context, pad->first_tc);
+ atom_trak_set_timecode_type (pad->tc_trak, qtmux->context,
+ pad->trak->mdia.mdhd.time_info.timescale, pad->first_tc);
tc_buf = gst_buffer_new_allocate (NULL, 4, NULL);
szret = gst_buffer_fill (tc_buf, 0, &frames_since_daily_jam, 4);