From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 06CA542A09 for ; Mon, 11 Apr 2022 16:43:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B146268B2B8; Mon, 11 Apr 2022 19:43:31 +0300 (EEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075090.outbound.protection.outlook.com [40.92.75.90]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F93268A43D for ; Mon, 11 Apr 2022 19:43:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iVBVYB5/dxQTypnLtYGvr7o55TUrqvnG51FHZNmXtOngflozWGV06Hd0pfCae2tZJOJpvDdhRN4tFOvplUMLVIRJwrVa3X5hF7za0VW2pKHcW05J/9F5+DBbYQoLlj1gCgjgay3uqPw0AyWF0RLlGlxt4Am9HDeAMb/iHLjF5S+82FpUin7E2uEeBNTb/XqMz0rXwN1/nzrLHPPanSs29Sg8JzHangznVuM/b0c2axJhFFuVsbO+eg7bm4JoKf4FiCn7Kw2BnqYM3qEbu3aRhlyW3hjqtgrR4ToStTfwqv27ymoXvGIsquWlhq+Dfjfg6t/icJ9q4tuzkrIZXUkokw== 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=q3P8ueBmcbEIMh/OMIvgIMgcuNu7jxq7vK/9PYSsb30=; b=jnR6UcKlUFRc7qQ8UMUBtZlLrOvjxfcd+Upx8Muw+NVIUNdj8mOEDWnHbUUGfWwhTtvNcHX1SpWBJYpvn//V7wHrqtlC1Ei027Ywn+8esreq7ZIvco4P/JiM914HDiShPZreuvGbrHlSVCT/g0Z1GKO2xOmzxSupOKgRb1e4z6WRIxT79NDSE4yQGDSeuPR3AeWxXkSDtbkEhYFE1fPgCLvEtXBNGOa1bozNMaISbGGEQmVxn2UNNuI8oTmp35GSYBa/eeC4L1QdJi5+aS5ifNDZqm+cIRe0UHRPgbTRm6X+0bELHRzoevdZd7CgKjsW+Kcmn3hQolWH3oDmNCmMww== 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=q3P8ueBmcbEIMh/OMIvgIMgcuNu7jxq7vK/9PYSsb30=; b=GuyLjlI2lbukR60rbgGGnleD03wc50PK4MQijvagCLGsVOcX+leTKG+zKeeTLiY88n6zRJIjsSG7NwGkrMALPGBfPKNB1HT26EnjlosUx9zWtT01gqN0OysFP6OJ36Jc4bNO1yn0CLQ7cWoKrEzMlMBHpyxDtqeeErRtUxkr8MmEiHJ8xj1jllGC2vn9EEA+agAWpyPJmr4xHGezcfPsU/HWWDKkuH8PsS/CMPGdmZ6TQa0g7uDNPQEYp8RoCdUpD2AaTl3I0g9he79uwrVNc9jLJ0bHqwY4OR0A1vmdbSyi1zZ1u0MFK9n2clUTQH95D74s0eTlIoNz4PkPLYfqww== Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) by AS1PR01MB10127.eurprd01.prod.exchangelabs.com (2603:10a6:20b:47a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19; Mon, 11 Apr 2022 16:43:23 +0000 Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::fcc3:1285:374c:9b2]) by AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::fcc3:1285:374c:9b2%5]) with mapi id 15.20.5144.028; Mon, 11 Apr 2022 16:43:23 +0000 Message-ID: Date: Mon, 11 Apr 2022 18:43:21 +0200 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220411082048.94984-1-onemda@gmail.com> From: Andreas Rheinhardt In-Reply-To: <20220411082048.94984-1-onemda@gmail.com> X-TMN: [jBwKkC7tYmee1xUCuE/MQkjv+Bh3IBBq] X-ClientProxiedBy: ZR0P278CA0015.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::25) To AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) X-Microsoft-Original-Message-ID: <052470f2-90d5-1600-6761-7e6d6a804e5f@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a60a8585-f569-48dc-eb2f-08da1bda64b5 X-MS-TrafficTypeDiagnostic: AS1PR01MB10127:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iDNHGnYEzVsY50RlgZG9tclK5pGFjkSX8oF26846VaFjHBiZA5aShVCQDvOmV2+X1Nsxz6K97IOkMT9nHOVjzQyGsy1NKLVzUMr9QS74NywddtNyP4Ve3Jzprvlh2SiyGd4gmneiAQoSQanskfot914T1esiPbOQndY9eg0fm6sILyUOHY5C7tBQBPs5CkqBGhZhoe1j+vVR8k0rj5to5bfKV9PNO1e2+wrqIoOc1Snm6oImEYIHIrbs3QtEyxGZj8PdzZ8fVVGnJskQwhq+k2BbHBlx6znkCzen6YzxiIJ7S/HVWxFhwFGcfVXlp/XTMmauMA5eK3pVXFUVdXOManmzyKZyFFit9znxSlBtS+ZUCXXCL1dDAgaCjWbvC7QIqI1xPjVOMzo1UmqyG3vwq4l2a4Qfz/H0uqBNFtcAQi4pNauBKpmS94At7tiBJLLHSLlvA8l6PB00LvpgR+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?B?WGc2cEZEMDRtWStPTlJsNStEQ0lSVGhGTlF4RDh0djZZaEtCVXQwQmlQcklP?= =?utf-8?B?VytDZVpiU2JUOWhya09yT2pnRnJlSHJudHpaK2VucnBYbDlXV1V4MTB4VHdH?= =?utf-8?B?Tm1acGRDTHpRdmNGd05UTVRVT3l5TTlva0wzY2RqRkdjSHVkV2gzVFhuaDFC?= =?utf-8?B?dlZPbjNkSFM1V29BYUtma29Nb3lTeUlxOHNXbFJoTVNHdDFHVWgxODdLRlBr?= =?utf-8?B?bVA3K3ZhajhsR1I1MkhyU3VVQXM0WStXcUtUR2k4RFBKa1JqeEo2QjFUMERG?= =?utf-8?B?TmpxWkhheS9TMW52Q1I1RHI2SXoraU13aXM4UzYzMVdCMHZFVnk5MmtUK2sz?= =?utf-8?B?SXpRSHY3QytnPT0=?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a60a8585-f569-48dc-eb2f-08da1bda64b5 X-MS-Exchange-CrossTenant-AuthSource: AS8PR01MB7944.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:43:23.5154 (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: AS1PR01MB10127 Subject: Re: [FFmpeg-devel] [PATCH] avfilter: add feedback video filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Paul B Mahol: > Signed-off-by: Paul B Mahol > --- > doc/filters.texi | 32 ++++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_feedback.c | 306 ++++++++++++++++++++++++++++++++++++++ > 4 files changed, 340 insertions(+) > create mode 100644 libavfilter/vf_feedback.c > > diff --git a/doc/filters.texi b/doc/filters.texi > index ac49092743..612497d865 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -12214,6 +12214,38 @@ fade=t=in:st=5.5:d=0.5 > > @end itemize > > +@section feedback > +Apply feedback video filter. > + > +This filter pass cropped input frames to 2nd output. > +From there it can be filtered with other video filters. > +After filter receives frame from 2nd input, that frame > +is combined on top of original frame from 1st input and passed > +to 1st output. > + > +The typical usage is filter only part of frame. > + > +The filter accepts the following options: > +@table @option > +@item x > +@item y > +Set the top left crop position. > + > +@item w > +@item h > +Set the crop size. > +@end table > + > +@subsection Examples > + > +@itemize > +@item > +Blur only top left rectangular part of size 100x100 of frame with gblur filter. > +@example > +[in][blurin]feedback=x=0:y=0:w=100:h=100[out][blurout];[blurout]gblur[blurin] > +@end example > +@end itemize > + > @section fftdnoiz > Denoise frames using 3D FFT (frequency domain filtering). > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index d69bd59bb6..bdfdfdc04a 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -279,6 +279,7 @@ OBJS-$(CONFIG_ESTDIF_FILTER) += vf_estdif.o > OBJS-$(CONFIG_EXPOSURE_FILTER) += vf_exposure.o > OBJS-$(CONFIG_EXTRACTPLANES_FILTER) += vf_extractplanes.o > OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o > +OBJS-$(CONFIG_FEEDBACK_FILTER) += vf_feedback.o > OBJS-$(CONFIG_FFTDNOIZ_FILTER) += vf_fftdnoiz.o > OBJS-$(CONFIG_FFTFILT_FILTER) += vf_fftfilt.o > OBJS-$(CONFIG_FIELD_FILTER) += vf_field.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c > index abd1fe2367..44fac46521 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -261,6 +261,7 @@ extern const AVFilter ff_vf_estdif; > extern const AVFilter ff_vf_exposure; > extern const AVFilter ff_vf_extractplanes; > extern const AVFilter ff_vf_fade; > +extern const AVFilter ff_vf_feedback; > extern const AVFilter ff_vf_fftdnoiz; > extern const AVFilter ff_vf_fftfilt; > extern const AVFilter ff_vf_field; > diff --git a/libavfilter/vf_feedback.c b/libavfilter/vf_feedback.c > new file mode 100644 > index 0000000000..cf6ef7ef0c > --- /dev/null > +++ b/libavfilter/vf_feedback.c > @@ -0,0 +1,306 @@ > +/* > + * 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 > + * feedback video filter > + */ > + > +#include "libavutil/avstring.h" ? > +#include "libavutil/fifo.h" > +#include "libavutil/imgutils.h" > +#include "libavutil/opt.h" > +#include "libavutil/internal.h" > +#include "avfilter.h" > +#include "filters.h" > +#include "internal.h" > +#include "video.h" > + > +typedef struct FeedbackContext { > + const AVClass *class; > + > + int x, y; > + int w, h; > + > + int max_step[4]; > + int hsub, vsub; > + > + AVFrame *feed; > + > + AVFifo *fifo; > +} FeedbackContext; > + > +static void adjust_pos(AVFilterContext *ctx, FeedbackContext *s) > +{ > + if (s->x + s->w > ctx->inputs[0]->w) > + s->x = ctx->inputs[0]->w - s->w; > + if (s->y + s->h > ctx->inputs[0]->h) > + s->y = ctx->inputs[0]->h - s->h; > +} > + > +static void adjust_parameters(AVFilterContext *ctx, FeedbackContext *s) > +{ > + if (s->x >= ctx->inputs[0]->w) > + s->x = 0; > + if (s->y >= ctx->inputs[0]->h) > + s->y = 0; > + > + if (s->w <= 0) > + s->w = ctx->inputs[0]->w - s->x; > + if (s->h <= 0) > + s->h = ctx->inputs[0]->h - s->y; > + > + if (s->w > ctx->inputs[0]->w) > + s->w = ctx->inputs[0]->w; > + if (s->h > ctx->inputs[0]->h) > + s->h = ctx->inputs[0]->h; > + > + adjust_pos(ctx, s); > +} > + > +static int config_input(AVFilterLink *inlink) > +{ > + AVFilterContext *ctx = inlink->dst; > + const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); > + FeedbackContext *s = ctx->priv; > + > + s->hsub = pix_desc->log2_chroma_w; > + s->vsub = pix_desc->log2_chroma_h; > + > + av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); > + > + adjust_parameters(ctx, s); > + > + ctx->inputs[1]->w = s->w; > + ctx->inputs[1]->h = s->h; > + > + return 0; > +} > + > +static int config_output(AVFilterLink *outlink) > +{ > + AVFilterContext *ctx = outlink->src; > + FeedbackContext *s = ctx->priv; > + > + adjust_parameters(ctx, s); > + > + ctx->outputs[0]->w = ctx->inputs[0]->w; > + ctx->outputs[0]->h = ctx->inputs[0]->h; > + ctx->outputs[1]->w = s->w; > + ctx->outputs[1]->h = s->h; > + > + return 0; > +} > + > +static int query_formats(AVFilterContext *ctx) > +{ > + return ff_set_common_formats(ctx, ff_formats_pixdesc_filter(0, AV_PIX_FMT_FLAG_BITSTREAM | > + AV_PIX_FMT_FLAG_HWACCEL | > + AV_PIX_FMT_FLAG_PAL)); > +} > + > +static int activate(AVFilterContext *ctx) > +{ > + FeedbackContext *s = ctx->priv; > + int status, ret; > + int64_t pts; > + > + adjust_pos(ctx, s); > + > + for (int i = 0; i < ctx->nb_outputs; i++) > + FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx); > + > + ret = ff_inlink_consume_frame(ctx->inputs[1], &s->feed); > + if (ret < 0) > + return ret; > + > + if (ret > 0 && av_fifo_can_read(s->fifo)) { > + AVFrame *src = s->feed; > + AVFrame *dst = NULL; > + > + ret = av_fifo_read(s->fifo, &dst, 1); > + if (!dst || ret < 0) > + return ret; You are never writing NULL to the fifo, so you can't ever get NULL back. And given that you check that you can read, ret < 0 can't happen either. You could also just use "if (ret > 0 && av_fifo_read(s->fifo, &dst, 1) >= 0)" (you need to increase the scope for dst for this). > + > + for (int y = 0; y < src->height; y++) { > + memmove(dst->data[0] + (s->y + y) * dst->linesize[0] + s->x * s->max_step[0], > + src->data[0] + y * src->linesize[0], src->width * s->max_step[0]); > + } > + > + for (int i = 1; i < 3; i ++) { > + if (dst->data[i]) { > + for (int y = 0; y < src->height; y++) { > + memmove(dst->data[i] + ((s->y + y) >> s->vsub) * dst->linesize[i] + ((s->x * s->max_step[i]) >> s->hsub), > + src->data[i] + (y >> s->vsub) * src->linesize[i], (src->width * s->max_step[i]) >> s->hsub); > + } > + } > + } > + > + if (dst->data[3]) { > + for (int y = 0; y < src->height; y++) { > + memmove(dst->data[3] + (s->y + y) * dst->linesize[3] + s->x * s->max_step[3], > + src->data[3] + y * src->linesize[3], src->width * s->max_step[3]); > + } > + } > + > + ret = ff_filter_frame(ctx->outputs[0], dst); > + av_frame_free(&s->feed); > + return ret; > + } > + > + if (!s->feed) { > + AVFrame *in = NULL; > + > + ret = ff_inlink_consume_frame(ctx->inputs[0], &in); > + if (ret < 0) > + return ret; > + > + if (ret > 0) { > + AVFrame *frame; > + > + ret = av_fifo_write(s->fifo, &in, 1); in leaks here on error. > + if (ret < 0) > + return ret; > + > + frame = av_frame_clone(in); > + if (!frame) > + return AVERROR(ENOMEM); > + > + frame->width = s->w; > + frame->height = s->h; > + > + frame->data[0] += s->y * frame->linesize[0]; > + frame->data[0] += s->x * s->max_step[0]; > + > + for (int i = 1; i < 3; i ++) { > + if (frame->data[i]) { > + frame->data[i] += (s->y >> s->vsub) * frame->linesize[i]; > + frame->data[i] += (s->x * s->max_step[i]) >> s->hsub; > + } > + } > + > + if (frame->data[3]) { > + frame->data[3] += s->y * frame->linesize[3]; > + frame->data[3] += s->x * s->max_step[3]; > + } > + > + return ff_filter_frame(ctx->outputs[1], frame); > + } > + } > + > + if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) { > + ff_outlink_set_status(ctx->outputs[0], status, pts); > + ff_outlink_set_status(ctx->outputs[1], status, pts); > + return 0; > + } > + > + if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) { > + ff_outlink_set_status(ctx->outputs[0], status, pts); > + ff_outlink_set_status(ctx->outputs[1], status, pts); > + return 0; > + } > + > + if (!s->feed) { > + if (ff_outlink_frame_wanted(ctx->outputs[0])) { > + ff_inlink_request_frame(ctx->inputs[0]); > + ff_inlink_request_frame(ctx->inputs[1]); > + return 0; > + } > + } > + > + return FFERROR_NOT_READY; > +} > + > +static av_cold int init(AVFilterContext *ctx) > +{ > + FeedbackContext *s = ctx->priv; > + > + s->fifo = av_fifo_alloc2(8, sizeof(AVFrame *), AV_FIFO_FLAG_AUTO_GROW); > + if (!s->fifo) > + return AVERROR(ENOMEM); > + > + return 0; > +} > + > +static av_cold void uninit(AVFilterContext *ctx) > +{ > + FeedbackContext *s = ctx->priv; > + > + for (int n = 0; n < av_fifo_can_read(s->fifo); n++) { This construct is completely wrong: 1. It just crashes in case the fifo has not been allocated (e.g. due to allocation error). 2. It calls av_fifo_can_read() on every iteration of the loop and increments n on every iteration of the loop. But av_fifo_read() in the loop body decrements the number of items one can read by 1, so that one gets a leak as soon as the number of initial items in the fifo is >= 2. Here is a working approach: if (s->fifo) { AVFrame *frame; while (av_fifo_read(s->fifo, &frame, 1) >= 0) av_frame_free(&frame); av_fifo_freep2(&s->fifo); } > + AVFrame *frame = NULL; > + > + av_fifo_read(s->fifo, &frame, 1); > + > + av_frame_free(&frame); > + } > + > + av_fifo_freep2(&s->fifo); > +} > + > +static const AVFilterPad inputs[] = { > + { > + .name = "default", > + .type = AVMEDIA_TYPE_VIDEO, > + .config_props = config_input, > + }, > + { > + .name = "feedin", > + .type = AVMEDIA_TYPE_VIDEO, > + .config_props = config_input, > + }, > +}; > + > +static const AVFilterPad outputs[] = { > + { > + .name = "default", > + .type = AVMEDIA_TYPE_VIDEO, > + .config_props = config_output, > + }, > + { > + .name = "feedout", > + .type = AVMEDIA_TYPE_VIDEO, > + .config_props = config_output, > + }, > +}; > + > +#define OFFSET(x) offsetof(FeedbackContext, x) > +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM) > +#define TFLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM) > + > +static const AVOption feedback_options[] = { > + { "x", "set top left crop position", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, TFLAGS }, > + { "y", "set top left crop position", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, TFLAGS }, > + { "w", "set crop size", OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, > + { "h", "set crop size", OFFSET(h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, > + { NULL } > +}; > + > +AVFILTER_DEFINE_CLASS(feedback); > + > +const AVFilter ff_vf_feedback = { > + .name = "feedback", > + .description = NULL_IF_CONFIG_SMALL("Apply feedback video filter."), > + .priv_class = &feedback_class, > + .priv_size = sizeof(FeedbackContext), > + .activate = activate, > + .init = init, > + .uninit = uninit, > + FILTER_INPUTS(inputs), > + FILTER_OUTPUTS(outputs), > + FILTER_QUERY_FUNC(query_formats), > +}; _______________________________________________ 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".