X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmux.c;h=98ec7a4cf2d600429550d037c0976399fa9f18b2;hb=b1b870fbd7185bffbe27c5918001b40a8ff8b920;hp=c7e176abb3b1fb4f38568772fad4e1dddf924b16;hpb=48d30f6733368f317a61901c61a78a10402eea7b;p=ffmpeg diff --git a/libavformat/mux.c b/libavformat/mux.c index c7e176abb3b..98ec7a4cf2d 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -395,7 +395,7 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) return ret; } - if ((ret = init_pts(s) < 0)) + if ((ret = init_pts(s)) < 0) return ret; return 0; @@ -490,13 +490,12 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) */ static inline int split_write_packet(AVFormatContext *s, AVPacket *pkt) { - int ret; - AVPacket spkt = *pkt; + int ret, did_split; - av_packet_split_side_data(&spkt); - ret = s->oformat->write_packet(s, &spkt); - spkt.data = NULL; - av_destruct_packet(&spkt); + did_split = av_packet_split_side_data(pkt); + ret = s->oformat->write_packet(s, pkt); + if (did_split) + av_packet_merge_side_data(pkt); return ret; } @@ -550,20 +549,26 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, next_point = &s->packet_buffer; } - if (*next_point) { - if (chunked) { - uint64_t max= av_rescale_q(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base); - if ( st->interleaver_chunk_size + pkt->size <= s->max_chunk_size-1U - && st->interleaver_chunk_duration + pkt->duration <= max-1U) { - st->interleaver_chunk_size += pkt->size; - st->interleaver_chunk_duration += pkt->duration; - goto next_non_null; - } else { - st->interleaver_chunk_size = + if (chunked) { + uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP); + st->interleaver_chunk_size += pkt->size; + st->interleaver_chunk_duration += pkt->duration; + if ( (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size) + || (max && st->interleaver_chunk_duration > max)) { + st->interleaver_chunk_size = 0; + this_pktl->pkt.flags |= CHUNK_START; + if (max && st->interleaver_chunk_duration > max) { + int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; + int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset; + + st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; + } else st->interleaver_chunk_duration = 0; - this_pktl->pkt.flags |= CHUNK_START; - } } + } + if (*next_point) { + if (chunked && !(this_pktl->pkt.flags & CHUNK_START)) + goto next_non_null; if (compare(s, &s->packet_buffer_end->pkt, pkt)) { while ( *next_point