[FFmpeg-devel] [PATCH 2/4] avisynth: switch to AviSynth+ on Linux
Stephen Hutchinson
qyot27 at gmail.com
Tue Mar 24 20:40:26 EET 2020
On 3/12/20 7:38 PM, Stephen Hutchinson wrote:
> AviSynth+ now supports non-Windows OSes, making AvxSynth
> obsolete. Since we no longer support AviSynth 2.5 (which is
> essentially what AvxSynth is), remove AvxSynth support and
> replace it with AviSynth+.
>
> As a result, the USING_AVISYNTH defines can be switched back
> to generic _WIN32.
> ---
> libavformat/avisynth.c | 56 +++++++++++-------------------------------
> 1 file changed, 15 insertions(+), 41 deletions(-)
>
> diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
> index 55a2efd884..43b65badc9 100644
> --- a/libavformat/avisynth.c
> +++ b/libavformat/avisynth.c
> @@ -1,5 +1,5 @@
> /*
> - * AviSynth/AvxSynth support
> + * AviSynth(+) support
> * Copyright (c) 2012 AvxSynth Team
> *
> * This file is part of FFmpeg
> @@ -31,20 +31,19 @@
> /* Enable function pointer definitions for runtime loading. */
> #define AVSC_NO_DECLSPEC
>
> -/* Platform-specific directives for AviSynth vs AvxSynth. */
> +/* Platform-specific directives. */
> #ifdef _WIN32
> #include "compat/w32dlfcn.h"
> #undef EXTERN_C
> - #include "compat/avisynth/avisynth_c.h"
> #define AVISYNTH_LIB "avisynth"
> - #define USING_AVISYNTH
> #else
> #include <dlfcn.h>
> - #include "compat/avisynth/avxsynth_c.h"
> - #define AVISYNTH_NAME "libavxsynth"
> + #define AVISYNTH_NAME "libavisynth"
> #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF
> #endif
>
> +#include <avisynth/avisynth_c.h>
> +
> typedef struct AviSynthLibrary {
> void *library;
> #define AVSC_DECLARE_FUNC(name) name ## _func name
> @@ -62,7 +61,6 @@ typedef struct AviSynthLibrary {
> AVSC_DECLARE_FUNC(avs_release_value);
> AVSC_DECLARE_FUNC(avs_release_video_frame);
> AVSC_DECLARE_FUNC(avs_take_clip);
> -#ifdef USING_AVISYNTH
> AVSC_DECLARE_FUNC(avs_bits_per_pixel);
> AVSC_DECLARE_FUNC(avs_get_height_p);
> AVSC_DECLARE_FUNC(avs_get_pitch_p);
> @@ -70,7 +68,6 @@ 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);
> -#endif
> #undef AVSC_DECLARE_FUNC
> } AviSynthLibrary;
>
> @@ -97,14 +94,12 @@ static const int avs_planes_packed[1] = { 0 };
> static const int avs_planes_grey[1] = { AVS_PLANAR_Y };
> static const int avs_planes_yuv[3] = { AVS_PLANAR_Y, AVS_PLANAR_U,
> AVS_PLANAR_V };
> -#ifdef USING_AVISYNTH
> static const int avs_planes_rgb[3] = { AVS_PLANAR_G, AVS_PLANAR_B,
> AVS_PLANAR_R };
> static const int avs_planes_yuva[4] = { AVS_PLANAR_Y, AVS_PLANAR_U,
> AVS_PLANAR_V, AVS_PLANAR_A };
> static const int avs_planes_rgba[4] = { AVS_PLANAR_G, AVS_PLANAR_B,
> AVS_PLANAR_R, AVS_PLANAR_A };
> -#endif
>
> /* A conflict between C++ global objects, atexit, and dynamic loading requires
> * us to register our own atexit handler to prevent double freeing. */
> @@ -142,7 +137,6 @@ static av_cold int avisynth_load_library(void)
> LOAD_AVS_FUNC(avs_release_value, 0);
> LOAD_AVS_FUNC(avs_release_video_frame, 0);
> LOAD_AVS_FUNC(avs_take_clip, 0);
> -#ifdef USING_AVISYNTH
> LOAD_AVS_FUNC(avs_bits_per_pixel, 1);
> LOAD_AVS_FUNC(avs_get_height_p, 1);
> LOAD_AVS_FUNC(avs_get_pitch_p, 1);
> @@ -150,7 +144,6 @@ 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);
> -#endif
> #undef LOAD_AVS_FUNC
>
> atexit(avisynth_atexit_handler);
> @@ -249,7 +242,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);
>
> switch (avs->vi->pixel_type) {
> -#ifdef USING_AVISYNTH
> /* 10~16-bit YUV pix_fmts (AviSynth+) */
> case AVS_CS_YUV444P10:
> st->codecpar->format = AV_PIX_FMT_YUV444P10;
> @@ -434,8 +426,7 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> case AVS_CS_BGR64:
> st->codecpar->format = AV_PIX_FMT_BGRA64;
> break;
> -#endif
> - /* AviSynth 2.5 and AvxSynth pix_fmts */
> + /* AviSynth 2.5 pix_fmts */
> case AVS_CS_BGR24:
> st->codecpar->format = AV_PIX_FMT_BGR24;
> break;
> @@ -461,7 +452,6 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> }
>
> switch (planar) {
> -#ifdef USING_AVISYNTH
> case 5: // Planar RGB + Alpha
> avs->n_planes = 4;
> avs->planes = avs_planes_rgba;
> @@ -474,7 +464,6 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
> avs->n_planes = 3;
> avs->planes = avs_planes_rgb;
> break;
> -#endif
> case 2: // Y8
> avs->n_planes = 1;
> avs->planes = avs_planes_grey;
> @@ -556,7 +545,7 @@ static int avisynth_open_file(AVFormatContext *s)
> AviSynthContext *avs = s->priv_data;
> AVS_Value arg, val;
> int ret;
> -#ifdef USING_AVISYNTH
> +#ifdef _WIN32
> char filename_ansi[MAX_PATH * 4];
> wchar_t filename_wc[MAX_PATH * 4];
> #endif
> @@ -564,7 +553,7 @@ static int avisynth_open_file(AVFormatContext *s)
> if (ret = avisynth_context_create(s))
> return ret;
>
> -#ifdef USING_AVISYNTH
> +#ifdef _WIN32
> /* Convert UTF-8 to ANSI code page */
> MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wc, MAX_PATH * 4);
> WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
> @@ -588,11 +577,9 @@ static int avisynth_open_file(AVFormatContext *s)
> avs->clip = avs_library.avs_take_clip(val, avs->env);
> avs->vi = avs_library.avs_get_video_info(avs->clip);
>
> -#ifdef USING_AVISYNTH
> /* On Windows, FFmpeg supports AviSynth interface version 6 or higher.
> * This includes AviSynth 2.6 RC1 or higher, and AviSynth+ r1718 or higher,
> - * and excludes 2.5 and the 2.6 alphas. Since AvxSynth identifies itself
> - * as interface version 3 like 2.5.8, this needs to be special-cased. */
> + * and excludes 2.5 and the 2.6 alphas. */
>
> if (avs_library.avs_get_version(avs->clip) < 6) {
> av_log(s, AV_LOG_ERROR,
> @@ -600,7 +587,6 @@ static int avisynth_open_file(AVFormatContext *s)
> ret = AVERROR_UNKNOWN;
> goto fail;
> }
> -#endif
>
> /* Release the AVS_Value as it will go out of scope. */
> avs_library.avs_release_value(val);
> @@ -652,23 +638,21 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
> if (discard)
> return 0;
>
> -#ifdef USING_AVISYNTH
> +#ifdef _WIN32
> /* Detect whether we're using AviSynth 2.6 or AviSynth+ by
> * looking for whether avs_is_planar_rgb exists. */
> if (GetProcAddress(avs_library.library, "avs_is_planar_rgb") == NULL)
> avsplus = 0;
> else
> avsplus = 1;
> -
> - /* avs_bits_per_pixel changed to AVSC_API with AviSynth 2.6, which
> - * requires going through avs_library, while AvxSynth has it under
> - * the older AVSC_INLINE type, so special-case this. */
> -
> - bits = avs_library.avs_bits_per_pixel(avs->vi);
> #else
> - bits = avs_bits_per_pixel(avs->vi);
> + /* AviSynth+ is now the only variant of AviSynth we support
> + * on Linux and macOS. */
> + avsplus = 1;
> #endif
>
> + bits = avs_library.avs_bits_per_pixel(avs->vi);
> +
> /* Without the cast to int64_t, calculation overflows at about 9k x 9k
> * resolution. */
> pkt->size = (((int64_t)avs->vi->width *
> @@ -696,19 +680,11 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
> dst_p = pkt->data;
> for (i = 0; i < avs->n_planes; i++) {
> plane = avs->planes[i];
> -#ifdef USING_AVISYNTH
> src_p = avs_library.avs_get_read_ptr_p(frame, plane);
> pitch = avs_library.avs_get_pitch_p(frame, plane);
>
> rowsize = avs_library.avs_get_row_size_p(frame, plane);
> planeheight = avs_library.avs_get_height_p(frame, plane);
> -#else
> - src_p = avs_get_read_ptr_p(frame, plane);
> - pitch = avs_get_pitch_p(frame, plane);
> -
> - rowsize = avs_get_row_size_p(frame, plane);
> - planeheight = avs_get_height_p(frame, plane);
> -#endif
>
> /* Flip RGB video. */
> if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) {
> @@ -716,14 +692,12 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
> pitch = -pitch;
> }
>
> -#ifdef USING_AVISYNTH
> /* Flip Planar RGB video */
> if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) ||
> avs_library.avs_is_planar_rgba(avs->vi))) {
> src_p = src_p + (planeheight - 1) * pitch;
> pitch = -pitch;
> }
> -#endif
>
> avs_library.avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch,
> rowsize, planeheight);
>
Ping.
More information about the ffmpeg-devel
mailing list