X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Favisynth.c;h=2c08ace8dbbe4d5ea50789cac2b6e911d0087cb9;hb=b5985ce44dea053d9de80b51d049dbb35e46e356;hp=250a489321edc6b150e079d2c960c47be48f6b37;hpb=c2631dfd0a0a12050cc1765fd41702c5e93abee5;p=ffmpeg diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 250a489321e..2c08ace8dbb 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 - #include "compat/avisynth/avxsynth_c.h" - #define AVISYNTH_NAME "libavxsynth" + #define AVISYNTH_NAME "libavisynth" #define AVISYNTH_LIB AVISYNTH_NAME SLIBSUF #endif +#include + 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. */ @@ -123,7 +118,8 @@ static av_cold int avisynth_load_library(void) return AVERROR_UNKNOWN; #define LOAD_AVS_FUNC(name, continue_on_fail) \ - avs_library.name = dlsym(avs_library.library, #name); \ + avs_library.name = (name ## _func) \ + dlsym(avs_library.library, #name); \ if (!continue_on_fail && !avs_library.name) \ goto fail; @@ -141,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); @@ -149,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); @@ -248,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; @@ -323,6 +316,10 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) st->codecpar->format = AV_PIX_FMT_YUVA420P10; planar = 4; break; + case AVS_CS_YUVA422P12: + st->codecpar->format = AV_PIX_FMT_YUVA422P12; + planar = 4; + break; case AVS_CS_YUVA444P16: st->codecpar->format = AV_PIX_FMT_YUVA444P16; planar = 4; @@ -356,6 +353,11 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) st->codecpar->format = AV_PIX_FMT_GBRP16; planar = 3; break; + /* Single precision floating point Planar RGB (AviSynth+) */ + case AVS_CS_RGBPS: + st->codecpar->format = AV_PIX_FMT_GBRPF32; + planar = 3; + break; /* Planar RGB pix_fmts with Alpha (AviSynth+) */ case AVS_CS_RGBAP: st->codecpar->format = AV_PIX_FMT_GBRAP; @@ -373,11 +375,33 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) st->codecpar->format = AV_PIX_FMT_GBRAP16; planar = 5; break; - /* GRAY16 (AviSynth+) */ + /* Single precision floating point Planar RGB with Alpha (AviSynth+) */ + case AVS_CS_RGBAPS: + st->codecpar->format = AV_PIX_FMT_GBRAPF32; + planar = 5; + break; + /* 10~16-bit gray pix_fmts (AviSynth+) */ + case AVS_CS_Y10: + st->codecpar->format = AV_PIX_FMT_GRAY10; + planar = 2; + break; + case AVS_CS_Y12: + st->codecpar->format = AV_PIX_FMT_GRAY12; + planar = 2; + break; + case AVS_CS_Y14: + st->codecpar->format = AV_PIX_FMT_GRAY14; + planar = 2; + break; case AVS_CS_Y16: st->codecpar->format = AV_PIX_FMT_GRAY16; planar = 2; break; + /* Single precision floating point gray (AviSynth+) */ + case AVS_CS_Y32: + st->codecpar->format = AV_PIX_FMT_GRAYF32; + planar = 2; + break; /* pix_fmts added in AviSynth 2.6 */ case AVS_CS_YV24: st->codecpar->format = AV_PIX_FMT_YUV444P; @@ -402,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; @@ -429,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; @@ -442,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; @@ -524,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 @@ -532,14 +553,14 @@ 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); + MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4); WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi, MAX_PATH * 4, NULL, NULL); arg = avs_new_value_string(filename_ansi); #else - arg = avs_new_value_string(s->filename); + arg = avs_new_value_string(s->url); #endif val = avs_library.avs_invoke(avs->env, "Import", arg, 0); if (avs_is_error(val)) { @@ -556,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, @@ -568,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); @@ -608,7 +626,7 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, AVS_VideoFrame *frame; unsigned char *dst_p; const unsigned char *src_p; - int n, i, plane, rowsize, planeheight, pitch, bits; + int n, i, plane, rowsize, planeheight, pitch, bits, ret; const char *error; int avsplus av_unused; @@ -620,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 * @@ -644,8 +660,8 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, if (!pkt->size) return AVERROR_UNKNOWN; - if (av_new_packet(pkt, pkt->size) < 0) - return AVERROR(ENOMEM); + if ((ret = av_new_packet(pkt, pkt->size)) < 0) + return ret; pkt->pts = n; pkt->dts = n; @@ -664,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)) { @@ -684,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); @@ -707,7 +713,7 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, { AviSynthContext *avs = s->priv_data; AVRational fps, samplerate; - int samples; + int samples, ret; int64_t n; const char *error; @@ -750,8 +756,8 @@ static int avisynth_read_packet_audio(AVFormatContext *s, AVPacket *pkt, if (!pkt->size) return AVERROR_UNKNOWN; - if (av_new_packet(pkt, pkt->size) < 0) - return AVERROR(ENOMEM); + if ((ret = av_new_packet(pkt, pkt->size)) < 0) + return ret; pkt->pts = n; pkt->dts = n;