mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-18 05:16:05 +00:00
qtdemux: Parse and use creation time tag from mvhd
Expose creation time from mvhd as a datetime tag Fixes #634928
This commit is contained in:
parent
be2d04e040
commit
6511730ba1
1 changed files with 35 additions and 4 deletions
|
@ -79,6 +79,12 @@
|
||||||
/* if the sample index is larger than this, something is likely wrong */
|
/* if the sample index is larger than this, something is likely wrong */
|
||||||
#define QTDEMUX_MAX_SAMPLE_INDEX_SIZE (50*1024*1024)
|
#define QTDEMUX_MAX_SAMPLE_INDEX_SIZE (50*1024*1024)
|
||||||
|
|
||||||
|
/* For converting qt creation times to unix epoch times */
|
||||||
|
#define QTDEMUX_SECONDS_PER_DAY (60 * 60 * 24)
|
||||||
|
#define QTDEMUX_LEAP_YEARS_FROM_1904_TO_1970 17
|
||||||
|
#define QTDEMUX_SECONDS_FROM_1904_TO_1970 (((1970 - 1904) * (guint64) 365 + \
|
||||||
|
QTDEMUX_LEAP_YEARS_FROM_1904_TO_1970) * QTDEMUX_SECONDS_PER_DAY)
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY (qtdemux_debug);
|
GST_DEBUG_CATEGORY (qtdemux_debug);
|
||||||
|
|
||||||
/*typedef struct _QtNode QtNode; */
|
/*typedef struct _QtNode QtNode; */
|
||||||
|
@ -7004,6 +7010,7 @@ qtdemux_parse_udta (GstQTDemux * qtdemux, GNode * udta)
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (qtdemux, "new tag list");
|
GST_DEBUG_OBJECT (qtdemux, "new tag list");
|
||||||
|
if (!qtdemux->tag_list)
|
||||||
qtdemux->tag_list = gst_tag_list_new ();
|
qtdemux->tag_list = gst_tag_list_new ();
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -7255,6 +7262,8 @@ qtdemux_parse_tree (GstQTDemux * qtdemux)
|
||||||
GNode *trak;
|
GNode *trak;
|
||||||
GNode *udta;
|
GNode *udta;
|
||||||
gint64 duration;
|
gint64 duration;
|
||||||
|
guint64 creation_time;
|
||||||
|
GstDateTime *datetime = NULL;
|
||||||
gint version;
|
gint version;
|
||||||
|
|
||||||
mvhd = qtdemux_tree_get_child_by_type (qtdemux->moov_node, FOURCC_mvhd);
|
mvhd = qtdemux_tree_get_child_by_type (qtdemux->moov_node, FOURCC_mvhd);
|
||||||
|
@ -7265,9 +7274,11 @@ qtdemux_parse_tree (GstQTDemux * qtdemux)
|
||||||
|
|
||||||
version = QT_UINT8 ((guint8 *) mvhd->data + 8);
|
version = QT_UINT8 ((guint8 *) mvhd->data + 8);
|
||||||
if (version == 1) {
|
if (version == 1) {
|
||||||
|
creation_time = QT_UINT64 ((guint8 *) mvhd->data + 12);
|
||||||
qtdemux->timescale = QT_UINT32 ((guint8 *) mvhd->data + 28);
|
qtdemux->timescale = QT_UINT32 ((guint8 *) mvhd->data + 28);
|
||||||
qtdemux->duration = QT_UINT64 ((guint8 *) mvhd->data + 32);
|
qtdemux->duration = QT_UINT64 ((guint8 *) mvhd->data + 32);
|
||||||
} else if (version == 0) {
|
} else if (version == 0) {
|
||||||
|
creation_time = QT_UINT32 ((guint8 *) mvhd->data + 12);
|
||||||
qtdemux->timescale = QT_UINT32 ((guint8 *) mvhd->data + 20);
|
qtdemux->timescale = QT_UINT32 ((guint8 *) mvhd->data + 20);
|
||||||
qtdemux->duration = QT_UINT32 ((guint8 *) mvhd->data + 24);
|
qtdemux->duration = QT_UINT32 ((guint8 *) mvhd->data + 24);
|
||||||
} else {
|
} else {
|
||||||
|
@ -7275,6 +7286,26 @@ qtdemux_parse_tree (GstQTDemux * qtdemux)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Moving qt creation time (secs since 1904) to unix time */
|
||||||
|
if (creation_time != 0) {
|
||||||
|
if (creation_time > QTDEMUX_SECONDS_FROM_1904_TO_1970) {
|
||||||
|
creation_time -= QTDEMUX_SECONDS_FROM_1904_TO_1970;
|
||||||
|
datetime = gst_date_time_new_from_unix_epoch_local_time (creation_time);
|
||||||
|
} else {
|
||||||
|
GST_WARNING_OBJECT (qtdemux, "Can't handle datetimes before 1970 yet, "
|
||||||
|
"please file a bug at http://bugzilla.gnome.org");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (datetime) {
|
||||||
|
if (!qtdemux->tag_list)
|
||||||
|
qtdemux->tag_list = gst_tag_list_new ();
|
||||||
|
|
||||||
|
/* Use KEEP as explicit tags should have a higher priority than mvhd tag */
|
||||||
|
gst_tag_list_add (qtdemux->tag_list, GST_TAG_MERGE_KEEP, GST_TAG_DATE_TIME,
|
||||||
|
datetime, NULL);
|
||||||
|
gst_date_time_unref (datetime);
|
||||||
|
}
|
||||||
|
|
||||||
GST_INFO_OBJECT (qtdemux, "timescale: %u", qtdemux->timescale);
|
GST_INFO_OBJECT (qtdemux, "timescale: %u", qtdemux->timescale);
|
||||||
GST_INFO_OBJECT (qtdemux, "duration: %" G_GUINT64_FORMAT, qtdemux->duration);
|
GST_INFO_OBJECT (qtdemux, "duration: %" G_GUINT64_FORMAT, qtdemux->duration);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue