From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/3] avisynth: use AviSynth+'s frame properties to set various fields
Date: Sat, 19 Feb 2022 21:39:27 +0100
Message-ID: <AM7PR03MB6660296693697EB1588EBEEE8F389@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <20220208110240.4179-3-qyot27@gmail.com>
Stephen Hutchinson:
> * Field Order
> * Chroma Location
> * Color Transfer Characteristics
> * Color Range
> * Color Primaries
> * Matrix Coefficients
>
> The existing TFF/BFF detection is retained as a fallback for
> older versions of AviSynth that can't access frame properties.
> The other properties have no legacy equivalent to detect them.
>
> Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
> ---
> libavformat/avisynth.c | 263 +++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 250 insertions(+), 13 deletions(-)
>
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index 1e862a6a85..8bc39869a3 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -19,6 +19,8 @@
> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> */
>
> +#include <stdbool.h>
> +
> #include "libavutil/attributes.h"
> #include "libavutil/internal.h"
>
> @@ -76,6 +78,9 @@ typedef struct AviSynthLibrary {
> AVSC_DECLARE_FUNC(avs_get_row_size_p);
> AVSC_DECLARE_FUNC(avs_is_planar_rgb);
> 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_get_env_property);
> #undef AVSC_DECLARE_FUNC
> } AviSynthLibrary;
>
> @@ -153,6 +158,9 @@ static av_cold int avisynth_load_library(void)
> LOAD_AVS_FUNC(avs_get_row_size_p, 1);
> LOAD_AVS_FUNC(avs_is_planar_rgb, 1);
> 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_get_env_property, 1);
> #undef LOAD_AVS_FUNC
>
> atexit(avisynth_atexit_handler);
> @@ -236,6 +244,10 @@ static av_cold void avisynth_atexit_handler(void)
> static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> {
> AviSynthContext *avs = s->priv_data;
> + const AVS_Map *avsmap;
> + AVS_VideoFrame *frame;
> + int framedata, error;
> + bool frameprop;
> int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: Planar RGBA
>
> st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> @@ -251,19 +263,6 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> avpriv_set_pts_info(st, 32, avs->vi->fps_denominator, avs->vi->fps_numerator);
>
>
> - st->codecpar->field_order = AV_FIELD_UNKNOWN;
> - /* AviSynth works with frame-based video, detecting field order can
> - * only work when avs_is_field_based returns 'false'. */
> - av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", avs_is_field_based(avs->vi));
> - if (avs_is_field_based(avs->vi) == 0) {
> - if (avs_is_tff(avs->vi)) {
> - st->codecpar->field_order = AV_FIELD_TT;
> - }
> - else if (avs_is_bff(avs->vi)) {
> - st->codecpar->field_order = AV_FIELD_BB;
> - }
> - }
> -
> switch (avs->vi->pixel_type) {
> /* 10~16-bit YUV pix_fmts (AviSynth+) */
> case AVS_CS_YUV444P10:
> @@ -499,6 +498,244 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> avs->n_planes = 1;
> avs->planes = avs_planes_packed;
> }
> +
> + /* Read AviSynth+'s frame properties to set additional info.
> + *
> + * Due to a bug preventing the C interface from accessing frame
> + * properties in earlier versions of interface version 8, only
> + * enable this if we detect version 8.1 at the minimum. */
> +
> + if (!avs_library.avs_get_env_property) {
> + av_log(s, AV_LOG_TRACE, "%s\n",
> + "avs_get_env_property does not exist in AviSynth library; frame properties won't be checked.");
> + frameprop = false;
> + } else {
> + if (avs_library.avs_get_env_property(avs->env, AVS_AEP_INTERFACE_BUGFIX)) {
> + av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.1 or higher, reading frame properties.");
> + frameprop = true;
> + } else {
> + av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.0, need 8.1+ to read frame properties.");
> + frameprop = false;
> + }
> + }
> +
> + if (frameprop = true) {
> +
> + frame = avs_library.avs_get_frame(avs->clip, framedata);
framedata is completely uninitialized here. I presume it should be zero
(for the first frame)? (This is Coverity issue 1500290.)
> + avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);
> +
> + /* Field order */
> + 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 */
> + 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 */
> + 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 */
> + 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;
> + }
> + } else {
> + st->codecpar->field_order = AV_FIELD_UNKNOWN;
> + /* AviSynth works with frame-based video, detecting field order can
> + * only work when avs_is_field_based returns 'false'. */
> + av_log(s, AV_LOG_TRACE, "avs_is_field_based: %d\n", avs_is_field_based(avs->vi));
> + if (avs_is_field_based(avs->vi) == 0) {
> + if (avs_is_tff(avs->vi)) {
> + st->codecpar->field_order = AV_FIELD_TT;
> + }
> + else if (avs_is_bff(avs->vi)) {
> + st->codecpar->field_order = AV_FIELD_BB;
> + }
> + }
> + }
> +
> return 0;
> }
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-19 20:39 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 11:02 [FFmpeg-devel] [PATCH 0/3] avformat/avisynth: support frame properties Stephen Hutchinson
2022-02-08 11:02 ` [FFmpeg-devel] [PATCH 1/3] avisynth: corrected interlace detection Stephen Hutchinson
2022-02-13 23:33 ` Stephen Hutchinson
2022-02-08 11:02 ` [FFmpeg-devel] [PATCH 2/3] avisynth: use AviSynth+'s frame properties to set various fields Stephen Hutchinson
2022-02-13 23:34 ` Stephen Hutchinson
2022-02-19 20:39 ` Andreas Rheinhardt [this message]
2022-02-19 21:41 ` [FFmpeg-devel] [PATCH 1/2] avformat/avisynth: remove unused variable 'frameprop' Stephen Hutchinson
2022-02-19 21:41 ` [FFmpeg-devel] [PATCH 2/2] avformat/avisynth: make sure framedata variable is initialized Stephen Hutchinson
2022-02-19 22:45 ` Andreas Rheinhardt
2022-02-20 0:05 ` Stephen Hutchinson
2022-02-20 0:09 ` [FFmpeg-devel] [PATCH] avformat/avisynth: remove framedata variable Stephen Hutchinson
2022-02-23 18:04 ` Stephen Hutchinson
2022-02-23 18:03 ` [FFmpeg-devel] [PATCH 1/2] avformat/avisynth: remove unused variable 'frameprop' Stephen Hutchinson
2022-02-19 21:45 ` [FFmpeg-devel] [PATCH 2/3] avisynth: use AviSynth+'s frame properties to set various fields Stephen Hutchinson
2022-08-24 17:04 ` Steinar Apalnes
2022-08-25 0:11 ` Stephen Hutchinson
2022-08-25 7:46 ` Steinar Apalnes
2022-09-04 19:14 ` Stephen Hutchinson
2022-02-08 11:02 ` [FFmpeg-devel] [PATCH 3/3] configure: check avisynth header version Stephen Hutchinson
2022-02-13 23:34 ` Stephen Hutchinson
2022-02-14 11:56 ` Gyan Doshi
2022-02-14 22:03 ` Stephen Hutchinson
2022-02-15 22:02 ` Helmut K. C. Tessarek
2022-02-15 23:55 ` Stephen Hutchinson
2022-02-16 1:33 ` Helmut K. C. Tessarek
2022-02-16 3:50 ` Stephen Hutchinson
2022-02-16 5:10 ` Helmut K. C. Tessarek
2022-02-16 7:37 ` Stephen Hutchinson
2022-02-16 18:25 ` Helmut K. C. Tessarek
2022-02-16 23:04 ` hydra3333
2022-02-16 23:13 ` Helmut K. C. Tessarek
2022-02-17 0:55 ` Stephen Hutchinson
2022-02-17 22:19 ` Helmut K. C. Tessarek
2022-02-18 0:21 ` Stephen Hutchinson
2022-02-13 17:48 ` [FFmpeg-devel] [PATCH 0/3] avformat/avisynth: support frame properties Stephen Hutchinson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM7PR03MB6660296693697EB1588EBEEE8F389@AM7PR03MB6660.eurprd03.prod.outlook.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git