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 BC4214A962 for ; Mon, 6 May 2024 06:05:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D39D68D62F; Mon, 6 May 2024 09:05:46 +0300 (EEST) Received: from mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C6F0468D583 for ; Mon, 6 May 2024 09:05:39 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marcusspencer.xyz; s=protonmail; t=1714975538; x=1715234738; bh=cd+dkz59z9YMwCoXiTr8Kk213pLvIuluGY+7DsDn6JE=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=jQnXWEXZvM4UPfYs2gB/qaGykzI1Wmoashdq703B/pjZyblBM9qJvmpaLHJgHlWFX j/S1/cHGCgV9b49MFBewcFfJ6HILO/4/UPmSpZ9mxZajZW6b5qaB6R8ZmIK963xQ5z KrkKLyR708b6Bcsw3wcEjIMWoFWp5sk89V/x/ddZlnZfqrrPJ5Qi4Oa0C1noFHNrQ4 piw1JqHFdwE6mnZQvPPKJouL9ERlRsWQhgkBhbUcgKC02Z9rbJeKuctS7gzZd3SJkh Nkrbe33XatmSNXxNhDyEikK2gCJRcbhkHDpw5M2Ld1ABYIRScUn3f1qHRB+noOsMme AVODIMRRt0Z2w== Date: Mon, 06 May 2024 06:05:34 +0000 To: FFmpeg development discussions and patches From: marcus Message-ID: <2aDytgKK-LTr1PKxuztMmyhXpSr6Rv5_VgQLZYWLCh6zc_6kv5_ZPimw2dybXo5kPCzfHJwjnanKa-c6txY0DN4Zw-pRBXex7nUUaUJIy1U=@marcusspencer.xyz> In-Reply-To: References: <20240506053219.216068-1-marcus@marcusspencer.xyz> Feedback-ID: 34157397:user:proton X-Pm-Message-ID: 700d9e43b8de98c18b592c3283be02cf11ead8e4 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 1/2] avcodec/bsf: add datamosh bitstream 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: I realized that my git history change failed which intended to retroactively fix issue #1 when the fix got added in the 2nd patch. Be careful when changing git history. On Monday, May 6th, 2024 at 12:47 AM, Andreas Rheinhardt wrote: > > > Marcus B Spencer: > > > Has an option called "target". > > > > For a positive target, drop the nth keyframe. > > For a nonpositive target, allow the first n keyframe(s) and drop the remainder. > > > > Its primary purpose is for datamoshing, but it can also be used for dropping parts of audio. > > > > Signed-off-by: Marcus B Spencer marcus@marcusspencer.xyz > > --- > > libavcodec/bitstream_filters.c | 1 + > > libavcodec/bsf/Makefile | 1 + > > libavcodec/bsf/datamosh.c | 88 ++++++++++++++++++++++++++++++++++ > > 3 files changed, 90 insertions(+) > > create mode 100644 libavcodec/bsf/datamosh.c > > > > diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c > > index 12860c332b..cde6090c77 100644 > > --- a/libavcodec/bitstream_filters.c > > +++ b/libavcodec/bitstream_filters.c > > @@ -29,6 +29,7 @@ extern const FFBitStreamFilter ff_av1_frame_merge_bsf; > > extern const FFBitStreamFilter ff_av1_frame_split_bsf; > > extern const FFBitStreamFilter ff_av1_metadata_bsf; > > extern const FFBitStreamFilter ff_chomp_bsf; > > +extern const FFBitStreamFilter ff_datamosh_bsf; > > extern const FFBitStreamFilter ff_dump_extradata_bsf; > > extern const FFBitStreamFilter ff_dca_core_bsf; > > extern const FFBitStreamFilter ff_dts2pts_bsf; > > diff --git a/libavcodec/bsf/Makefile b/libavcodec/bsf/Makefile > > index fb70ad0c21..ad3b870d12 100644 > > --- a/libavcodec/bsf/Makefile > > +++ b/libavcodec/bsf/Makefile > > @@ -6,6 +6,7 @@ OBJS-$(CONFIG_AV1_FRAME_MERGE_BSF) += bsf/av1_frame_merge.o > > OBJS-$(CONFIG_AV1_FRAME_SPLIT_BSF) += bsf/av1_frame_split.o > > OBJS-$(CONFIG_AV1_METADATA_BSF) += bsf/av1_metadata.o > > OBJS-$(CONFIG_CHOMP_BSF) += bsf/chomp.o > > +OBJS-$(CONFIG_DATAMOSH_BSF) += bsf/datamosh.o > > OBJS-$(CONFIG_DCA_CORE_BSF) += bsf/dca_core.o > > OBJS-$(CONFIG_DTS2PTS_BSF) += bsf/dts2pts.o > > OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += bsf/dump_extradata.o > > diff --git a/libavcodec/bsf/datamosh.c b/libavcodec/bsf/datamosh.c > > new file mode 100644 > > index 0000000000..8314a4efc8 > > --- /dev/null > > +++ b/libavcodec/bsf/datamosh.c > > @@ -0,0 +1,88 @@ > > +/* > > + * Copyright (c) 2024 Marcus B Spencer marcus@marcusspencer.xyz > > + * > > + * 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 > > + */ > > + > > +#include > > + > > +#include "bsf.h" > > +#include "bsf_internal.h" > > + > > +#include "libavutil/opt.h" > > + > > +typedef struct { > > + const AVClass *class; > > + > > + int target, i; > > +} DatamoshContext; > > + > > +static int datamosh_init(AVBSFContext *ctx) > > +{ > > + DatamoshContext *s = ctx->priv_data; > > + > > + s->i = 0; > > + > > + return 0; > > +} > > + > > +static int datamosh(AVBSFContext *ctx, AVPacket *pkt) > > +{ > > + DatamoshContext *s = ctx->priv_data; > > + bool key; > > + int ret; > > + > > + ret = ff_bsf_get_packet_ref(ctx, pkt); > > + if (ret < 0) > > + return ret; > > + > > + key = pkt->flags & AV_PKT_FLAG_KEY; > > + if (key) > > + ++s->i; > > + > > + if (s->target < 1) { > > + if (s->i <= -s->target) > > + return 0; > > + else if (key) { > > + av_packet_unref(pkt); > > + return AVERROR(EAGAIN); > > + } > > + } > > + > > + if (key && s->i == s->target) { > > + av_packet_unref(pkt); > > + return AVERROR(EAGAIN); > > + } > > + > > + return 0; > > +} > > + > > + > > +#define OFFSET(x) offsetof(DatamoshContext, x) > > +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_BSF_PARAM) > > + > > +static const AVOption options[] = { > > + { "target", NULL, OFFSET(target), AV_OPT_TYPE_INT, { .i64 = 0 }, -INT_MAX, INT_MAX, FLAGS }, > > + { NULL }, > > +}; > > + > > +static const AVClass datamosh_class = { > > + .class_name = "datamosh", > > + .item_name = av_default_item_name, > > + .option = options, > > + .version = LIBAVUTIL_VERSION_INT, > > +}; > > > 1. This won't compile, as you only add the FFBitStreamFilter in the > second patch. > 2. Look at the noise bsf. > > - Andreas > > _______________________________________________ > 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". _______________________________________________ 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".