diff mbox

[FFmpeg-devel,2/2] avisynth: support pix_fmts added to AviSynth+

Message ID 1471279051-8180-3-git-send-email-qyot27@gmail.com
State Superseded
Headers show

Commit Message

Stephen Hutchinson Aug. 15, 2016, 4:37 p.m. UTC
A number of new pix_fmts have been added to AviSynth+:
16-bit packed RGB and RGBA
10-, 12-, 14, and 16-bit YUV 4:2:0, 4:2:2, and 4:4:4
8-, 10-, 12-, 14-, and 16-bit Planar RGB
8-, 10-, 12-, 14-, and 16-bit Planar YUVA and Planar RGBA*
10-, 12-, 14-, and 16-bit GRAY variants*
32-bit floating point Planar YUV(A), Planar RGB(A), and GRAY*

*some of which are not currently available pix_fmts here and were
 not added to the demuxer due to this
---
 libavformat/avisynth.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 175 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Aug. 16, 2016, 1:31 p.m. UTC | #1
On Mon, Aug 15, 2016 at 12:37:31PM -0400, Stephen Hutchinson wrote:
> A number of new pix_fmts have been added to AviSynth+:
> 16-bit packed RGB and RGBA
> 10-, 12-, 14, and 16-bit YUV 4:2:0, 4:2:2, and 4:4:4
> 8-, 10-, 12-, 14-, and 16-bit Planar RGB
> 8-, 10-, 12-, 14-, and 16-bit Planar YUVA and Planar RGBA*
> 10-, 12-, 14-, and 16-bit GRAY variants*
> 32-bit floating point Planar YUV(A), Planar RGB(A), and GRAY*
> 
> *some of which are not currently available pix_fmts here and were
>  not added to the demuxer due to this
> ---
>  libavformat/avisynth.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 175 insertions(+), 1 deletion(-)

breaks build

libavformat/avisynth.c:100:40: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
libavformat/avisynth.c:100:54: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
make: *** [libavformat/avisynth.o] Error 1

[...]
Roger Pack Aug. 16, 2016, 1:46 p.m. UTC | #2
Does this require some version check in configure to be added as well?

On 8/16/16, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Mon, Aug 15, 2016 at 12:37:31PM -0400, Stephen Hutchinson wrote:
>> A number of new pix_fmts have been added to AviSynth+:
>> 16-bit packed RGB and RGBA
>> 10-, 12-, 14, and 16-bit YUV 4:2:0, 4:2:2, and 4:4:4
>> 8-, 10-, 12-, 14-, and 16-bit Planar RGB
>> 8-, 10-, 12-, 14-, and 16-bit Planar YUVA and Planar RGBA*
>> 10-, 12-, 14-, and 16-bit GRAY variants*
>> 32-bit floating point Planar YUV(A), Planar RGB(A), and GRAY*
>>
>> *some of which are not currently available pix_fmts here and were
>>  not added to the demuxer due to this
>> ---
>>  libavformat/avisynth.c | 176
>> ++++++++++++++++++++++++++++++++++++++++++++++++-
>>  1 file changed, 175 insertions(+), 1 deletion(-)
>
> breaks build
>
> libavformat/avisynth.c:100:40: error: ‘AVS_PLANAR_G’ undeclared here (not in
> a function)
> libavformat/avisynth.c:100:54: error: ‘AVS_PLANAR_B’ undeclared here (not in
> a function)
> libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in
> a function)
> libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in
> a function)
> libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
> libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named
> ‘avs_is_planar_rgb’
> libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named
> ‘avs_is_planar_rgba’
> make: *** [libavformat/avisynth.o] Error 1
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Rewriting code that is poorly written but fully understood is good.
> Rewriting code that one doesnt understand is a sign that one is less smart
> then the original author, trying to rewrite it will not make it better.
>
Stephen Hutchinson Aug. 16, 2016, 4:57 p.m. UTC | #3
On 8/16/2016 9:31 AM, Michael Niedermayer wrote:
>
> breaks build
>
> libavformat/avisynth.c:100:40: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
> libavformat/avisynth.c:100:54: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
> libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
> libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
> libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
> libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
> libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
> make: *** [libavformat/avisynth.o] Error 1
>

That looks like the other patch updating compat/avisynth/avisynth_c.h 
wasn't applied first.
Stephen Hutchinson Aug. 16, 2016, 5:07 p.m. UTC | #4
On 8/16/2016 9:46 AM, Roger Pack wrote:
> Does this require some version check in configure to be added as well?
>

