[FFmpeg-cvslog] avformat/movenc: use AVProducerReferenceTime side data to write the prft atom

James Almer git at videolan.org
Thu Jan 16 05:13:03 EET 2020


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri Oct  4 12:04:17 2019 -0300| [7abc0979e6c64fae799ce3345026e6ba595c4a34] | committer: James Almer

avformat/movenc: use AVProducerReferenceTime side data to write the prft atom

If not available, set flags to 24 (bits 4 and 5), to signal the wallclock value
is read at the time of writing the atom.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7abc0979e6c64fae799ce3345026e6ba595c4a34
---

 libavformat/movenc.c | 18 ++++++++++++++++--
 libavformat/movenc.h |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4a3a594bc6..b2996dc22f 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4630,6 +4630,7 @@ static int mov_write_prft_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks)
 {
     int64_t pos = avio_tell(pb), pts_us, ntp_ts;
     MOVTrack *first_track;
+    int flags = 24;
 
     /* PRFT should be associated with at most one track. So, choosing only the
      * first track. */
@@ -4648,7 +4649,11 @@ static int mov_write_prft_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks)
     }
 
     if (mov->write_prft == MOV_PRFT_SRC_WALLCLOCK) {
-        ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time(av_gettime()));
+        if (first_track->cluster[0].prft.wallclock) {
+            ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time(first_track->cluster[0].prft.wallclock));
+            flags = first_track->cluster[0].prft.flags;
+        } else
+            ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time(av_gettime()));
     } else if (mov->write_prft == MOV_PRFT_SRC_PTS) {
         pts_us = av_rescale_q(first_track->cluster[0].pts,
                               first_track->st->time_base, AV_TIME_BASE_Q);
@@ -4662,7 +4667,7 @@ static int mov_write_prft_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks)
     avio_wb32(pb, 0);                           // Size place holder
     ffio_wfourcc(pb, "prft");                   // Type
     avio_w8(pb, 1);                             // Version
-    avio_wb24(pb, 0);                           // Flags
+    avio_wb24(pb, flags);                       // Flags
     avio_wb32(pb, first_track->track_id);       // reference track ID
     avio_wb64(pb, ntp_ts);                      // NTP time stamp
     avio_wb64(pb, first_track->cluster[0].pts); //media time
@@ -5356,8 +5361,10 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     MOVTrack *trk = &mov->tracks[pkt->stream_index];
     AVCodecParameters *par = trk->par;
+    AVProducerReferenceTime *prft;
     unsigned int samples_in_chunk = 0;
     int size = pkt->size, ret = 0;
+    int prft_size;
     uint8_t *reformatted_data = NULL;
 
     ret = check_pkt(s, pkt);
@@ -5629,6 +5636,13 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
         trk->cluster[trk->entry].flags |= MOV_DISPOSABLE_SAMPLE;
         trk->has_disposable++;
     }
+
+    prft = (AVProducerReferenceTime *)av_packet_get_side_data(pkt, AV_PKT_DATA_PRFT, &prft_size);
+    if (prft && prft_size == sizeof(AVProducerReferenceTime))
+        memcpy(&trk->cluster[trk->entry].prft, prft, prft_size);
+    else
+        memset(&trk->cluster[trk->entry].prft, 0, sizeof(AVProducerReferenceTime));
+
     trk->entry++;
     trk->sample_count += samples_in_chunk;
     mov->mdat_size    += size;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 68d6f23a5a..a3c6467c67 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -56,6 +56,7 @@ typedef struct MOVIentry {
 #define MOV_PARTIAL_SYNC_SAMPLE 0x0002
 #define MOV_DISPOSABLE_SAMPLE   0x0004
     uint32_t     flags;
+    AVProducerReferenceTime prft;
 } MOVIentry;
 
 typedef struct HintSample {



More information about the ffmpeg-cvslog mailing list