[FFmpeg-devel] [PATCH 6/9] avformat/avisynth: add read_frameprop_primaries option

Stephen Hutchinson qyot27 at gmail.com
Mon Aug 29 03:02:41 EEST 2022


Signed-off-by: Stephen Hutchinson <qyot27 at gmail.com>
---
 libavformat/avisynth.c | 82 ++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 39 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 65d8448e89..945ce0e245 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -106,6 +106,7 @@ typedef struct AviSynthContext {
     int frameprops;
     int frameprop_field_order;
     int frameprop_range;
+    int frameprop_primaries;
     int frameprop_sar;
 
     /* Linked list pointers. */
@@ -566,45 +567,47 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
             }
 
             /* Color Primaries */
-            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Primaries", 0, &error)) {
-            case 1:
-                st->codecpar->color_primaries = AVCOL_PRI_BT709;
-                break;
-            case 2:
-                st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
-                break;
-            case 4:
-                st->codecpar->color_primaries = AVCOL_PRI_BT470M;
-                break;
-            case 5:
-                st->codecpar->color_primaries = AVCOL_PRI_BT470BG;
-                break;
-            case 6:
-                st->codecpar->color_primaries = AVCOL_PRI_SMPTE170M;
-                break;
-            case 7:
-                st->codecpar->color_primaries = AVCOL_PRI_SMPTE240M;
-                break;
-            case 8:
-                st->codecpar->color_primaries = AVCOL_PRI_FILM;
-                break;
-            case 9:
-                st->codecpar->color_primaries = AVCOL_PRI_BT2020;
-                break;
-            case 10:
-                st->codecpar->color_primaries = AVCOL_PRI_SMPTE428;
-                break;
-            case 11:
-                st->codecpar->color_primaries = AVCOL_PRI_SMPTE431;
-                break;
-            case 12:
-                st->codecpar->color_primaries = AVCOL_PRI_SMPTE432;
-                break;
-            case 22:
-                st->codecpar->color_primaries = AVCOL_PRI_EBU3213;
-                break;
-            default:
-                st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
+            if(avs->frameprop_primaries) {
+                switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Primaries", 0, &error)) {
+                case 1:
+                    st->codecpar->color_primaries = AVCOL_PRI_BT709;
+                    break;
+                case 2:
+                    st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
+                    break;
+                case 4:
+                    st->codecpar->color_primaries = AVCOL_PRI_BT470M;
+                    break;
+                case 5:
+                    st->codecpar->color_primaries = AVCOL_PRI_BT470BG;
+                    break;
+                case 6:
+                    st->codecpar->color_primaries = AVCOL_PRI_SMPTE170M;
+                    break;
+                case 7:
+                    st->codecpar->color_primaries = AVCOL_PRI_SMPTE240M;
+                    break;
+                case 8:
+                    st->codecpar->color_primaries = AVCOL_PRI_FILM;
+                    break;
+                case 9:
+                    st->codecpar->color_primaries = AVCOL_PRI_BT2020;
+                    break;
+                case 10:
+                    st->codecpar->color_primaries = AVCOL_PRI_SMPTE428;
+                    break;
+                case 11:
+                    st->codecpar->color_primaries = AVCOL_PRI_SMPTE431;
+                    break;
+                case 12:
+                    st->codecpar->color_primaries = AVCOL_PRI_SMPTE432;
+                    break;
+                case 22:
+                    st->codecpar->color_primaries = AVCOL_PRI_EBU3213;
+                    break;
+                default:
+                    st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
+                }
             }
 
             /* Color Transfer Characteristics */
@@ -1160,6 +1163,7 @@ static const AVOption avisynth_options[] = {
     { "read_frameprops", "Read frame properties from script (AviSynth+ v3.7.1+).", OFFSET(frameprops), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { "read_frameprop_field_order", "Read field order from script's frame properties (AviSynth+ v3.7.1+).", OFFSET(frameprop_field_order), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { "read_frameprop_range", "Read color range from script's frame properties (AviSynth+ v3.7.1+).", OFFSET(frameprop_range), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
+    { "read_frameprop_primaries", "Read color primaries from script's frame properties (AviSynth+ v3.7.1+).", OFFSET(frameprop_primaries), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { "read_frameprop_sar", "Read SAR from script's frame properties (AviSynth+ v3.7.1+).", OFFSET(frameprop_sar), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
-- 
2.34.1



More information about the ffmpeg-devel mailing list