diff mbox

[FFmpeg-devel,2/5] libavformat/avisynth: enable additional pix_fmts

Message ID 20190324202540.6502-3-qyot27@gmail.com
State Accepted
Commit b1681bad33581bc8a018bc9b6ec02761162240e4
Headers show

Commit Message

Stephen Hutchinson March 24, 2019, 8:25 p.m. UTC
These pix_fmts have been added to FFmpeg in the 31 months since
commit 92916e8542e425ca20daddb490261a5818643206 added support for
the larger number of pix_fmts that AviSynth+ can use. They were
present in AviSynth+ even then, just not in libavutil.
---
 libavformat/avisynth.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Carl Eugen Hoyos March 24, 2019, 11:07 p.m. UTC | #1
2019-03-24 21:25 GMT+01:00, Stephen Hutchinson <qyot27@gmail.com>:
> These pix_fmts have been added to FFmpeg in the 31 months since
> commit 92916e8542e425ca20daddb490261a5818643206 added support for
> the larger number of pix_fmts that AviSynth+ can use. They were
> present in AviSynth+ even then, just not in libavutil.

> +    /* Single precision floating point Planar RGB (AviSynth+) */
> +    case AVS_CS_RGBPS:
> +        st->codecpar->format = AV_PIX_FMT_GBRPF32;

> +    /* Single precision floating point Planar RGB with Alpha (AviSynth+) */
> +    case AVS_CS_RGBAPS:
> +        st->codecpar->format = AV_PIX_FMT_GBRAPF32;

Were you able to test these two in any way?
Is there absolutely no danger that they mean something
completely different in avisynth?

Thank you, Carl Eugen
Stephen Hutchinson March 25, 2019, 1:13 a.m. UTC | #2
On 3/24/2019 7:07 PM, Carl Eugen Hoyos wrote:
> 2019-03-24 21:25 GMT+01:00, Stephen Hutchinson <qyot27@gmail.com>:
>> These pix_fmts have been added to FFmpeg in the 31 months since
>> commit 92916e8542e425ca20daddb490261a5818643206 added support for
>> the larger number of pix_fmts that AviSynth+ can use. They were
>> present in AviSynth+ even then, just not in libavutil.
>> +    /* Single precision floating point Planar RGB (AviSynth+) */
>> +    case AVS_CS_RGBPS:
>> +        st->codecpar->format = AV_PIX_FMT_GBRPF32;
>> +    /* Single precision floating point Planar RGB with Alpha (AviSynth+) */
>> +    case AVS_CS_RGBAPS:
>> +        st->codecpar->format = AV_PIX_FMT_GBRAPF32;
> Were you able to test these two in any way?
> Is there absolutely no danger that they mean something
> completely different in avisynth?
There shouldn't be any danger whatsoever.  AviSynth+ supports 32bpp 
video only as being floating point¹,
and the plane order is exactly the same as the other RGB(A)P formats 
libavformat already support in
AviSynth scripts².

AviSynth+-side, they can be tested with relatively simple scripts that 
generate content in these pix_fmts.
Planar RGB Float:
Version().ConvertToPlanarRGB().ConvertBits(32) # ConvertToFloat() is an 
older, more specific alternative to the ConvertBits call
or
BlankClip(pixel_type="RGBPS")


Planar RGBA Float:
Version().ConvertToPlanarRGB().ConvertBits(32).AddAlphaPlane()
or
BlankClip(pixel_type="RGBAPS")

I also tested with real video input. I don't have any natively-float 
RGB(A) samples,
so I used the above conversion functions on a standard 8bpp 4:2:0 input, and
verified that the script is detected as gbr(a)pf32 in FFmpeg, and the actual
output was correct when previewed with a build of mpv linked against the 
patched
libavformat (and it also detected the video as gbr(a)pf32).  I wasn't 
able to preview
either of those formats in ffplay, but I think that may simply be a 
problem with the
way I built SDL2, unless SDL2 itself doesn't support floating-point 
RGB(A); the
Y32/GRAYF32 test worked in ffplay.

¹http://avisynth.nl/index.php/Avisynthplus_color_formats (see footnote 
2, linked from the Bit Depth column in the table)

²http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavformat/avisynth.c;h=250a489321edc6b150e079d2c960c47be48f6b37;hb=c3b517dac2bbd3007c5ac8fc61efe87661dda5c0#l100,
the formats themselves defined in avisynth_c.h (using the 
AVS_GENERIC_RGBP and AVS_GENERIC_RGBAP values):
http://git.videolan.org/?p=ffmpeg.git;a=blob;f=compat/avisynth/avisynth_c.h;h=605b92ae62f94e374242dc90f1e4f2ea1f7ac864;hb=c3b517dac2bbd3007c5ac8fc61efe87661dda5c0#l186
http://git.videolan.org/?p=ffmpeg.git;a=blob;f=compat/avisynth/avisynth_c.h;h=605b92ae62f94e374242dc90f1e4f2ea1f7ac864;hb=c3b517dac2bbd3007c5ac8fc61efe87661dda5c0#l194
Carl Eugen Hoyos March 26, 2019, 10:55 a.m. UTC | #3
2019-03-25 2:13 GMT+01:00, Stephen Hutchinson <qyot27@gmail.com>:
> On 3/24/2019 7:07 PM, Carl Eugen Hoyos wrote:
>> 2019-03-24 21:25 GMT+01:00, Stephen Hutchinson <qyot27@gmail.com>:
>>> These pix_fmts have been added to FFmpeg in the 31 months since
>>> commit 92916e8542e425ca20daddb490261a5818643206 added support for
>>> the larger number of pix_fmts that AviSynth+ can use. They were
>>> present in AviSynth+ even then, just not in libavutil.
>>> +    /* Single precision floating point Planar RGB (AviSynth+) */
>>> +    case AVS_CS_RGBPS:
>>> +        st->codecpar->format = AV_PIX_FMT_GBRPF32;
>>> +    /* Single precision floating point Planar RGB with Alpha (AviSynth+)
>>> */
>>> +    case AVS_CS_RGBAPS:
>>> +        st->codecpar->format = AV_PIX_FMT_GBRAPF32;
>> Were you able to test these two in any way?
>> Is there absolutely no danger that they mean something
>> completely different in avisynth?
> There shouldn't be any danger whatsoever.

Thank you for the extensive explanation!

Carl Eugen
diff mbox

Patch

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 250a489321..2181510c2f 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -323,6 +323,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 +360,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 +382,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;