Please find here enclosed the patch synthesizing all your comments.

Nicolas DEROUINEAU
Research Engineer
VITEC

T.  +33 1 46 73 06 06
E.  nicolas.derouin...@vitec.com
W. www.vitec.com

________________________________________
De : ffmpeg-devel-boun...@ffmpeg.org <ffmpeg-devel-boun...@ffmpeg.org> de la 
part de Carl Eugen Hoyos <ceho...@ag.or.at>
Envoyé : mardi 30 juin 2015 12:47
À : FFmpeg development discussions and patches
Objet : Re: [FFmpeg-devel] Patch to parse H264 SEI Green Metadata

On Tuesday 30 June 2015 12:30:50 pm Nicolas Derouineau wrote:
> >> @@ -2610,6 +2610,7 @@ typedef struct AVCodecContext {
> >>  #define FF_DEBUG_ER          0x00000400
> >>  #define FF_DEBUG_MMCO        0x00000800
> >>  #define FF_DEBUG_BUGS        0x00001000
> >> +#define FF_DEBUG_GREEN_MD    0x00001200
> >
> >I believe this has to come at the end of the list with value 0x20000.
>
> Michael Niedermayer has sugested 0x00800000. I'm however going to use the
> one you suggest (as it is the last comment). Corrected.

Please use what Michael suggested, sorry that I had missed it.

> >Your av_logs could use a linebreak after the string.
>
> I'm not sure I understand correctly this last comment. I have unified the
> number of space in the strings.

av_log(context, "a string with %d %d %d \n", some variables);
vs.
av_log(context, "string",
       variables);

(This of course only makes sense for long lines!)

Carl Eugen
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
From 438a83b4cb86dd1045dca1d566f19148543e46ae Mon Sep 17 00:00:00 2001
From: Nicolas DEROUINEAU <nicolas.derouin...@vitec.com>
Date: Tue, 30 Jun 2015 15:17:59 +0200
Subject: [PATCH] Enabling Greenmetadata SEI parsing

---
 doc/codecs.texi            |    3 ++
 libavcodec/avcodec.h       |    1 +
 libavcodec/h264.h          |   21 ++++++++++++++
 libavcodec/h264_sei.c      |   65 ++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/options_table.h |    1 +
 5 files changed, 91 insertions(+)

diff --git a/doc/codecs.texi b/doc/codecs.texi
index 3c035a5..a2aa503 100644
--- a/doc/codecs.texi
+++ b/doc/codecs.texi
@@ -475,6 +475,9 @@ per-block quantization parameter (QP)
 motion vector
 @item dct_coeff
 
+@item green_metadata
+display complexity metadata for the upcoming frame, GoP or for a given duration.
+
 @item skip
 
 @item startcode
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ddbf0a3..6391cf3 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2616,6 +2616,7 @@ typedef struct AVCodecContext {
 #endif
 #define FF_DEBUG_BUFFERS     0x00008000
 #define FF_DEBUG_THREADS     0x00010000
+#define FF_DEBUG_GREEN_MD    0x00800000
 #define FF_DEBUG_NOMC        0x01000000
 
 #if FF_API_DEBUG_MV
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 15b9a5d..c298008 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -137,6 +137,7 @@ typedef enum {
     SEI_TYPE_RECOVERY_POINT         = 6,   ///< recovery point (frame # to decoder sync)
     SEI_TYPE_FRAME_PACKING          = 45,  ///< frame packing arrangement
     SEI_TYPE_DISPLAY_ORIENTATION    = 47,  ///< display orientation
+    SEI_TYPE_GREEN_METADATA         = 56   ///< GreenMPEG information
 } SEI_Type;
 
 /**
@@ -268,6 +269,22 @@ typedef struct FPA {
 } FPA;
 
 /**
+ *     Green MetaData Information Type
+ */
+typedef struct GreenMetaData {
+    uint8_t  green_metadata_type;
+    uint8_t  period_type;
+    uint16_t  num_seconds;
+    uint16_t  num_pictures;
+    uint8_t percent_non_zero_macroblocks;
+    uint8_t percent_intra_coded_macroblocks;
+    uint8_t percent_six_tap_filtering;
+    uint8_t percent_alpha_point_deblocking_instance;
+    uint8_t xsd_metric_type;
+    uint16_t xsd_metric_value;
+} GreenMetaData;
+
+/**
  * Memory management control operation opcode.
  */
 typedef enum MMCOOpcode {
@@ -814,6 +831,10 @@ typedef struct H264Context {
     /* Motion Estimation */
     qpel_mc_func (*qpel_put)[16];
     qpel_mc_func (*qpel_avg)[16];
+
+    /*Green Metadata */
+    GreenMetaData sei_green_metadata;
+
 } H264Context;
 
 extern const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-14).
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index b6ec5c7..9ade524 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -285,6 +285,66 @@ static int decode_display_orientation(H264Context *h)
     return 0;
 }
 
+static int decode_GreenMetadata(H264Context *h)
+{
+    if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+        av_log(h->avctx, AV_LOG_DEBUG,          "Green Metadata Info SEI message\n");
+
+    h->sei_green_metadata.green_metadata_type=get_bits(&h->gb, 8);
+
+    if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+        av_log(h->avctx, AV_LOG_DEBUG,          "green_metadata_type                            = %d\n",
+               h->sei_green_metadata.green_metadata_type);
+
+    if (h->sei_green_metadata.green_metadata_type==0){
+        h->sei_green_metadata.period_type=get_bits(&h->gb, 8);
+
+        if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+            av_log(h->avctx, AV_LOG_DEBUG,      "green_metadata_period_type                     = %d\n",
+                   h->sei_green_metadata.period_type);
+
+        if (h->sei_green_metadata.green_metadata_type==2){
+            h->sei_green_metadata.num_seconds = get_bits(&h->gb, 16);
+            if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+                av_log(h->avctx, AV_LOG_DEBUG,  "green_metadata_num_seconds                     = %d\n",
+                       h->sei_green_metadata.num_seconds);
+        }
+        else if (h->sei_green_metadata.period_type==3){
+            h->sei_green_metadata.num_pictures = get_bits(&h->gb, 16);
+            if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+                av_log(h->avctx, AV_LOG_DEBUG,  "green_metadata_num_pictures                    = %d\n",
+                       h->sei_green_metadata.num_pictures);
+        }
+
+        h->sei_green_metadata.percent_non_zero_macroblocks=get_bits(&h->gb, 8);
+        h->sei_green_metadata.percent_intra_coded_macroblocks=get_bits(&h->gb, 8);
+        h->sei_green_metadata.percent_six_tap_filtering=get_bits(&h->gb, 8);
+        h->sei_green_metadata.percent_alpha_point_deblocking_instance=get_bits(&h->gb, 8);
+
+        if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+            av_log(h->avctx, AV_LOG_DEBUG,      "SEI GREEN Complexity Metrics                   = %f %f %f %f\n",
+                                           (float)h->sei_green_metadata.percent_non_zero_macroblocks/255,
+                                           (float)h->sei_green_metadata.percent_intra_coded_macroblocks/255,
+                                           (float)h->sei_green_metadata.percent_six_tap_filtering/255,
+                                           (float)h->sei_green_metadata.percent_alpha_point_deblocking_instance/255);
+
+    }else if( h->sei_green_metadata.green_metadata_type==1){
+        h->sei_green_metadata.xsd_metric_type=get_bits(&h->gb, 8);
+        h->sei_green_metadata.xsd_metric_value=get_bits(&h->gb, 16);
+
+        if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+            av_log(h->avctx, AV_LOG_DEBUG,      "xsd_metric_type                                = %d\n",
+                   h->sei_green_metadata.xsd_metric_type);
+        if ( h->sei_green_metadata.xsd_metric_type==0){
+            if (h->avctx->debug & FF_DEBUG_GREEN_MD)
+                av_log(h->avctx, AV_LOG_DEBUG,  "xsd_metric_value                               = %f\n",
+                       (float)h->sei_green_metadata.xsd_metric_value/100);
+        }
+    }
+
+    return 0;
+}
+
 int ff_h264_decode_sei(H264Context *h)
 {
     while (get_bits_left(&h->gb) > 16 && show_bits(&h->gb, 16)) {
@@ -350,6 +410,11 @@ int ff_h264_decode_sei(H264Context *h)
             if (ret < 0)
                 return ret;
             break;
+        case SEI_TYPE_GREEN_METADATA:
+            ret = decode_GreenMetadata(h);
+            if (ret < 0)
+                return ret;
+            break;
         default:
             av_log(h->avctx, AV_LOG_DEBUG, "unknown SEI type %d\n", type);
         }
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index a906864..76ae81f 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -253,6 +253,7 @@ static const AVOption avcodec_options[] = {
 {"mv", "motion vector", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_MV }, INT_MIN, INT_MAX, V|D, "debug"},
 #endif
 {"dct_coeff", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_DCT_COEFF }, INT_MIN, INT_MAX, V|D, "debug"},
+{"green_metadata", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_GREEN_MD }, INT_MIN, INT_MAX, V|D, "debug"},
 {"skip", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_SKIP }, INT_MIN, INT_MAX, V|D, "debug"},
 {"startcode", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_STARTCODE }, INT_MIN, INT_MAX, V|D, "debug"},
 #if FF_API_UNUSED_MEMBERS
-- 
1.7.9.5

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

Reply via email to