X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fnutenc.c;h=44773924dd7e02227969fe015bcc54b401848123;hb=dfb0b9370d3621ab1f603e7bb8e142b1f6996562;hp=e9a3bb49db01b910669c9f718173809c027f4876;hpb=cd8087444bb459c7c62e21913adfef5ec09675cc;p=ffmpeg diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index e9a3bb49db0..44773924dd7 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -637,8 +637,10 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc) if (ret < 0) return ret; ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i); - if (ret < 0) + if (ret < 0) { + ffio_free_dyn_buf(&dyn_bc); return ret; + } put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE); } @@ -653,12 +655,13 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc) if (ret < 0) return ret; ret = write_streaminfo(nut, dyn_bc, i); - if (ret < 0) - return ret; if (ret > 0) put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); - else + else { ffio_free_dyn_buf(&dyn_bc); + if (ret < 0) + return ret; + } } for (i = 0; i < nut->avf->nb_chapters; i++) { @@ -765,8 +768,6 @@ static int nut_write_header(AVFormatContext *s) if (s->avoid_negative_ts < 0) s->avoid_negative_ts = 1; - avio_flush(bc); - return 0; } @@ -789,11 +790,12 @@ static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, flags |= FLAG_CHECKSUM; if (FFABS(pkt->pts - nus->last_pts) > nus->max_pts_distance) flags |= FLAG_CHECKSUM; - if (pkt->size < nut->header_len[fc->header_idx] || - (pkt->size > 4096 && fc->header_idx) || - memcmp(pkt->data, nut->header[fc->header_idx], - nut->header_len[fc->header_idx])) - flags |= FLAG_HEADER_IDX; + if (fc->header_idx) + if (pkt->size < nut->header_len[fc->header_idx] || + pkt->size > 4096 || + memcmp(pkt->data, nut->header [fc->header_idx], + nut->header_len[fc->header_idx])) + flags |= FLAG_HEADER_IDX; return flags | (fc->flags & FLAG_CODED); } @@ -1170,8 +1172,11 @@ static int nut_write_trailer(AVFormatContext *s) while (nut->header_count < 3) write_headers(s, bc); + if (!nut->sp_count) + return 0; + ret = avio_open_dyn_buf(&dyn_bc); - if (ret >= 0 && nut->sp_count) { + if (ret >= 0) { av_assert1(nut->write_index); // sp_count should be 0 if no index is going to be written write_index(nut, dyn_bc); put_packet(nut, bc, dyn_bc, 1, INDEX_STARTCODE);