[FFmpeg-devel] [PATCH 06/44] avformat/utils: Move ff_stream_add_bitstream_filter to mux.c
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Sat May 7 14:27:52 EEST 2022
It is muxing-only; in fact, it should be considered part of
the core muxing code.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavformat/flvenc.c | 3 +--
libavformat/internal.h | 11 ----------
libavformat/ivfenc.c | 1 +
libavformat/latmenc.c | 1 +
libavformat/matroskaenc.c | 2 +-
libavformat/mpegtsenc.c | 1 +
libavformat/mux.c | 43 +++++++++++++++++++++++++++++++++++++++
libavformat/mux.h | 11 ++++++++++
libavformat/rawenc.c | 2 +-
libavformat/utils.c | 43 ---------------------------------------
10 files changed, 60 insertions(+), 58 deletions(-)
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 429732297d..4e65ba4066 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -25,13 +25,12 @@
#include "libavutil/avassert.h"
#include "libavutil/mathematics.h"
#include "libavcodec/mpeg4audio.h"
-#include "avio_internal.h"
#include "avio.h"
#include "avc.h"
#include "avformat.h"
#include "flv.h"
#include "internal.h"
-#include "metadata.h"
+#include "mux.h"
#include "libavutil/opt.h"
#include "libavcodec/put_bits.h"
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 5e84942fb9..a40a29c5c0 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -771,17 +771,6 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
*/
int ff_generate_avci_extradata(AVStream *st);
-/**
- * Add a bitstream filter to a stream.
- *
- * @param st output stream to add a filter to
- * @param name the name of the filter to add
- * @param args filter-specific argument string
- * @return >0 on success;
- * AVERROR code on failure
- */
-int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args);
-
/**
* Copy encoding parameters from source to destination stream
*
diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c
index 5aa8bd1257..ed5ec90ce9 100644
--- a/libavformat/ivfenc.c
+++ b/libavformat/ivfenc.c
@@ -19,6 +19,7 @@
*/
#include "avformat.h"
#include "internal.h"
+#include "mux.h"
#include "libavutil/intreadwrite.h"
typedef struct IVFEncContext {
diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c
index 72865c9565..6553c28d9f 100644
--- a/libavformat/latmenc.c
+++ b/libavformat/latmenc.c
@@ -28,6 +28,7 @@
#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
+#include "mux.h"
#include "rawenc.h"
#define MAX_EXTRADATA_SIZE 1024
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3b8ca11f28..4f9e283940 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -21,7 +21,6 @@
#include <stdint.h>
-#include "config.h"
#include "config_components.h"
#include "av1.h"
@@ -35,6 +34,7 @@
#include "internal.h"
#include "isom.h"
#include "matroska.h"
+#include "mux.h"
#include "riff.h"
#include "version.h"
#include "vorbiscomment.h"
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index ead2ca25db..18e8f7e45f 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -34,6 +34,7 @@
#include "avio_internal.h"
#include "internal.h"
#include "mpegts.h"
+#include "mux.h"
#define PCR_TIME_BASE 27000000
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 11b0cb1307..31361f9b46 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1304,6 +1304,49 @@ int av_get_output_timestamp(struct AVFormatContext *s, int stream,
return 0;
}
+int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
+{
+ int ret;
+ const AVBitStreamFilter *bsf;
+ FFStream *const sti = ffstream(st);
+ AVBSFContext *bsfc;
+
+ av_assert0(!sti->bsfc);
+
+ if (!(bsf = av_bsf_get_by_name(name))) {
+ av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
+ return AVERROR_BSF_NOT_FOUND;
+ }
+
+ if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
+ return ret;
+
+ bsfc->time_base_in = st->time_base;
+ if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
+ av_bsf_free(&bsfc);
+ return ret;
+ }
+
+ if (args && bsfc->filter->priv_class) {
+ if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
+ av_bsf_free(&bsfc);
+ return ret;
+ }
+ }
+
+ if ((ret = av_bsf_init(bsfc)) < 0) {
+ av_bsf_free(&bsfc);
+ return ret;
+ }
+
+ sti->bsfc = bsfc;
+
+ av_log(NULL, AV_LOG_VERBOSE,
+ "Automatically inserted bitstream filter '%s'; args='%s'\n",
+ name, args ? args : "");
+ return 1;
+}
+
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
AVFormatContext *src, int interleave)
{
diff --git a/libavformat/mux.h b/libavformat/mux.h
index d1dc2fa2cb..4f6e8a50e5 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -56,6 +56,17 @@ const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
+/**
+ * Add a bitstream filter to a stream.
+ *
+ * @param st output stream to add a filter to
+ * @param name the name of the filter to add
+ * @param args filter-specific argument string
+ * @return >0 on success;
+ * AVERROR code on failure
+ */
+int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args);
+
/**
* Write a packet to another muxer than the one the user originally
* intended. Useful when chaining muxers, where one muxer internally
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index efdfd0b0aa..26099cb1c1 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -26,7 +26,7 @@
#include "avformat.h"
#include "rawenc.h"
-#include "internal.h"
+#include "mux.h"
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
{
diff --git a/libavformat/utils.c b/libavformat/utils.c
index a905838468..fcee417c4e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1776,49 +1776,6 @@ uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
return data;
}
-int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
-{
- int ret;
- const AVBitStreamFilter *bsf;
- FFStream *const sti = ffstream(st);
- AVBSFContext *bsfc;
-
- av_assert0(!sti->bsfc);
-
- if (!(bsf = av_bsf_get_by_name(name))) {
- av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
- return AVERROR_BSF_NOT_FOUND;
- }
-
- if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
- return ret;
-
- bsfc->time_base_in = st->time_base;
- if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
- av_bsf_free(&bsfc);
- return ret;
- }
-
- if (args && bsfc->filter->priv_class) {
- if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
- av_bsf_free(&bsfc);
- return ret;
- }
- }
-
- if ((ret = av_bsf_init(bsfc)) < 0) {
- av_bsf_free(&bsfc);
- return ret;
- }
-
- sti->bsfc = bsfc;
-
- av_log(NULL, AV_LOG_VERBOSE,
- "Automatically inserted bitstream filter '%s'; args='%s'\n",
- name, args ? args : "");
- return 1;
-}
-
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
{
if (!s->oformat)
--
2.32.0
More information about the ffmpeg-devel
mailing list