[vlc-commits] avcodec: make the video_format_t color to AVCodecContext conversion more generic

Steve Lhomme git at videolan.org
Thu Sep 7 12:13:54 CEST 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Tue Sep  5 13:37:25 2017 +0200| [c491eec988409cf4eac7f35adf2e17152ec8df5b] | committer: Jean-Baptiste Kempf

avcodec: make the video_format_t color to AVCodecContext conversion more generic

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c491eec988409cf4eac7f35adf2e17152ec8df5b
---

 modules/codec/avcodec/avcommon.h | 72 +++++++++++++++++++++++++++++++++++++++
 modules/codec/avcodec/encoder.c  | 73 +---------------------------------------
 2 files changed, 73 insertions(+), 72 deletions(-)

diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index 5b8deb19aa..4c917703c2 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -31,6 +31,7 @@
 #include <vlc_avcodec.h>
 #include <vlc_configuration.h>
 #include <vlc_variables.h>
+#include <vlc_es.h>
 
 #include <limits.h>
 
@@ -120,4 +121,75 @@ static inline vlc_rational_t FromAVRational(const AVRational rat)
     return (vlc_rational_t){.num = rat.num, .den = rat.den};
 }
 
+static inline void set_video_color_settings( const video_format_t *p_fmt, AVCodecContext *p_context )
+{
+    if( p_fmt->b_color_range_full )
+        p_context->color_range = AVCOL_RANGE_JPEG;
+
+    switch( p_fmt->space )
+    {
+        case COLOR_SPACE_BT709:
+            p_context->colorspace = AVCOL_SPC_BT709;
+            break;
+        case COLOR_SPACE_BT601:
+            p_context->colorspace = AVCOL_SPC_BT470BG;
+            break;
+        case COLOR_SPACE_BT2020:
+            p_context->colorspace = AVCOL_SPC_BT2020_CL;
+            break;
+        default:
+            p_context->colorspace = AVCOL_SPC_UNSPECIFIED;
+            break;
+    }
+
+    switch( p_fmt->transfer )
+    {
+        case TRANSFER_FUNC_LINEAR:
+            p_context->color_trc = AVCOL_TRC_LINEAR;
+            break;
+        case TRANSFER_FUNC_SRGB:
+            p_context->color_trc = AVCOL_TRC_GAMMA22;
+            break;
+        case TRANSFER_FUNC_BT470_BG:
+            p_context->color_trc = AVCOL_TRC_GAMMA28;
+            break;
+        case TRANSFER_FUNC_BT470_M:
+            p_context->color_trc = AVCOL_TRC_GAMMA22;
+            break;
+        case TRANSFER_FUNC_BT709:
+            p_context->color_trc = AVCOL_TRC_BT709;
+            break;
+        case TRANSFER_FUNC_SMPTE_ST2084:
+            p_context->color_trc = AVCOL_TRC_SMPTEST2084;
+            break;
+        case TRANSFER_FUNC_SMPTE_240:
+            p_context->color_trc = AVCOL_TRC_SMPTE240M;
+            break;
+        default:
+            p_context->color_trc = AVCOL_TRC_UNSPECIFIED;
+            break;
+    }
+    switch( p_fmt->primaries )
+    {
+        case COLOR_PRIMARIES_BT601_525:
+            p_context->color_primaries = AVCOL_PRI_SMPTE170M;
+            break;
+        case COLOR_PRIMARIES_BT601_625:
+            p_context->color_primaries = AVCOL_PRI_BT470BG;
+            break;
+        case COLOR_PRIMARIES_BT709:
+            p_context->color_primaries = AVCOL_PRI_BT709;
+            break;
+        case COLOR_PRIMARIES_BT2020:
+            p_context->color_primaries = AVCOL_PRI_BT2020;
+            break;
+        case COLOR_PRIMARIES_FCC1953:
+            p_context->color_primaries = AVCOL_PRI_BT470M;
+            break;
+        default:
+            p_context->color_primaries = AVCOL_PRI_UNSPECIFIED;
+            break;
+    }
+}
+
 #endif
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 7b5e15a245..5e8e4f9425 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -277,77 +277,6 @@ static void probe_video_frame_rate( encoder_t *p_enc, AVCodecContext *p_context,
     msg_Dbg( p_enc, "Time base set to %d/%d", p_context->time_base.num, p_context->time_base.den );
 }
 
