diff mbox series

[FFmpeg-devel] support raw avi for raw PAL8 or Gray8 pixel data

Message ID tencent_149A51FDC715BD444A65614FC23D08A25807@qq.com
State New
Headers show
Series [FFmpeg-devel] support raw avi for raw PAL8 or Gray8 pixel data | expand

Checks

Context Check Description
andriy/commit_summary warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

rui.jiang Aug. 16, 2021, 4:07 a.m. UTC
add palette data in avi header when the input data is raw PAL8 or Gray8 pixel data and the output data is 8bit raw avi video;

Here is a sample:
the codec params like:
        st->codecpar->bits_per_raw_sample=8;
        st->codecpar->bits_per_coded_sample=8;
        st->codecpar->format = AV_PIX_FMT_GRAY8;//AV_PIX_FMT_PAL8;
the input data like:
        int width = 320;
        int height = 480;
        int BUFSIZE = width * height;
        uint8_t* buffer = new unsigned char[BUFSIZE];

---
 libavformat/riffenc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 43c8bf957a..bc654b3cd3 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -228,7 +228,8 @@  void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par,
     pal_avi = !for_asf &&
               (pix_fmt == AV_PIX_FMT_PAL8 ||
                pix_fmt == AV_PIX_FMT_MONOWHITE ||
-               pix_fmt == AV_PIX_FMT_MONOBLACK);
+               pix_fmt == AV_PIX_FMT_MONOBLACK ||
+               pix_fmt == AV_PIX_FMT_GRAY8);
 
     /* Size (not including the size of the color table or color masks) */
     avio_wl32(pb, 40 + (ignore_extradata || pal_avi ? 0 : extradata_size));
@@ -263,6 +264,13 @@  void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par,
                     avio_wl32(pb, 0xffffff);
                 else if (i == 1 && pix_fmt == AV_PIX_FMT_MONOBLACK)
                     avio_wl32(pb, 0xffffff);
+                else if (pix_fmt == AV_PIX_FMT_PAL8 || pix_fmt == AV_PIX_FMT_GRAY8) {
+                    /* Initialize palette */
+                    avio_w8(pb,i);
+                    avio_w8(pb,i);
+                    avio_w8(pb,i);
+                    avio_w8(pb,0);
+                }
                 else
                     avio_wl32(pb, 0);
             }