No. We ship the header ourselves, rendering a version check in configure 
moot.  What configure checks for is the presence of the dynamic loading 
functionality that the library depends on.

The actual version compliancy checking occurs inside the AviSynth 
demuxer: version 2.5 is checked for at load time and rejected.  This 
patch adds a check for whether we're using AviSynth+ by detecting the 
presence of the planar RGB functions in the library, and if that's false 
(in other words, 2.6 is the one being used), it stops 2.6 from even 
attempting to use the two functions that it doesn't have.
Michael Niedermayer Aug. 16, 2016, 6 p.m. UTC | #5
On Tue, Aug 16, 2016 at 12:57:53PM -0400, Stephen Hutchinson wrote:
> On 8/16/2016 9:31 AM, Michael Niedermayer wrote:
> >
> >breaks build
> >
> >libavformat/avisynth.c:100:40: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
> >libavformat/avisynth.c:100:54: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
> >libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
> >libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
> >libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
> >libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
> >libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
> >make: *** [libavformat/avisynth.o] Error 1
> >
> 
> That looks like the other patch updating
> compat/avisynth/avisynth_c.h wasn't applied first.

git log -2
commit 67f4e2cc041377cc5272a76ee1beaf73c3e49514
Author: Stephen Hutchinson <qyot27@gmail.com>
Date:   Mon Aug 15 12:37:31 2016 -0400

    avisynth: support pix_fmts added to AviSynth+

    A number of new pix_fmts have been added to AviSynth+:
    16-bit packed RGB and RGBA
    10-, 12-, 14, and 16-bit YUV 4:2:0, 4:2:2, and 4:4:4
    8-, 10-, 12-, 14-, and 16-bit Planar RGB
    8-, 10-, 12-, 14-, and 16-bit Planar YUVA and Planar RGBA*
    10-, 12-, 14-, and 16-bit GRAY variants*
    32-bit floating point Planar YUV(A), Planar RGB(A), and GRAY*

    *some of which are not currently available pix_fmts here and were
     not added to the demuxer due to this

    Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

commit 220babe8078489065637b9b1bf2de013de7e6fd5
Author: Stephen Hutchinson <qyot27@gmail.com>
Date:   Mon Aug 15 12:37:30 2016 -0400

    compat/avisynth: update AviSynth+ header

    Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

make distclean ; ./configure --enable-avisynth && make -j12

libavformat/avisynth.c:100:43: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
libavformat/avisynth.c:100:57: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
make: *** [libavformat/avisynth.o] Error 1
make: *** Waiting for unfinished jobs....


This works before the 2 patches

That is all on linux, straight compilation no cross build or anything

[...]
Stephen Hutchinson Aug. 16, 2016, 7:23 p.m. UTC | #6
On 8/16/2016 2:00 PM, Michael Niedermayer wrote:
> On Tue, Aug 16, 2016 at 12:57:53PM -0400, Stephen Hutchinson wrote:
>> On 8/16/2016 9:31 AM, Michael Niedermayer wrote:
>>>
>>> breaks build
>>>
>>> libavformat/avisynth.c:100:40: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
>>> libavformat/avisynth.c:100:54: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
>>> libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
>>> libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
>>> libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
>>> libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
>>> libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
>>> make: *** [libavformat/avisynth.o] Error 1
>>>
>>
>> That looks like the other patch updating
>> compat/avisynth/avisynth_c.h wasn't applied first.
>
> git log -2
> commit 67f4e2cc041377cc5272a76ee1beaf73c3e49514
> Author: Stephen Hutchinson <qyot27@gmail.com>
> Date:   Mon Aug 15 12:37:31 2016 -0400
>
>     avisynth: support pix_fmts added to AviSynth+
>
>     A number of new pix_fmts have been added to AviSynth+:
>     16-bit packed RGB and RGBA
>     10-, 12-, 14, and 16-bit YUV 4:2:0, 4:2:2, and 4:4:4
>     8-, 10-, 12-, 14-, and 16-bit Planar RGB
>     8-, 10-, 12-, 14-, and 16-bit Planar YUVA and Planar RGBA*
>     10-, 12-, 14-, and 16-bit GRAY variants*
>     32-bit floating point Planar YUV(A), Planar RGB(A), and GRAY*
>
>     *some of which are not currently available pix_fmts here and were
>      not added to the demuxer due to this
>
>     Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>
> commit 220babe8078489065637b9b1bf2de013de7e6fd5
> Author: Stephen Hutchinson <qyot27@gmail.com>
> Date:   Mon Aug 15 12:37:30 2016 -0400
>
>     compat/avisynth: update AviSynth+ header
>
>     Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>
> make distclean ; ./configure --enable-avisynth && make -j12
>
> libavformat/avisynth.c:100:43: error: ‘AVS_PLANAR_G’ undeclared here (not in a function)
> libavformat/avisynth.c:100:57: error: ‘AVS_PLANAR_B’ undeclared here (not in a function)
> libavformat/avisynth.c:101:43: error: ‘AVS_PLANAR_R’ undeclared here (not in a function)
> libavformat/avisynth.c:103:57: error: ‘AVS_PLANAR_A’ undeclared here (not in a function)
> libavformat/avisynth.c: In function ‘avisynth_read_packet_video’:
> libavformat/avisynth.c:686:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgb’
> libavformat/avisynth.c:687:36: error: ‘AviSynthLibrary’ has no member named ‘avs_is_planar_rgba’
> make: *** [libavformat/avisynth.o] Error 1
> make: *** Waiting for unfinished jobs....
>
>
> This works before the 2 patches
>
> That is all on linux, straight compilation no cross build or anything
>
> [...]
>

