[FFmpeg-devel] [PATCH 3/9] avformat/avisynth: add read_frameprops option

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


Allows turning the reading of frame properties entirely on and off.
Defaults to reading frame properties.

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

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index d503c7ed40..5d726d70a5 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -103,6 +103,7 @@ typedef struct AviSynthContext {
     int error;
 
     /* (de)activate reading frame properties */
+    int frameprops;
     int frameprop_sar;
 
     /* Linked list pointers. */
@@ -522,227 +523,228 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
         frame  = avs_library.avs_get_frame(avs->clip, 0);
         avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);
 
-        /* Field order */
-        if(avs_library.avs_prop_get_type(avs->env, avsmap, "_FieldBased") == AVS_PROPTYPE_UNSET) {
-            st->codecpar->field_order = AV_FIELD_UNKNOWN;
-        } else {
-            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_FieldBased", 0, &error)) {
-            case 0:
-                st->codecpar->field_order = AV_FIELD_PROGRESSIVE;
-                break;
-            case 1:
-                st->codecpar->field_order = AV_FIELD_BB;
-                break;
-            case 2:
-                st->codecpar->field_order = AV_FIELD_TT;
-                break;
-            default:
+        if(avs->frameprops) {
+            /* Field order */
+            if(avs_library.avs_prop_get_type(avs->env, avsmap, "_FieldBased") == AVS_PROPTYPE_UNSET) {
                 st->codecpar->field_order = AV_FIELD_UNKNOWN;
+            } else {
+                switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_FieldBased", 0, &error)) {
+                case 0:
+                    st->codecpar->field_order = AV_FIELD_PROGRESSIVE;
+                    break;
+                case 1:
+                    st->codecpar->field_order = AV_FIELD_BB;
+                    break;
+                case 2:
+                    st->codecpar->field_order = AV_FIELD_TT;
+                    break;
+                default:
+                    st->codecpar->field_order = AV_FIELD_UNKNOWN;
+                }
             }
-        }
 
-        /* Color Range */
-        if(avs_library.avs_prop_get_type(avs->env, avsmap, "_ColorRange") == AVS_PROPTYPE_UNSET) {
-            st->codecpar->color_range = AVCOL_RANGE_UNSPECIFIED;
-        } else {
-            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_ColorRange", 0, &error)) {
-            case 0:
-                st->codecpar->color_range = AVCOL_RANGE_JPEG;
-                break;
-            case 1:
-                st->codecpar->color_range = AVCOL_RANGE_MPEG;
-                break;
-            default:
+            /* Color Range */
+            if(avs_library.avs_prop_get_type(avs->env, avsmap, "_ColorRange") == AVS_PROPTYPE_UNSET) {
                 st->codecpar->color_range = AVCOL_RANGE_UNSPECIFIED;
+            } else {
+                switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_ColorRange", 0, &error)) {
+                case 0:
+                    st->codecpar->color_range = AVCOL_RANGE_JPEG;
+                    break;
+                case 1:
+                    st->codecpar->color_range = AVCOL_RANGE_MPEG;
+                    break;
+                default:
+                    st->codecpar->color_range = AVCOL_RANGE_UNSPECIFIED;
+                }
             }
-        }
 
