[FFmpeg-devel] [RFC] cinedec: report white balance gain coefficients using metadata

Peter Ross pross at xvid.org
Sun Nov 9 02:05:41 CET 2014


For cehoyos:

The PhantomCINE file format stores unprocessed sensor data from the 
camera CFA, and reports image processing coefficients in the file header.
To make meaningful use of this file format with FFmpeg, additional filtering
is required.

R/B gain:

  -vf 'lutrgb=r=WBRGAIN*val:b=WBBGAIN_*val'
  (replace WBxGAIN with value reported by cinedec)

_or_ for automatic adjustment

  -vf 'histeq'

There is still a need to compensate for gamma, but I do not know how to
convert the gamma value reported in the cinedec file to lutyuv/eq2 value.
(Also, the gain and gamma is intended to be applied in bayer colorspace.
 FFmpeg does have any bayer colorspace filters yet so they are applied post
 RGB conversion.)

[You may reuse the above text in FFmpeg wiki/documentation if neccessary.]

---
 libavformat/cinedec.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c
index 5776708..632f46c 100644
--- a/libavformat/cinedec.c
+++ b/libavformat/cinedec.c
@@ -27,6 +27,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/bmp.h"
+#include "libavutil/intfloat.h"
 #include "avformat.h"
 #include "internal.h"
 
@@ -78,6 +79,16 @@ static int set_metadata_int(AVDictionary **dict, const char *key, int value, int
     return 0;
 }
 
+static int set_metadata_float(AVDictionary **dict, const char *key, float value, int allow_zero)
+{
+    if (value != 0 || allow_zero) {
+        char tmp[64];
+        snprintf(tmp, sizeof(tmp), "%f", value);
+        return av_dict_set(dict, key, tmp, 0);
+    }
+    return 0;
+}
+
 static int cine_read_header(AVFormatContext *avctx)
 {
     AVIOContext *pb = avctx->pb;
@@ -177,7 +188,10 @@ static int cine_read_header(AVFormatContext *avctx)
     set_metadata_int(&st->metadata, "contrast", avio_rl32(pb), 1);
     set_metadata_int(&st->metadata, "gamma", avio_rl32(pb), 1);
 
-    avio_skip(pb, 72); // Reserved1 .. WBView
+    avio_skip(pb, 12 + 16); // Reserved1 .. AutoExpRect
+    set_metadata_float(&st->metadata, "wbgain[0].r", av_int2float(avio_rl32(pb)), 1);
+    set_metadata_float(&st->metadata, "wbgain[0].b", av_int2float(avio_rl32(pb)), 1);
+    avio_skip(pb, 36); // WBGain[1].. WBView
 
     st->codec->bits_per_coded_sample = avio_rl32(pb);
 
-- 
2.1.0

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141109/b37e380e/attachment.asc>


More information about the ffmpeg-devel mailing list