aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/opus_metadata_bsf.c
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2020-05-03 21:17:33 +0100
committerLynne <dev@lynne.ee>2020-05-05 22:25:33 +0100
commitbdd57e2a371f70ee75f70bfde5a9a162c76b48ba (patch)
tree854b328a682423c450c9b563fc1a203db6b290a5 /libavcodec/opus_metadata_bsf.c
parent30f5d6751047bbe8974f016c9745da9cd2daa3fc (diff)
downloadffmpeg-bdd57e2a371f70ee75f70bfde5a9a162c76b48ba.tar.gz
lavc/bsf: add an Opus metadata bitstream filter
The only adjustable field is the gain. Some ripping/transcoding programs have started to use it.
Diffstat (limited to 'libavcodec/opus_metadata_bsf.c')
-rw-r--r--libavcodec/opus_metadata_bsf.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/libavcodec/opus_metadata_bsf.c b/libavcodec/opus_metadata_bsf.c
new file mode 100644
index 0000000000..867ad830d3
--- /dev/null
+++ b/libavcodec/opus_metadata_bsf.c
@@ -0,0 +1,72 @@
+/*
+ * 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 "bsf.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+typedef struct OpusBSFContext {
+ const AVClass *class;
+ int gain;
+} OpusBSFContext;
+
+static int opus_metadata_filter(AVBSFContext *bsfc, AVPacket *pkt)
+{
+ return ff_bsf_get_packet_ref(bsfc, pkt);
+}
+
+static int opus_metadata_init(AVBSFContext *bsfc)
+{
+ OpusBSFContext *s = bsfc->priv_data;
+
+ if (bsfc->par_out->extradata_size < 19)
+ return AVERROR_INVALIDDATA;
+
+ AV_WL16(bsfc->par_out->extradata + 16, s->gain);
+
+ return 0;
+}
+
+#define OFFSET(x) offsetof(OpusBSFContext, x)
+#define FLAGS (AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_BSF_PARAM)
+static const AVOption opus_metadata_options[] = {
+ { "gain", "Gain, actual amplification is pow(10, gain/(20.0*256))", OFFSET(gain),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, -(INT16_MAX + 1), INT16_MAX, .flags = FLAGS },
+
+ { NULL },
+};
+
+static const AVClass opus_metadata_class = {
+ .class_name = "opus_metadata_bsf",
+ .item_name = av_default_item_name,
+ .option = opus_metadata_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const enum AVCodecID codec_ids[] = {
+ AV_CODEC_ID_OPUS, AV_CODEC_ID_NONE,
+};
+
+const AVBitStreamFilter ff_opus_metadata_bsf = {
+ .name = "opus_metadata",
+ .priv_data_size = sizeof(OpusBSFContext),
+ .priv_class = &opus_metadata_class,
+ .init = &opus_metadata_init,
+ .filter = &opus_metadata_filter,
+ .codec_ids = codec_ids,
+};