From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/2] avcodec/bsf: add datamosh bitstream filter
Date: Mon, 6 May 2024 07:47:16 +0200
Message-ID: <GV1P250MB0737B398D0DB22C6A8FCA2868F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20240506053219.216068-1-marcus@marcusspencer.xyz>
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 <stdbool.h>
> +
> +#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".
next prev parent reply other threads:[~2024-05-06 5:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 5:32 Marcus B Spencer
2024-05-06 5:32 ` [FFmpeg-devel] [PATCH 2/2] Changelog: add datamosh bitstream filter entry Marcus B Spencer
2024-05-06 5:47 ` marcus
2024-05-06 5:47 ` Andreas Rheinhardt [this message]
2024-05-06 6:05 ` [FFmpeg-devel] [PATCH 1/2] avcodec/bsf: add datamosh bitstream filter marcus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=GV1P250MB0737B398D0DB22C6A8FCA2868F1C2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git