From the Microsoft documentation for BITMAPINFOHEADER at
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318229%28v=vs.85%29.aspx:

"biSize: Specifies the number of bytes required by the structure. This value does not include the size of the color table or the size of the color masks, if they are appended to the end of structure."

So, biSize is always 40. Also, Windows Media Player won't detect video encoded with Microsoft Video 1 in 8 bpp mode if this value is anything else than 40. I don't know about other codecs, they probably work. Anyway, we should stick with the specs, and not include the palette size in that field.

Regarding the biClrUsed field, I'm setting it to 1 << bits_per_coded_sample if palettized video, since setting it to 0 is another case where it won't work with Windows Media Player and Microsoft Video 1 in 8 bpp mode.

Mats


--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From c9b1a89ddc16a7c65feaa56ca6ecb8d8ff7a9dbc Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Wed, 9 Mar 2016 23:20:09 +0100
Subject: [PATCH 2/3] lavf/riffenc: Improve spec compliance

---
 libavformat/riffenc.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 195a58e..3edb8d6 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -222,8 +222,8 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
     if (!enc->extradata_size && pal_avi)
         extradata_size = 4 * (1 << enc->bits_per_coded_sample);
 
-    /* size */
-    avio_wl32(pb, 40 + (ignore_extradata ? 0 :extradata_size));
+    /* size (not including the size of the color table or color masks */
+    avio_wl32(pb, 40);
     avio_wl32(pb, enc->width);
     //We always store RGB TopDown
     avio_wl32(pb, enc->codec_tag || keep_height ? enc->height : -enc->height);
@@ -236,7 +236,8 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc,
     avio_wl32(pb, (enc->width * enc->height * (enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24)+7) / 8);
     avio_wl32(pb, 0);
     avio_wl32(pb, 0);
-    avio_wl32(pb, 0);
+    /* number of color indices in the color table that are used */
+    avio_wl32(pb, pal_avi ? 1 << enc->bits_per_coded_sample : 0);
     avio_wl32(pb, 0);
 
     if (!ignore_extradata) {
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to