From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id C103647135
	for <ffmpegdev@gitmailbox.com>; Tue, 26 Dec 2023 19:06:52 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E51E68CC39;
	Tue, 26 Dec 2023 21:06:49 +0200 (EET)
Received: from EUR05-DB8-obe.outbound.protection.outlook.com
 (mail-db8eur05olkn2040.outbound.protection.outlook.com [40.92.89.40])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2422D68C313
 for <ffmpeg-devel@ffmpeg.org>; Tue, 26 Dec 2023 21:06:42 +0200 (EET)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=IHjPx9IirA6/TGqaOIFdc1bqkSyZSDbYJSRrO5TJ+zGDXjoFrWG6W+86mw6ZGCk9g6sG/hvP2hE/gEakoRO8fTtqzQojKivQDXBw7I+u+jiADYyOn2ETo1GVbpuvlZO5ux0oaWKZKyip2a7mEAzqP5tyiTkR/mPggxRkxngyLwlfxJyOJasFUqDsXr3DY2GnBWoQEi855CQELL6wbccQ7BLJUgMD4VGs/e1CO1EYaSZ/JL88vXlmX4/GYD/Yb0UGXMYmRRUujEFTg8AIP0/Pb/XIVU4/iB5OQLIoWuvZHf5Fgnd3HfQ98paFrR69ZkfqLTz1wbSq6Y4J+OnOVstbCQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=t4GfjqwEUsCjjpWkcW1IeQ52rMyJmgC4KnqA2tCxvCc=;
 b=kBhMNkGz8qSJ+m5UfIORaPQSZur5PoFRFencFMRI0TsN9/W9HDNIsP/KhT9VaJc68cFbxh2YDoTUhsrnYpaTegEDFa22BvUZ+FdH7aNjrn0cyE+OrYNPjU/rzSNQaop/MH3X0WoKwVzythaYWPhxrAf6ZlFu5R3nAEy1X5BKchCLWFuMPx/uM1Wz5IklEOsBQhLwbsYIpSwdmZ/ZiEymjU6nBQQr741kMkM0ydp94eemB6UC84yhcGaHsF0aPTgZwqtbsYe00Q/QiZpQh8bs+OYS1XF3begbcbai706oJIIoCZ0BbC6vciZtmswc0vWPxP0pjVtUVDsKpsrBVVqUgA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com;
 s=selector1;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=t4GfjqwEUsCjjpWkcW1IeQ52rMyJmgC4KnqA2tCxvCc=;
 b=DYe5EBjDpTug+mtIWql6NBgckZEZbEoYnlMq8m3TjjvvIcHMqfgynJ2tP4B/QZYR42KQg1zfAs//VLAnWlH/WI+ZWcebKWr+RXoJ6gaBj9igCe5s8SEAqnbqaRIx1vLhvAer3WT8gr+3aX1j+m70JysvGNIJzcyHatQheoGBK5ccLqmqIRwYSsoox0GQuQn7s5IEJjdIHVfZhKCuQ7AknXJf09/wYqKO9j0vTGPY1H8kG2pnDKDHZjJrJ8pJRUaLblPNOLYG7y8xjuKZG1uug6koCFCq1SbgYqL9wnCUD8VJG4ob1jVTSwwvh10JlMqoOnVpLpN32BpgprrqFT6UUA==
Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14)
 by AM8P250MB0076.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:36f::15)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.18; Tue, 26 Dec
 2023 19:06:39 +0000
Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
 ([fe80::f59c:9cff:a42d:bde]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
 ([fe80::f59c:9cff:a42d:bde%3]) with mapi id 15.20.7113.027; Tue, 26 Dec 2023
 19:06:39 +0000
Message-ID: <AS8P250MB0744898E86189E92404280168F98A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
Date: Tue, 26 Dec 2023 20:08:10 +0100
User-Agent: Mozilla Thunderbird
To: ffmpeg-devel@ffmpeg.org
References: <20231226162033.782945-1-stefasab@gmail.com>
Content-Language: en-US
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
In-Reply-To: <20231226162033.782945-1-stefasab@gmail.com>
X-TMN: [vMKWMfQv1+riTF/WWD7qdvA1XCJdgGnnnxWlKRH84/k=]
X-ClientProxiedBy: FR0P281CA0161.DEUP281.PROD.OUTLOOK.COM
 (2603:10a6:d10:b3::8) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
 (2603:10a6:20b:541::14)
X-Microsoft-Original-Message-ID: <221ea296-0471-4012-b1c6-13fbaeecd782@outlook.com>
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0076:EE_
X-MS-Office365-Filtering-Correlation-Id: 2487d8e8-2a4b-47bb-2288-08dc0645ca04
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: O90qkXykwq24J8x8iMtLrb9jlJ9xsaFdJ4OQEQbuKGlN4CR1BGL59pse9//vlytpITnb/gDIU6qN+rWWOjFVxnU1VEkvNcX//3kZv+HAlSEYMnigwSEoPzsvSWGAFRiB+zTtzlXJpgi1hJP3dg+YR7wkk6FtjPCc1AAmZq5o38mROM+AUhfHgDBAQjVlb+dByV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?=
 =?utf-8?B?UnhWdjdYYjk5ajFwYmRLSWUweFpLbDZVZURpaUFpTFI2SGl1MzRYRlNtNndu?=
 =?utf-8?B?QU9McC9pemQrcnhxL1Bud0Roa0toVlF2dmZ6bGNhUnVDaVdCemFWUFl5OWNM?=
 =?utf-8?B?aDBpeGVFanFQUXNmOFAzdlVNWEJOMllNdjJ3UTRIdU1Xa1NLKzRleXV6NXhI?=
 =?utf-8?B?TEwraTV5czZ6NFlNeHZlNFE0MW5iVDMwMWxIbzdrVVFTWTlKYktqK1J0UkVV?=
 =?utf-8?B?OUZwNGxaY0xmVld6UFBpK1hZUGZXUnkvMk1mK1pxc1Z1VytxYmhOQ01EYnov?=
 =?utf-8?B?b0R6TUVTTFlFTGFvcGdYMDZraHB2dzZrZzhxcy9rWEpsMzczS3UxU2dCSmIw?=
 =?utf-8?Q?xbSNs0JMgoutlmgzJbxZ?=
X-OriginatorOrg: outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 2487d8e8-2a4b-47bb-2288-08dc0645ca04
X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2023 19:06:39.4625 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P250MB0076
Subject: Re: [FFmpeg-devel] [PATCH] lavfi: add quirc filter
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/AS8P250MB0744898E86189E92404280168F98A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

Stefano Sabatini:
> ---
>  Changelog                |   1 +
>  configure                |   4 +
>  doc/filters.texi         |  35 ++++++++
>  libavfilter/Makefile     |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vf_quirc.c   | 183 +++++++++++++++++++++++++++++++++++++++
>  6 files changed, 225 insertions(+)
>  create mode 100644 libavfilter/vf_quirc.c
> 
> diff --git a/Changelog b/Changelog
> index b483bb9c69..424bfc11af 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -14,6 +14,7 @@ version <next>:
>  - D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
>  - tiltandshift filter
>  - qrencode filter and qrencodesrc source
> +- quirc filter
>  
>  version 6.1:
>  - libaribcaption decoder
> diff --git a/configure b/configure
> index 0b2f4e9792..419ff76bc1 100755
> --- a/configure
> +++ b/configure
> @@ -257,6 +257,7 @@ External library support:
>    --enable-libplacebo      enable libplacebo library [no]
>    --enable-libpulse        enable Pulseaudio input via libpulse [no]
>    --enable-libqrencode     enable QR encode generation via libqrencode [no]
> +  --enable-libquirc        enable QR decoding via libquirc [no]
>    --enable-librabbitmq     enable RabbitMQ library [no]
>    --enable-librav1e        enable AV1 encoding via rav1e [no]
>    --enable-librist         enable RIST via librist [no]
> @@ -1883,6 +1884,7 @@ EXTERNAL_LIBRARY_LIST="
>      libplacebo
>      libpulse
>      libqrencode
> +    libquirc
>      librabbitmq
>      librav1e
>      librist
> @@ -3793,6 +3795,7 @@ ocv_filter_deps="libopencv"
>  openclsrc_filter_deps="opencl"
>  qrencode_filter_deps="libqrencode"
>  qrencodesrc_filter_deps="libqrencode"
> +quirc_filter_deps="libquirc"
>  overlay_opencl_filter_deps="opencl"
>  overlay_qsv_filter_deps="libmfx"
>  overlay_qsv_filter_select="qsvvpp"
> @@ -6845,6 +6848,7 @@ enabled libopus           && {
>  enabled libplacebo        && require_pkg_config libplacebo "libplacebo >= 4.192.0" libplacebo/vulkan.h pl_vulkan_create
>  enabled libpulse          && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new
>  enabled libqrencode       && require_pkg_config libqrencode libqrencode qrencode.h QRcode_encodeString
> +enabled libquirc          && require libquirc quirc.h quirc_decode -lquirc
>  enabled librabbitmq       && require_pkg_config librabbitmq "librabbitmq >= 0.7.1" amqp.h amqp_new_connection
>  enabled librav1e          && require_pkg_config librav1e "rav1e >= 0.5.0" rav1e.h rav1e_context_new
>  enabled librist           && require_pkg_config librist "librist >= 0.2.7" librist/librist.h rist_receiver_create
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 04898ede31..5fbe381d74 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -20368,6 +20368,41 @@ qrencode=text=%@{pts@}
>  
>  @end itemize
>  
> +@section quirc
> +
> +Identify and decode a QR code using the libquirc library (see
> +@url{https://github.com/dlbeer/quirc/}), and print the identified QR codes
> +positions and payload as metadata.
> +
> +To enable the compilation of this filter, you need to configure FFmpeg with with
> +@code{--enable-libquirc}.
> +
> +For each found QR code in the input video, some metadata entries are added with
> +the prefix @var{lavfi.quirc.N}, where @var{N} is the index, starting from 0,
> +associated to the QR code.
> +
> +A description of each metadata value follows:
> +
> +@table @option
> +@item lavfi.quirc.count
> +the number of found QR codes, it is not set in case none was found
> +
> +@item lavfi.quirc.N.x
> +@item lavfi.quirc.N.y
> +the top-left position of the @var{N} QR code
> +
> +@item lavfi.quirc.N.X
> +@item lavfi.quirc.N.Y
> +the bottom-right position of the @var{N} QR code
> +
> +@item lavfi.quirc.N.w
> +@item lavfi.quirc.N.h
> +the size of the @var{N} QR code
> +
> +@item lavfi.quirc.N.payload
> +the payload of the QR code
> +@end table
> +
>  @section random
>  
>  Flush video frames from internal cache of frames into a random order.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 31371ceb1a..f65fb9a5a7 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -437,6 +437,7 @@ OBJS-$(CONFIG_PSEUDOCOLOR_FILTER)            += vf_pseudocolor.o
>  OBJS-$(CONFIG_PSNR_FILTER)                   += vf_psnr.o framesync.o
>  OBJS-$(CONFIG_PULLUP_FILTER)                 += vf_pullup.o
>  OBJS-$(CONFIG_QP_FILTER)                     += vf_qp.o
> +OBJS-$(CONFIG_QUIRC_FILTER)                  += vf_quirc.o
>  OBJS-$(CONFIG_RANDOM_FILTER)                 += vf_random.o
>  OBJS-$(CONFIG_READEIA608_FILTER)             += vf_readeia608.o
>  OBJS-$(CONFIG_READVITC_FILTER)               += vf_readvitc.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 20feb37967..b8570dbab2 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -412,6 +412,7 @@ extern const AVFilter ff_vf_psnr;
>  extern const AVFilter ff_vf_pullup;
>  extern const AVFilter ff_vf_qp;
>  extern const AVFilter ff_vf_qrencode;
> +extern const AVFilter ff_vf_quirc;
>  extern const AVFilter ff_vf_random;
>  extern const AVFilter ff_vf_readeia608;
>  extern const AVFilter ff_vf_readvitc;
> diff --git a/libavfilter/vf_quirc.c b/libavfilter/vf_quirc.c
> new file mode 100644
> index 0000000000..6945a6aa31
> --- /dev/null
> +++ b/libavfilter/vf_quirc.c
> @@ -0,0 +1,183 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file QR decoder video filter
> + *
> + * Use libquirc library to decode the content of QR codes, and put the decoded
> + * content to metadata. See:
> + * https://github.com/dlbeer/quirc
> + */
> +
> +#include "config_components.h"

Unneeded.

> +//#include "libavutil/internal.h"
> +#include "libavutil/opt.h"
> +#include "avfilter.h"
> +#include "formats.h"
> +#include "video.h"
> +#include <quirc.h>
> +
> +typedef struct QuircContext {
> +    const AVClass *class;
> +
> +    struct quirc *quirc;
> +} QuircContext;
> +
> +static const AVOption quirc_options[] = {
> +    { NULL }
> +};

There is no need for empty options (and also no need for an AVClass for
a filter without options).

> +
> +static av_cold int init(AVFilterContext *ctx)
> +{
> +    QuircContext *quirc = ctx->priv;
> +
> +    quirc->quirc = quirc_new();
> +    if (!quirc->quirc) {
> +        return AVERROR(ENOMEM);
> +    }
> +
> +    return 0;
> +}
> +
> +static av_cold void uninit(AVFilterContext *ctx)
> +{
> +    QuircContext *quirc = ctx->priv;
> +
> +    quirc_destroy(quirc->quirc);
> +}
> +
> +static int config_input(AVFilterLink *inlink)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    QuircContext *quirc = ctx->priv;
> +    int err;
> +
> +    err = quirc_resize(quirc->quirc, inlink->w, inlink->h);
> +    if (err == -1) {
> +        return AVERROR(ENOMEM);
> +    }
> +
> +    return 0;
> +}
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +    static const enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
> +    return ff_set_common_formats_from_list(ctx, pix_fmts);
> +}

FILTER_QUERY_FUNC is inappropriate for this.

> +
> +static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    QuircContext *quirc = ctx->priv;
> +    int codes_count;
> +    int i, w, h;
> +    uint8_t *image, *imagep, *srcp;
> +
> +    image = quirc_begin(quirc->quirc, &w, &h);
> +
> +    /* copy input image to quirc buffer */
> +    imagep = image;
> +    srcp = frame->data[0];
> +    for (i = 0; i < inlink->h; i++) {
> +        memcpy(imagep, srcp, w);
> +        imagep += w;
> +        srcp += frame->linesize[0];
> +    }
> +
> +    quirc_end(quirc->quirc);
> +
> +    codes_count = quirc_count(quirc->quirc);
> +    av_log(ctx, AV_LOG_VERBOSE,
> +           "Found count %d codes in image #%ld\n", codes_count, inlink->frame_count_out);
> +
> +    if (codes_count) {
> +        AVDictionary **metadata = &frame->metadata;
> +
> +        av_dict_set_int(metadata, "lavfi.quirc.count", codes_count, 0);
> +
> +        for (i = 0; i < codes_count; i++) {
> +            struct quirc_code code;
> +            struct quirc_data data;
> +            struct quirc_point top_left, bottom_right;
> +            quirc_decode_error_t err;
> +            int w, h;
> +            char metadata_key[64];
> +
> +            quirc_extract(quirc->quirc, i, &code);
> +
> +            err = quirc_decode(&code, &data);
> +            if (err) {
> +                av_log(ctx, AV_LOG_WARNING,
> +                       "Failed to decode image: %s\n", quirc_strerror(err));
> +                continue;
> +            }
> +
> +            top_left = code.corners[0];
> +            bottom_right = code.corners[2];
> +            w = bottom_right.x - top_left.x;
> +            h = bottom_right.y - top_left.y;
> +
> +#define SET_METADATA_I(key_, value_)                                    \
> +            snprintf(metadata_key, sizeof(metadata_key)-1, "lavfi.quirc.%d." #key_, i); \
> +            av_dict_set_int(metadata, metadata_key, value_, AV_DICT_MATCH_CASE)
> +
> +            SET_METADATA_I(x, top_left.x);
> +            SET_METADATA_I(y, top_left.y);
> +            SET_METADATA_I(X, bottom_right.x);
> +            SET_METADATA_I(Y, bottom_right.y);
> +            SET_METADATA_I(w, w);
> +            SET_METADATA_I(h, h);
> +            snprintf(metadata_key, sizeof(metadata_key)-1, "lavfi.quirc.%d.payload", i); \
> +            av_dict_set(metadata, metadata_key, data.payload, 0);
> +
> +            av_log(ctx, AV_LOG_INFO,
> +                   "Found QR code at position %d+%d:%dx%d with payload: %s\n",
> +                   top_left.x, top_left.y, w, h, data.payload);
> +        }
> +    }
> +
> +    return ff_filter_frame(outlink, frame);
> +}
> +
> +AVFILTER_DEFINE_CLASS(quirc);
> +
> +static const AVFilterPad inputs[] = {
> +    {
> +        .name         = "default",
> +        .type         = AVMEDIA_TYPE_VIDEO,
> +        .filter_frame = filter_frame,
> +        .config_props = config_input
> +    },
> +};
> +
> +const AVFilter ff_vf_quirc = {
> +    .name        = "quirc",
> +    .description = NULL_IF_CONFIG_SMALL("Decode and show QR codes content."),
> +    .priv_size   = sizeof(QuircContext),
> +    .priv_class  = &quirc_class,
> +    .init        = init,
> +    .uninit      = uninit,
> +    FILTER_INPUTS(inputs),
> +    FILTER_OUTPUTS(ff_video_default_filterpad),
> +    FILTER_QUERY_FUNC(query_formats),
> +    .flags       = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
> +                   AVFILTER_FLAG_METADATA_ONLY,
> +};
> +

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".