From 850a45aef10b50a2344a71055a30987aea23e48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Fri, 21 Jul 2017 10:30:19 +0200 Subject: [PATCH] lavf/movenc: support GPMF track (gpmd) remuxing See https://github.com/gopro/gpmf-parser for more information on the data stream itself. --- libavformat/movenc.c | 25 +++++++++++++++++++++++++ tests/fate/mov.mak | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 3989ac167e..0e5b45d150 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -2060,6 +2060,18 @@ static int mov_write_tmcd_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } +static int mov_write_gpmd_tag(AVIOContext *pb, const MOVTrack *track) +{ + int64_t pos = avio_tell(pb); + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "gpmd"); + avio_wb32(pb, 0); /* Reserved */ + avio_wb16(pb, 0); /* Reserved */ + avio_wb16(pb, 1); /* Data-reference index */ + avio_wb32(pb, 0); /* Reserved */ + return update_size(pb, pos); +} + static int mov_write_stsd_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); @@ -2077,6 +2089,8 @@ static int mov_write_stsd_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext mov_write_rtp_tag(pb, track); else if (track->par->codec_tag == MKTAG('t','m','c','d')) mov_write_tmcd_tag(pb, track); + else if (track->par->codec_tag == MKTAG('g','p','m','d')) + mov_write_gpmd_tag(pb, track); return update_size(pb, pos); } @@ -2377,6 +2391,12 @@ static int mov_write_gmhd_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "tmcd"); mov_write_tcmi_tag(pb, track); update_size(pb, tmcd_pos); + } else if (track->par->codec_tag == MKTAG('g','p','m','d')) { + int64_t gpmd_pos = avio_tell(pb); + avio_wb32(pb, 0); /* size */ + ffio_wfourcc(pb, "gpmd"); + avio_wb32(pb, 0); /* version */ + update_size(pb, gpmd_pos); } return update_size(pb, pos); } @@ -2443,6 +2463,9 @@ static int mov_write_hdlr_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra } else if (track->par->codec_tag == MKTAG('t','m','c','d')) { hdlr_type = "tmcd"; descr = "TimeCodeHandler"; + } else if (track->par->codec_tag == MKTAG('g','p','m','d')) { + hdlr_type = "meta"; + descr = "GoPro MET"; // GoPro Metadata } else { av_log(s, AV_LOG_WARNING, "Unknown hldr_type for %s, writing dummy values\n", @@ -2514,6 +2537,8 @@ static int mov_write_minf_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext mov_write_nmhd_tag(pb); else mov_write_gmhd_tag(pb, track); + } else if (track->tag == MKTAG('g','p','m','d')) { + mov_write_gmhd_tag(pb, track); } if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */ mov_write_hdlr_tag(s, pb, NULL); diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak index eac2f3789e..cfdada7a2e 100644 --- a/tests/fate/mov.mak +++ b/tests/fate/mov.mak @@ -6,6 +6,7 @@ FATE_MOV = fate-mov-3elist \ fate-mov-1elist-ends-last-bframe \ fate-mov-2elist-elist1-ends-bframe \ fate-mov-3elist-encrypted \ + fate-mov-gpmf-remux \ FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \ fate-mov-zombie \ @@ -47,3 +48,7 @@ fate-mov-init-nonkeyframe: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_packets - fate-mov-displaymatrix: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream=display_aspect_ratio,sample_aspect_ratio:stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mov/displaymatrix.mov fate-mov-spherical-mono: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_side_data_list -select_streams v -v 0 $(TARGET_SAMPLES)/mov/spherical.mov + +fate-mov-gpmf-remux: CMD = md5 -i $(TARGET_SAMPLES)/mov/fake-gp-media-with-real-gpmf.mp4 -map 0 -c copy -fflags +bitexact -f mp4 +fate-mov-gpmf-remux: CMP = oneline +fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3