From patchwork Tue Aug 16 22:45:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hutchinson X-Patchwork-Id: 205 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp2362380vsd; Tue, 16 Aug 2016 15:45:56 -0700 (PDT) X-Received: by 10.194.16.65 with SMTP id e1mr43625396wjd.143.1471387555555; Tue, 16 Aug 2016 15:45:55 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t185si22724862wma.107.2016.08.16.15.45.55; Tue, 16 Aug 2016 15:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68818689B5F; Wed, 17 Aug 2016 01:45:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw0-f194.google.com (mail-yw0-f194.google.com [209.85.161.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D6D9689B08 for ; Wed, 17 Aug 2016 01:45:29 +0300 (EEST) Received: by mail-yw0-f194.google.com with SMTP id r9so4157415ywg.2 for ; Tue, 16 Aug 2016 15:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=AjBV8OV+LEnwBTQoDqoYwh6S1ck/PCOftLAqecqgm3k=; b=Yhx6lurTPIH8VataWU+2V1meoQutAlJ6UG1c5Dub3TxAHt4NCyj4exlMTcAJ9YNmCn vrlo19xow6+YLzdTNABBZQFBLjdl/YPyIc3JRpAAgzUoRydGA5v3SlXozQfkZXN+OSw5 7v+8yR+zG4PVad4t3tF6w0eUcg36+3JvELdwyKvSBQlQpPCqiGVKumNbRh0GquOjmc9G f9sK6SSmyMER3ZyYGcPDzUPfEz0uTSyXQfPQOWpSqZIjlcRDC5GfH7WkLKnv9YYAHPlh oa1BmeyOc+xsp+DS1/wpz+PBE4NReREZeb7rq8l5E9V6ZjCx2CS5ni1h4I5ekmkhiuKy lEWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AjBV8OV+LEnwBTQoDqoYwh6S1ck/PCOftLAqecqgm3k=; b=SYcrc9TFI1YlmcagtWDVQLka6LL2NSWT4e4T5J3C/Maedqj3cvSw8ROBXzFtxmu218 DxAG6UJdbgPO4r173QtY/giibJ8zl4ax8QX83BKoxksa0boVus6chKOTeTHAVAzFSfc+ vTIVDb69C9W93ovft48Ei8KwmwZlLllPGszs+mTKkl0+y3lYETBEu1qiSD6tP8yR/Fl8 Hw5hukrOxYK9G6WvmvWJ/D3CozT7az2sptqQGKNObFveoVRkE5FscFLtY/JuPO0itxxY 6xQO7q1TSxTXYGNpcihmBuxfiUrDM/EzcpXhHcKTDw0Y4OQP/p0tHFtpmrWKpRjiTZyH Jnwg== X-Gm-Message-State: AEkoouu5LwzhIlv4Kl4cAYNLkQ1S63dfckTfseLwxFCsBCXk7jV4qNz42B5cmKle5rAD4w== X-Received: by 10.129.116.86 with SMTP id p83mr25759098ywc.151.1471387529629; Tue, 16 Aug 2016 15:45:29 -0700 (PDT) Received: from localhost.localdomain (97-96-108-192.res.bhn.net. [97.96.108.192]) by smtp.gmail.com with ESMTPSA id u189sm13978051ywe.25.2016.08.16.15.45.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 15:45:29 -0700 (PDT) From: Stephen Hutchinson To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2016 18:45:21 -0400 Message-Id: <1471387521-20663-1-git-send-email-qyot27@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20160816180009.GT5460@nb4> References: <20160816180009.GT5460@nb4> Subject: [FFmpeg-devel] [PATCH] avisynth: support pix_fmts added to AviSynth+ X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 | 183 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 1 deletion(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 04ac257..1fe8e08 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,14 @@ 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. */ @@ -138,6 +148,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 +234,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 +250,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 +396,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 +430,20 @@ 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; + 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; +#endif case 2: // Y8 avs->n_planes = 1; avs->planes = avs_planes_grey; @@ -457,6 +621,16 @@ 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. */ + + int avsplus; + + 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 +687,13 @@ 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))) + pitch = -pitch; +#endif + avs_library.avs_bit_blt(avs->env, dst_p, rowsize, src_p, pitch, rowsize, planeheight); dst_p += rowsize * planeheight;