X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Favienc.c;h=297d5b8964ae71e77a8c90d5780867cc679a9e04;hb=af9e622776c9268fd473cc23a0fd6b29f0017f64;hp=ac0f04c3547fd83a51780ae39ceceeb2ca8c827f;hpb=fbd607dd560afe44c3b90de1e6cbe5265cac8f1e;p=ffmpeg diff --git a/libavformat/avienc.c b/libavformat/avienc.c index ac0f04c3547..297d5b8964a 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -31,7 +31,6 @@ #include "libavutil/avstring.h" #include "libavutil/avutil.h" #include "libavutil/internal.h" -#include "libavutil/intreadwrite.h" #include "libavutil/dict.h" #include "libavutil/avassert.h" #include "libavutil/timestamp.h" @@ -269,8 +268,8 @@ static int avi_write_header(AVFormatContext *s) int padding; if (s->nb_streams > AVI_MAX_STREAM_COUNT) { - av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n", - AVI_MAX_STREAM_COUNT); + av_log(s, AV_LOG_ERROR, "AVI does not support " + ">"AV_STRINGIFY(AVI_MAX_STREAM_COUNT)" streams\n"); return AVERROR(EINVAL); } @@ -459,6 +458,14 @@ static int avi_write_header(AVFormatContext *s) && par->format != AV_PIX_FMT_NONE) av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n", av_get_pix_fmt_name(par->format)); + + if (par->format == AV_PIX_FMT_PAL8) { + if (par->bits_per_coded_sample < 0 || par->bits_per_coded_sample > 8) { + av_log(s, AV_LOG_ERROR, "PAL8 with %d bps is not allowed\n", par->bits_per_coded_sample); + return AVERROR(EINVAL); + } + } + break; case AVMEDIA_TYPE_AUDIO: flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0; @@ -581,8 +588,6 @@ static int avi_write_header(AVFormatContext *s) avi->movi_list = ff_start_tag(pb, "LIST"); ffio_wfourcc(pb, "movi"); - avio_flush(pb); - return 0; } @@ -594,7 +599,6 @@ static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, int64_t pos; int au_byterate, au_ssize, au_scale; - avio_flush(pb); pos = avio_tell(pb); /* Updating one entry in the AVI OpenDML master index */ @@ -909,7 +913,7 @@ static int avi_write_trailer(AVFormatContext *s) AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; int res = 0; - int i, j, n, nb_frames; + int i, n, nb_frames; int64_t file_size; for (i = 0; i < s->nb_streams; i++) { @@ -962,10 +966,6 @@ static int avi_write_trailer(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVIStream *avist = s->streams[i]->priv_data; - for (j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++) - av_freep(&avist->indexes.cluster[j]); - av_freep(&avist->indexes.cluster); - avist->indexes.ents_allocated = avist->indexes.entry = 0; if (pb->seekable & AVIO_SEEKABLE_NORMAL) { avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET); avio_wl32(pb, avist->max_size); @@ -975,6 +975,19 @@ static int avi_write_trailer(AVFormatContext *s) return res; } +static void avi_deinit(AVFormatContext *s) +{ + for (int i = 0; i < s->nb_streams; i++) { + AVIStream *avist = s->streams[i]->priv_data; + if (!avist) + continue; + for (int j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++) + av_freep(&avist->indexes.cluster[j]); + av_freep(&avist->indexes.cluster); + avist->indexes.ents_allocated = avist->indexes.entry = 0; + } +} + #define OFFSET(x) offsetof(AVIContext, x) #define ENC AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -999,6 +1012,7 @@ AVOutputFormat ff_avi_muxer = { .audio_codec = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_AC3, .video_codec = AV_CODEC_ID_MPEG4, .init = avi_init, + .deinit = avi_deinit, .write_header = avi_write_header, .write_packet = avi_write_packet, .write_trailer = avi_write_trailer,