Oh, right.  Yeah, I forgot about that.  There need to be ENABLE_AVISYNTH 
ifdefs around those because AvxSynth's header is the one that wasn't 
updated.

I'll fix it and send the patch again.
diff mbox

Patch

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 04ac257..5b74caa 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -68,6 +68,8 @@  typedef struct AviSynthLibrary {
     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_planar_rgb);
+    AVSC_DECLARE_FUNC(avs_is_planar_rgba);
 #endif
 #undef AVSC_DECLARE_FUNC
 } AviSynthLibrary;
@@ -95,6 +97,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 };
+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 };
 
 /* A conflict between C++ global objects, atexit, and dynamic loading requires
  * us to register our own atexit handler to prevent double freeing. */
@@ -138,6 +146,8 @@  static av_cold int avisynth_load_library(void)
     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_planar_rgb, 1);
+    LOAD_AVS_FUNC(avs_is_planar_rgba, 1);
 #endif
 #undef LOAD_AVS_FUNC
 
@@ -222,7 +232,7 @@  static av_cold void avisynth_atexit_handler(void)
 static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
 {
     AviSynthContext *avs = s->priv_data;
-    int planar = 0; // 0: packed, 1: YUV, 2: Y8
+    int planar = 0; // 0: packed, 1: YUV, 2: Y8, 3: Planar RGB, 4: YUVA, 5: Planar RGBA
 
     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
     st->codecpar->codec_id   = AV_CODEC_ID_RAWVIDEO;
@@ -238,6 +248,136 @@  static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
 
     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;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV422P10:
+        st->codecpar->format = AV_PIX_FMT_YUV422P10;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV420P10:
+        st->codecpar->format = AV_PIX_FMT_YUV420P10;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV444P12:
+        st->codecpar->format = AV_PIX_FMT_YUV444P12;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV422P12:
+        st->codecpar->format = AV_PIX_FMT_YUV422P12;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV420P12:
+        st->codecpar->format = AV_PIX_FMT_YUV420P12;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV444P14:
+        st->codecpar->format = AV_PIX_FMT_YUV444P14;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV422P14:
+        st->codecpar->format = AV_PIX_FMT_YUV422P14;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV420P14:
+        st->codecpar->format = AV_PIX_FMT_YUV420P14;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV444P16:
+        st->codecpar->format = AV_PIX_FMT_YUV444P16;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV422P16:
+        st->codecpar->format = AV_PIX_FMT_YUV422P16;
+        planar               = 1;
+        break;
+    case AVS_CS_YUV420P16:
+        st->codecpar->format = AV_PIX_FMT_YUV420P16;
+        planar               = 1;
+        break;
+/* 8~16-bit YUV pix_fmts with Alpha (AviSynth+) */
+    case AVS_CS_YUVA444:
+        st->codecpar->format = AV_PIX_FMT_YUVA444P;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA422:
+        st->codecpar->format = AV_PIX_FMT_YUVA422P;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA420:
+        st->codecpar->format = AV_PIX_FMT_YUVA420P;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA444P10:
+        st->codecpar->format = AV_PIX_FMT_YUVA444P10;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA422P10:
+        st->codecpar->format = AV_PIX_FMT_YUVA422P10;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA420P10:
+        st->codecpar->format = AV_PIX_FMT_YUVA420P10;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA444P16:
+        st->codecpar->format = AV_PIX_FMT_YUVA444P16;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA422P16:
+        st->codecpar->format = AV_PIX_FMT_YUVA422P16;
+        planar               = 4;
+        break;
+    case AVS_CS_YUVA420P16:
+        st->codecpar->format = AV_PIX_FMT_YUVA420P16;
+        planar               = 4;
+        break;
+/* Planar RGB pix_fmts (AviSynth+)  */
+    case AVS_CS_RGBP:
+        st->codecpar->format = AV_PIX_FMT_GBRP;
+        planar               = 3;
+        break;
+    case AVS_CS_RGBP10:
+        st->codecpar->format = AV_PIX_FMT_GBRP10;
+        planar               = 3;
+        break;
+    case AVS_CS_RGBP12:
+        st->codecpar->format = AV_PIX_FMT_GBRP12;
+        planar               = 3;
+        break;
+    case AVS_CS_RGBP14:
+        st->codecpar->format = AV_PIX_FMT_GBRP14;
+        planar               = 3;
+        break;
+    case AVS_CS_RGBP16:
+        st->codecpar->format = AV_PIX_FMT_GBRP16;
+        planar               = 3;
+        break;
+/* Planar RGB pix_fmts with Alpha (AviSynth+) */
+    case AVS_CS_RGBAP:
+        st->codecpar->format = AV_PIX_FMT_GBRAP;
+        planar               = 5;
+        break;
+    case AVS_CS_RGBAP10:
+        st->codecpar->format = AV_PIX_FMT_GBRAP10;
+        planar               = 5;
+        break;
+    case AVS_CS_RGBAP12:
+        st->codecpar->format = AV_PIX_FMT_GBRAP12;
+        planar               = 5;
+        break;
+    case AVS_CS_RGBAP16:
+        st->codecpar->format = AV_PIX_FMT_GBRAP16;
+        planar               = 5;
+        break;
+/* GRAY16 (AviSynth+) */
+    case AVS_CS_Y16:
+        st->codecpar->format = AV_PIX_FMT_GRAY16;
+        planar               = 2;
+        break;
+/* pix_fmts added in AviSynth 2.6 */
     case AVS_CS_YV24:
         st->codecpar->format = AV_PIX_FMT_YUV444P;
         planar               = 1;
@@ -254,7 +394,15 @@  static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
         st->codecpar->format = AV_PIX_FMT_GRAY8;
         planar               = 2;
         break;
+/* 16-bit packed RGB pix_fmts (AviSynth+) */
+    case AVS_CS_BGR48:
+        st->codecpar->format = AV_PIX_FMT_BGR48;
+        break;
+    case AVS_CS_BGR64:
+        st->codecpar->format = AV_PIX_FMT_BGRA64;
+        break;
 #endif
+/* AviSynth 2.5 and AvxSynth pix_fmts */
     case AVS_CS_BGR24:
         st->codecpar->format = AV_PIX_FMT_BGR24;
         break;
@@ -280,6 +428,18 @@  static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st)
     }
 
     switch (planar) {
+    case 5: // Planar RGB + Alpha
+        avs->n_planes = 4;
+        avs->planes   = avs_planes_rgba;
+        break;
+    case 4: // YUV + Alpha
+        avs->n_planes = 4;
+        avs->planes   = avs_planes_yuva;
+        break;
+    case 3: // Planar RGB
+        avs->n_planes = 3;
+        avs->planes   = avs_planes_rgb;
+        break;
     case 2: // Y8
         avs->n_planes = 1;
         avs->planes   = avs_planes_grey;
@@ -447,6 +607,7 @@  static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
     const unsigned char *src_p;
     int n, i, plane, rowsize, planeheight, pitch, bits;
     const char *error;
+    int avsplus;
 
     if (avs->curr_frame >= avs->vi->num_frames)
         return AVERROR_EOF;
@@ -457,6 +618,14 @@  static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
         return 0;
 
 #ifdef USING_AVISYNTH
+    /* 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. */
@@ -513,6 +682,11 @@  static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
             pitch = -pitch;
         }
 
+        /* Flip Planar RGB video. */
+        if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) ||
+                        avs_library.avs_is_planar_rgba(avs->vi)))
+            pitch = -pitch;
+
         avs_library.avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch,
                                  rowsize, planeheight);
         dst_p += rowsize * planeheight;