-static void set_video_color_settings( encoder_t *p_enc, AVCodecContext *p_context )
-{
-    if( p_enc->fmt_in.video.b_color_range_full )
-        p_context->color_range = AVCOL_RANGE_JPEG;
-
-    switch( p_enc->fmt_in.video.space )
-    {
-        case COLOR_SPACE_BT709:
-            p_context->colorspace = AVCOL_SPC_BT709;
-            break;
-        case COLOR_SPACE_BT601:
-            p_context->colorspace = AVCOL_SPC_BT470BG;
-            break;
-        case COLOR_SPACE_BT2020:
-            p_context->colorspace = AVCOL_SPC_BT2020_CL;
-            break;
-        default:
-            p_context->colorspace = AVCOL_SPC_UNSPECIFIED;
-            break;
-    }
-
-    switch( p_enc->fmt_in.video.transfer )
-    {
-        case TRANSFER_FUNC_LINEAR:
-            p_context->color_trc = AVCOL_TRC_LINEAR;
-            break;
-        case TRANSFER_FUNC_SRGB:
-            p_context->color_trc = AVCOL_TRC_GAMMA22;
-            break;
-        case TRANSFER_FUNC_BT470_BG:
-            p_context->color_trc = AVCOL_TRC_GAMMA28;
-            break;
-        case TRANSFER_FUNC_BT470_M:
-            p_context->color_trc = AVCOL_TRC_GAMMA22;
-            break;
-        case TRANSFER_FUNC_BT709:
-            p_context->color_trc = AVCOL_TRC_BT709;
-            break;
-        case TRANSFER_FUNC_SMPTE_ST2084:
-            p_context->color_trc = AVCOL_TRC_SMPTEST2084;
-            break;
-        case TRANSFER_FUNC_SMPTE_240:
-            p_context->color_trc = AVCOL_TRC_SMPTE240M;
-            break;
-        default:
-            p_context->color_trc = AVCOL_TRC_UNSPECIFIED;
-            break;
-    }
-    switch( p_enc->fmt_in.video.primaries )
-    {
-        case COLOR_PRIMARIES_BT601_525:
-            p_context->color_primaries = AVCOL_PRI_SMPTE170M;
-            break;
-        case COLOR_PRIMARIES_BT601_625:
-            p_context->color_primaries = AVCOL_PRI_BT470BG;
-            break;
-        case COLOR_PRIMARIES_BT709:
-            p_context->color_primaries = AVCOL_PRI_BT709;
-            break;
-        case COLOR_PRIMARIES_BT2020:
-            p_context->color_primaries = AVCOL_PRI_BT2020;
-            break;
-        case COLOR_PRIMARIES_FCC1953:
-            p_context->color_primaries = AVCOL_PRI_BT470M;
-            break;
-        default:
-            p_context->color_primaries = AVCOL_PRI_UNSPECIFIED;
-            break;
-    }
-}
-
 static void add_av_option_int( encoder_t *p_enc, AVDictionary** pp_dict, const char* psz_name, int i_value )
 {
     char buff[32];
@@ -581,7 +510,7 @@ int OpenEncoder( vlc_object_t *p_this )
         p_context->height = p_enc->fmt_in.video.i_visible_height;
 
         probe_video_frame_rate( p_enc, p_context, p_codec );
-        set_video_color_settings( p_enc, p_context );
+        set_video_color_settings( &p_enc->fmt_in.video, p_context );
 
         /* Defaults from ffmpeg.c */
         p_context->qblur = 0.5;



More information about the vlc-commits mailing list