-        /* 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;
-        }
-
-        /* Color Transfer Characteristics */
-        switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Transfer", 0, &error)) {
-        case 1:
-            st->codecpar->color_trc = AVCOL_TRC_BT709;
-            break;
-        case 2:
-            st->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED;
-            break;
-        case 4:
-            st->codecpar->color_trc = AVCOL_TRC_GAMMA22;
-            break;
-        case 5:
-            st->codecpar->color_trc = AVCOL_TRC_GAMMA28;
-            break;
-        case 6:
-            st->codecpar->color_trc = AVCOL_TRC_SMPTE170M;
-            break;
-        case 7:
-            st->codecpar->color_trc = AVCOL_TRC_SMPTE240M;
-            break;
-        case 8:
-            st->codecpar->color_trc = AVCOL_TRC_LINEAR;
-            break;
-        case 9:
-            st->codecpar->color_trc = AVCOL_TRC_LOG;
-            break;
-        case 10:
-            st->codecpar->color_trc = AVCOL_TRC_LOG_SQRT;
-            break;
-        case 11:
-            st->codecpar->color_trc = AVCOL_TRC_IEC61966_2_4;
-            break;
-        case 12:
-            st->codecpar->color_trc = AVCOL_TRC_BT1361_ECG;
-            break;
-        case 13:
-            st->codecpar->color_trc = AVCOL_TRC_IEC61966_2_1;
-            break;
-        case 14:
-            st->codecpar->color_trc = AVCOL_TRC_BT2020_10;
-            break;
-        case 15:
-            st->codecpar->color_trc = AVCOL_TRC_BT2020_12;
-            break;
-        case 16:
-            st->codecpar->color_trc = AVCOL_TRC_SMPTE2084;
-            break;
-        case 17:
-            st->codecpar->color_trc = AVCOL_TRC_SMPTE428;
-            break;
-        case 18:
-            st->codecpar->color_trc = AVCOL_TRC_ARIB_STD_B67;
-            break;
-        default:
-            st->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED;
-        }
-
-        /* Matrix coefficients */
-        if(avs_library.avs_prop_get_type(avs->env, avsmap, "_Matrix") == AVS_PROPTYPE_UNSET) {
-            st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
-        } else {
-            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Matrix", 0, &error)) {
-            case 0:
-                st->codecpar->color_space = AVCOL_SPC_RGB;
-                break;
+            /* Color Primaries */
+            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Primaries", 0, &error)) {
             case 1:
-                st->codecpar->color_space = AVCOL_SPC_BT709;
+                st->codecpar->color_primaries = AVCOL_PRI_BT709;
                 break;
             case 2:
-                st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
+                st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
                 break;
             case 4:
-                st->codecpar->color_space = AVCOL_SPC_FCC;
+                st->codecpar->color_primaries = AVCOL_PRI_BT470M;
                 break;
             case 5:
-                st->codecpar->color_space = AVCOL_SPC_BT470BG;
+                st->codecpar->color_primaries = AVCOL_PRI_BT470BG;
                 break;
             case 6:
-                st->codecpar->color_space = AVCOL_SPC_SMPTE170M;
+                st->codecpar->color_primaries = AVCOL_PRI_SMPTE170M;
                 break;
             case 7:
-                st->codecpar->color_space = AVCOL_SPC_SMPTE240M;
+                st->codecpar->color_primaries = AVCOL_PRI_SMPTE240M;
                 break;
             case 8:
-                st->codecpar->color_space = AVCOL_SPC_YCGCO;
+                st->codecpar->color_primaries = AVCOL_PRI_FILM;
                 break;
             case 9:
-                st->codecpar->color_space = AVCOL_SPC_BT2020_NCL;
+                st->codecpar->color_primaries = AVCOL_PRI_BT2020;
                 break;
             case 10:
-                st->codecpar->color_space = AVCOL_SPC_BT2020_CL;
+                st->codecpar->color_primaries = AVCOL_PRI_SMPTE428;
                 break;
             case 11:
-                st->codecpar->color_space = AVCOL_SPC_SMPTE2085;
+                st->codecpar->color_primaries = AVCOL_PRI_SMPTE431;
                 break;
             case 12:
-                st->codecpar->color_space = AVCOL_SPC_CHROMA_DERIVED_NCL;
+                st->codecpar->color_primaries = AVCOL_PRI_SMPTE432;
                 break;
-            case 13:
-                st->codecpar->color_space = AVCOL_SPC_CHROMA_DERIVED_CL;
-                break;
-            case 14:
-                st->codecpar->color_space = AVCOL_SPC_ICTCP;
+            case 22:
+                st->codecpar->color_primaries = AVCOL_PRI_EBU3213;
                 break;
             default:
-                st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
+                st->codecpar->color_primaries = AVCOL_PRI_UNSPECIFIED;
             }
-        }
 
