avformat/avisynth: fix fallbacks for four frameprops

If _FieldBased, _Matrix, _ColorRange, or _ChromaLocation haven't
been set, that absence would be interpreted as 0, leading to those
being set to case 0 instead of default. There is no case 0 for
_Primaries and _Transfer, so those were correctly falling back
to the default case.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
This commit is contained in:
Stephen Hutchinson 2022-02-26 19:25:40 -05:00
parent 4419433d77
commit e81242bb13

View File

@ -78,6 +78,7 @@ typedef struct AviSynthLibrary {
AVSC_DECLARE_FUNC(avs_is_planar_rgba);
AVSC_DECLARE_FUNC(avs_get_frame_props_ro);
AVSC_DECLARE_FUNC(avs_prop_get_int);
AVSC_DECLARE_FUNC(avs_prop_get_type);
AVSC_DECLARE_FUNC(avs_get_env_property);
#undef AVSC_DECLARE_FUNC
} AviSynthLibrary;
@ -158,6 +159,7 @@ static av_cold int avisynth_load_library(void)
LOAD_AVS_FUNC(avs_is_planar_rgba, 1);
LOAD_AVS_FUNC(avs_get_frame_props_ro, 1);
LOAD_AVS_FUNC(avs_prop_get_int, 1);
LOAD_AVS_FUNC(avs_prop_get_type, 1);
LOAD_AVS_FUNC(avs_get_env_property, 1);
#undef LOAD_AVS_FUNC
@ -511,6 +513,9 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
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;
@ -524,8 +529,12 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
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;
@ -536,6 +545,7 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
default:
st->codecpar->color_range = AVCOL_RANGE_UNSPECIFIED;
}
}
/* Color Primaries */
switch (avs_library.avs_prop_get_int(avs->env, avsmap, "_Primaries", 0, &error)) {
@ -637,6 +647,9 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
}
/* 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;
@ -683,8 +696,12 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
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;
@ -707,6 +724,7 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
default:
st->codecpar->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
}
}
} else {
st->codecpar->field_order = AV_FIELD_UNKNOWN;
/* AviSynth works with frame-based video, detecting field order can