]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/avisynth.c
Merge commit '13e4f2c7f7857feb6885f0c2ea8c9ddf438f46ea'
[ffmpeg] / libavformat / avisynth.c
index fbd4a8d4b03597086d25de89738ead48dada329a..4af58f62f77ba4114158b2e451ca44a6db52677a 100644 (file)
@@ -31,7 +31,6 @@
   #include <windows.h>
   #undef EXTERN_C
   #include "compat/avisynth/avisynth_c.h"
-  #include "compat/avisynth/avisynth_c_25.h"
   #define AVISYNTH_LIB "avisynth"
   #define USING_AVISYNTH
 #else
@@ -65,6 +64,17 @@ 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);
+    AVSC_DECLARE_FUNC(avs_get_read_ptr_p);
+    AVSC_DECLARE_FUNC(avs_get_row_size_p);
+    AVSC_DECLARE_FUNC(avs_is_yv24);
+    AVSC_DECLARE_FUNC(avs_is_yv16);
+    AVSC_DECLARE_FUNC(avs_is_yv411);
+    AVSC_DECLARE_FUNC(avs_is_y8);
+#endif
 #undef AVSC_DECLARE_FUNC
 } AviSynthLibrary;
 
@@ -128,6 +138,17 @@ 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);
+    LOAD_AVS_FUNC(avs_get_read_ptr_p, 1);
+    LOAD_AVS_FUNC(avs_get_row_size_p, 1);
+    LOAD_AVS_FUNC(avs_is_yv24, 1);
+    LOAD_AVS_FUNC(avs_is_yv16, 1);
+    LOAD_AVS_FUNC(avs_is_yv411, 1);
+    LOAD_AVS_FUNC(avs_is_y8, 1);
+#endif
 #undef LOAD_AVS_FUNC
 
     atexit(avisynth_atexit_handler);
@@ -384,6 +405,20 @@ 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. */
+
+    if (avs_library.avs_get_version(avs->clip) < 6) {
+        av_log(s, AV_LOG_ERROR,
+               "AviSynth version is too old. Please upgrade to either AviSynth 2.6 >= RC1 or AviSynth+ >= r1718.\n");
+        ret = AVERROR_UNKNOWN;
+        goto fail;
+    }
+#endif
+
     /* Release the AVS_Value as it will go out of scope. */
     avs_library.avs_release_value(val);
 
@@ -438,17 +473,19 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
      * Since AvxSynth doesn't have these functions, special-case
      * it in order to avoid implicit declaration errors. */
 
-    if (avs_is_yv24(avs->vi))
+    if (avs_library.avs_is_yv24(avs->vi))
         bits = 24;
-    else if (avs_is_yv16(avs->vi))
+    else if (avs_library.avs_is_yv16(avs->vi))
         bits = 16;
-    else if (avs_is_yv411(avs->vi))
+    else if (avs_library.avs_is_yv411(avs->vi))
         bits = 12;
-    else if (avs_is_y8(avs->vi))
+    else if (avs_library.avs_is_y8(avs->vi))
         bits = 8;
     else
+        bits = avs_library.avs_bits_per_pixel(avs->vi);
+#else
+    bits = avs_bits_per_pixel(avs->vi);
 #endif
-        bits = avs_bits_per_pixel(avs->vi);
 
     /* Without the cast to int64_t, calculation overflows at about 9k x 9k
      * resolution. */
@@ -477,18 +514,16 @@ 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);
 
-#ifdef USING_AVISYNTH
-        if (avs_library.avs_get_version(avs->clip) == 3) {
-            rowsize     = avs_get_row_size_p_25(frame, plane);
-            planeheight = avs_get_height_p_25(frame, plane);
-        } else {
-            rowsize     = avs_get_row_size_p(frame, plane);
-            planeheight = avs_get_height_p(frame, plane);
-        }
-#else
         rowsize     = avs_get_row_size_p(frame, plane);
         planeheight = avs_get_height_p(frame, plane);
 #endif