Merge commit '9ad1e0c12caa440de860bd8f2122beb11d73815c'
authorHendrik Leppkes <h.leppkes@gmail.com>
Mon, 7 Sep 2015 14:19:40 +0000 (16:19 +0200)
committerHendrik Leppkes <h.leppkes@gmail.com>
Mon, 7 Sep 2015 14:19:40 +0000 (16:19 +0200)
* commit '9ad1e0c12caa440de860bd8f2122beb11d73815c':
  mux: Make sure that the data is actually written

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavformat/mux.c

@@@ -627,45 -342,23 +627,50 @@@ static int write_packet(AVFormatContex
          if (pkt->pts != AV_NOPTS_VALUE)
              pkt->pts += offset;
  
 -        if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
 -            av_log(s, AV_LOG_WARNING,
 -                   "Packets poorly interleaved, failed to avoid negative "
 -                   "timestamp %"PRId64" in stream %d.\n"
 -                   "Try -max_interleave_delta 0 as a possible workaround.\n",
 -                   pkt->dts, pkt->stream_index);
 +        if (s->internal->avoid_negative_ts_use_pts) {
 +            if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) {
 +                av_log(s, AV_LOG_WARNING, "failed to avoid negative "
 +                    "pts %s in stream %d.\n"
 +                    "Try -avoid_negative_ts 1 as a possible workaround.\n",
 +                    av_ts2str(pkt->dts),
 +                    pkt->stream_index
 +                );
 +            }
 +        } else {
 +            av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0 || s->max_interleave_delta > 0);
 +            if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
 +                av_log(s, AV_LOG_WARNING,
 +                    "Packets poorly interleaved, failed to avoid negative "
 +                    "timestamp %s in stream %d.\n"
 +                    "Try -max_interleave_delta 0 as a possible workaround.\n",
 +                    av_ts2str(pkt->dts),
 +                    pkt->stream_index
 +                );
 +            }
          }
      }
 -    ret = s->oformat->write_packet(s, pkt);
 +
 +    did_split = av_packet_split_side_data(pkt);
 +    if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
 +        AVFrame *frame = (AVFrame *)pkt->data;
 +        av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE);
 +        ret = s->oformat->write_uncoded_frame(s, pkt->stream_index, &frame, 0);
 +        av_frame_free(&frame);
 +    } else {
 +        ret = s->oformat->write_packet(s, pkt);
 +    }
  
-     if (s->flush_packets && s->pb && ret >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
-         avio_flush(s->pb);
+     if (s->pb && ret >= 0) {
 -        if (s->flags & AVFMT_FLAG_FLUSH_PACKETS)
++        if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
+             avio_flush(s->pb);
+         if (s->pb->error < 0)
+             ret = s->pb->error;
+     }
 +
 +    if (did_split)
 +        av_packet_merge_side_data(pkt);
 +
      return ret;
  }