-        /* Chroma Location */
-        if(avs_library.avs_prop_get_type(avs->env, avsmap, "_ChromaLocation") == AVS_PROPTYPE_UNSET) {
-            st->codecpar->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
-        } else {
-            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_ChromaLocation", 0, &error)) {
-            case 0:
-                st->codecpar->chroma_location = AVCHROMA_LOC_LEFT;
-                break;
+            /* Color Transfer Characteristics */
+            switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Transfer", 0, &error)) {
             case 1:
-                st->codecpar->chroma_location = AVCHROMA_LOC_CENTER;
+                st->codecpar->color_trc = AVCOL_TRC_BT709;
                 break;
             case 2:
-                st->codecpar->chroma_location = AVCHROMA_LOC_TOPLEFT;
-                break;
-            case 3:
-                st->codecpar->chroma_location = AVCHROMA_LOC_TOP;
+                st->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED;
                 break;
             case 4:
-                st->codecpar->chroma_location = AVCHROMA_LOC_BOTTOMLEFT;
+                st->codecpar->color_trc = AVCOL_TRC_GAMMA22;
                 break;
             case 5:
-                st->codecpar->chroma_location = AVCHROMA_LOC_BOTTOM;
+                st->codecpar->color_trc = AVCOL_TRC_GAMMA28;
+                break;
+            case 6:
+                st->codecpar->color_trc = AVCOL_TRC_SMPTE170M;
+                break;
+            case 7:
+                st->codecpar->color_trc = AVCOL_TRC_SMPTE240M;
+                break;
+            case 8:
+                st->codecpar->color_trc = AVCOL_TRC_LINEAR;
+                break;
+            case 9:
+                st->codecpar->color_trc = AVCOL_TRC_LOG;
+                break;
+            case 10:
+                st->codecpar->color_trc = AVCOL_TRC_LOG_SQRT;
+                break;
+            case 11:
+                st->codecpar->color_trc = AVCOL_TRC_IEC61966_2_4;
+                break;
+            case 12:
+                st->codecpar->color_trc = AVCOL_TRC_BT1361_ECG;
+                break;
+            case 13:
+                st->codecpar->color_trc = AVCOL_TRC_IEC61966_2_1;
+                break;
+            case 14:
+                st->codecpar->color_trc = AVCOL_TRC_BT2020_10;
+                break;
+            case 15:
+                st->codecpar->color_trc = AVCOL_TRC_BT2020_12;
+                break;
+            case 16:
+                st->codecpar->color_trc = AVCOL_TRC_SMPTE2084;
+                break;
+            case 17:
+                st->codecpar->color_trc = AVCOL_TRC_SMPTE428;
+                break;
+            case 18:
+                st->codecpar->color_trc = AVCOL_TRC_ARIB_STD_B67;
                 break;
             default:
+                st->codecpar->color_trc = AVCOL_TRC_UNSPECIFIED;
+            }
+
+            /* Matrix coefficients */
+            if(avs_library.avs_prop_get_type(avs->env, avsmap, "_Matrix") == AVS_PROPTYPE_UNSET) {
+                st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
+            } else {
+                switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Matrix", 0, &error)) {
+                case 0:
+                    st->codecpar->color_space = AVCOL_SPC_RGB;
+                    break;
+                case 1:
+                    st->codecpar->color_space = AVCOL_SPC_BT709;
+                    break;
+                case 2:
+                    st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
+                    break;
+                case 4:
+                    st->codecpar->color_space = AVCOL_SPC_FCC;
+                    break;
+                case 5:
+                    st->codecpar->color_space = AVCOL_SPC_BT470BG;
+                    break;
+                case 6:
+                    st->codecpar->color_space = AVCOL_SPC_SMPTE170M;
+                    break;
+                case 7:
+                    st->codecpar->color_space = AVCOL_SPC_SMPTE240M;
+                    break;
+                case 8:
+                    st->codecpar->color_space = AVCOL_SPC_YCGCO;
+                    break;
+                case 9:
+                    st->codecpar->color_space = AVCOL_SPC_BT2020_NCL;
+                    break;
+                case 10:
+                    st->codecpar->color_space = AVCOL_SPC_BT2020_CL;
+                    break;
+                case 11:
+                    st->codecpar->color_space = AVCOL_SPC_SMPTE2085;
+                    break;
+                case 12:
+                    st->codecpar->color_space = AVCOL_SPC_CHROMA_DERIVED_NCL;
+                    break;
+                case 13:
+                    st->codecpar->color_space = AVCOL_SPC_CHROMA_DERIVED_CL;
+                    break;
+                case 14:
+                    st->codecpar->color_space = AVCOL_SPC_ICTCP;
+                    break;
+                default:
+                    st->codecpar->color_space = AVCOL_SPC_UNSPECIFIED;
+                }
+            }
+
+            /* Chroma Location */
+            if(avs_library.avs_prop_get_type(avs->env, avsmap, "_ChromaLocation") == AVS_PROPTYPE_UNSET) {
                 st->codecpar->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
+            } else {
+                switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_ChromaLocation", 0, &error)) {
+                case 0:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_LEFT;
+                    break;
+                case 1:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_CENTER;
+                    break;
+                case 2:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_TOPLEFT;
+                    break;
+                case 3:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_TOP;
+                    break;
+                case 4:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_BOTTOMLEFT;
+                    break;
+                case 5:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_BOTTOM;
+                    break;
+                default:
+                    st->codecpar->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
+                }
             }
-        }
 
-        /* Sample aspect ratio */
-        if (avs->frameprop_sar) {
-            sar_num = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARNum", 0, &error);
-            sar_den = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARDen", 0, &error);
-            st->sample_aspect_ratio = (AVRational){ sar_num, sar_den };
+            /* Sample aspect ratio */
+            if (avs->frameprop_sar) {
+                sar_num = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARNum", 0, &error);
+                sar_den = avs_library.avs_prop_get_int(avs->env, avsmap, "_SARDen", 0, &error);
+                st->sample_aspect_ratio = (AVRational){ sar_num, sar_den };
+            }
         }
-
         avs_library.avs_release_video_frame(frame);
     } else {
         st->codecpar->field_order = AV_FIELD_UNKNOWN;
@@ -1149,6 +1151,7 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index,
 
 #define OFFSET(x) offsetof(AviSynthContext, x)
 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_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