]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/avienc.c
tests/api-band-test: simplify code
[ffmpeg] / libavformat / avienc.c
index 23cc58ea76ccc9ce4c78048f7072d8f7a4b6578c..9cbf3d33493ed0ee7b2e2ca9d8ca7eb30ae6e2f8 100644 (file)
@@ -72,6 +72,7 @@ typedef struct AVIContext {
     int reserve_index_space;
     int master_index_max_size;
     int write_channel_mask;
+    int flipped_raw_rgb;
 } AVIContext;
 
 typedef struct AVIStream {
@@ -268,8 +269,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);
     }
 
@@ -449,7 +450,7 @@ static int avi_write_header(AVFormatContext *s)
                     && par->bits_per_coded_sample == 15)
                     par->bits_per_coded_sample = 16;
                 avist->pal_offset = avio_tell(pb) + 40;
-                ff_put_bmp_header(pb, par, 0, 0);
+                ff_put_bmp_header(pb, par, 0, 0, avi->flipped_raw_rgb);
                 pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
                                               par->bits_per_coded_sample);
                 if (   !par->codec_tag
@@ -458,6 +459,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;
@@ -591,7 +600,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 */
@@ -986,6 +994,7 @@ static void avi_deinit(AVFormatContext *s)
 static const AVOption options[] = {
     { "reserve_index_space", "reserve space (in bytes) at the beginning of the file for each stream index", OFFSET(reserve_index_space), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, ENC },
     { "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
+    { "flipped_raw_rgb", "Raw RGB bitmaps are stored bottom-up", OFFSET(flipped_raw_rgb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
     { NULL },
 };
 
@@ -1009,8 +1018,6 @@ AVOutputFormat ff_avi_muxer = {
     .write_header   = avi_write_header,
     .write_packet   = avi_write_packet,
     .write_trailer  = avi_write_trailer,
-    .codec_tag      = (const AVCodecTag * const []) {
-        ff_codec_bmp_tags, ff_codec_wav_tags, 0
-    },
+    .codec_tag      = ff_riff_codec_tags_list,
     .priv_class     = &avi_muxer_class,
 };