]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mux.c
Merge commit '7a76371437f9562c3414f985523f883489e3936a'
[ffmpeg] / libavformat / mux.c
index 816e8567ce82fc7117def53a084bdbfaa985289c..e500531789ecbcc526edb186e24e9b4c4b6665ec 100644 (file)
@@ -309,12 +309,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-        /* update internal context from codecpar, old bsf api needs this
-         * FIXME: remove when autobsf uses new bsf API */
-        ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
-        if (ret < 0)
-            goto fail;
-
         if (!st->time_base.num) {
             /* fall back on the default timebase values */
             if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate)
@@ -581,6 +575,7 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *
 
     if (!s->internal->missing_ts_warning &&
         !(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
+        (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC) || (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)) &&
         (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
         av_log(s, AV_LOG_WARNING,
                "Timestamps are unset in a packet for stream %d. "
@@ -692,12 +687,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
  */
 static int write_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    int ret;
+    int ret, did_split;
     int64_t pts_backup, dts_backup;
 
     pts_backup = pkt->pts;
     dts_backup = pkt->dts;
 
+    // If the timestamp offsetting below is adjusted, adjust
+    // ff_interleaved_peek similarly.
     if (s->output_ts_offset) {
         AVStream *st = s->streams[pkt->stream_index];
         int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
@@ -755,6 +752,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         }
     }
 
+    did_split = av_packet_split_side_data(pkt);
+
     if (!s->internal->header_written) {
         ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s);
         if (ret < 0)
@@ -778,6 +777,9 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
 fail:
+    if (did_split)
+        av_packet_merge_side_data(pkt);
+
     if (ret < 0) {
         pkt->pts = pts_backup;
         pkt->dts = dts_backup;
@@ -873,6 +875,9 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
         }
     }
 
+    if (st->internal->nb_bsfcs)
+        av_packet_split_side_data(pkt);
+
     for (i = 0; i < st->internal->nb_bsfcs; i++) {
         AVBSFContext *ctx = st->internal->bsfcs[i];
         if (i > 0) {
@@ -913,7 +918,7 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) {
 
 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
-    int ret, did_split = 0;
+    int ret;
 
     ret = prepare_input_packet(s, pkt);
     if (ret < 0)
@@ -934,8 +939,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
             return ret;
         }
         return 1;
-    } else
-        did_split = av_packet_split_side_data(pkt);
+    }
 
     ret = do_packet_auto_bsf(s, pkt);
     if (ret <= 0)
@@ -954,10 +958,6 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
 
     if (ret >= 0)
         s->streams[pkt->stream_index]->nb_frames++;
-
-    if (did_split)
-        av_packet_merge_side_data(pkt);
-
     return ret;
 }
 
@@ -1183,23 +1183,30 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
     }
 }
 
-const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream, int64_t *ts_offset)
+int ff_interleaved_peek(AVFormatContext *s, int stream,
+                        AVPacket *pkt, int add_offset)
 {
     AVPacketList *pktl = s->internal->packet_buffer;
     while (pktl) {
         if (pktl->pkt.stream_index == stream) {
-            AVPacket *pkt = &pktl->pkt;
-            AVStream *st = s->streams[pkt->stream_index];
-            *ts_offset = st->mux_ts_offset;
-
-            if (s->output_ts_offset)
-                *ts_offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
-
-            return pkt;
+            *pkt = pktl->pkt;
+            if (add_offset) {
+                AVStream *st = s->streams[pkt->stream_index];
+                int64_t offset = st->mux_ts_offset;
+
+                if (s->output_ts_offset)
+                    offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
+
+                if (pkt->dts != AV_NOPTS_VALUE)
+                    pkt->dts += offset;
+                if (pkt->pts != AV_NOPTS_VALUE)
+                    pkt->pts += offset;
+            }
+            return 0;
         }
         pktl = pktl->next;
     }
-    return NULL;
+    return AVERROR(ENOENT);
 }
 
 /**
@@ -1224,7 +1231,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
 
 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
-    int ret, did_split = 0, flush = 0;
+    int ret, flush = 0;
 
     ret = prepare_input_packet(s, pkt);
     if (ret < 0)
@@ -1233,8 +1240,6 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
     if (pkt) {
         AVStream *st = s->streams[pkt->stream_index];
 
-        did_split = av_packet_split_side_data(pkt);
-
         ret = do_packet_auto_bsf(s, pkt);
         if (ret == 0)
             return 0;
@@ -1282,9 +1287,6 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
             return s->pb->error;
     }
 fail:
-    if (did_split)
-        av_packet_merge_side_data(pkt);
-
     av_packet_unref(pkt);
     return ret;
 }