How to debayer bmp image with FFMpeg? (.exe file)

Total
23
Shares

I have an bayer image .bmp I would like to debayer with FFMpeg, I thought that possibly FFMpeg knows to debayer it by default so I tried to use such a very simple query

ffmpeg -i input.bmp output.png

but output.png looks gray, so ffmpeg doesn’t apply debayer automatically. I tried to figure out if is it possible with ffmpeg, but there is almost nothing about it on google.

Image example (it is too large to upload it here): https://drive.google.com/file/d/1V8HwOuIo9PBX3ix0eKFQFGimskU_H0mN/view?usp=sharing

How to do it?

UPD

this is what I tried to do

ffmpeg -y -i D:BufferBayerTime0000000_img.bmp -pix_fmt gray D:BufferBayerbmptest11.y -hide_banner
ffmpeg -y -pixel_format bayer_rggb8 -video_size 4104x3006 -i D:BufferBayerbmptest11.y D:BufferBayerbmpresult1.png -hide_banner

and there is an error I get

Input #0, image2, from 'D:BufferBayerbmptest11.y':
  Duration: 00:00:00.04, start: 0.000000, bitrate: 1013196 kb/s
    Stream #0:0: Video: rawvideo ([186]RG[8] / 0x84752BA), bayer_rggb8, 4104x3006, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> png (native))
Press [q] to stop, [?] for help
[rawvideo @ 0000027da39d3f80] Invalid buffer size, packet size 5065984 < expected frame_size 12336624
Error while decoding stream #0:0: Invalid argument
Output #0, image2, to 'D:BufferBayerbmpresult1.png':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: png, rgb24, 4104x3006, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 png
frame=    0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Conversion failed!

if I change the resolution to 1920x1080 like this

ffmpeg -y -pixel_format bayer_rggb8 -video_size 1920x1080 -i D:BufferBayerbmptest11.y D:BufferBayerbmpresult1.png -hide_banner

I don’t get an error, but the output is wrong

enter image description here


Solution

It doesn’t look like FFmpeg has a Debayer filter.
The only documented option is selecting Bayer as input pixel format.

I found a solution executing FFmpeg twice:

  • Convert from BMP to raw Bayer:

     ffmpeg -y -i Time0000005_img.bmp -pix_fmt gray tmp.y
    
  • Convert from raw Bayer to RGB (Debayer):

     ffmpeg -y -pixel_format bayer_rggb8 -video_size 4104x3006 -i tmp.y rgb.png
    

Single line solution (using pipes):

ffmpeg -y -i Time0000005_img.bmp -vf format=gray -f rawvideo pipe: | ffmpeg -y -f rawvideo -pixel_format bayer_rggb8 -video_size 4104x3006 -i pipe: rgb.png

You may also try gamma correction:

ffmpeg -y -i Time0000005_img.bmp -vf format=gray -f rawvideo pipe: | ffmpeg -y -f rawvideo -pixel_format bayer_rggb8 -video_size 4104x3006 -i pipe: -vf eq=gamma=2.2 rgb.png

Note:
I manually sets video_size to 4104x3006.
Setting video_size automatically is possible using FFprobe, but it makes the solution more complicated.


Result (after gamma correction) resized by a factor of 1/10:
enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *