summaryrefslogtreecommitdiff
path: root/fftools/ffmpeg_mux_init.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-04-13 14:22:28 +0200
committerAnton Khirnov <anton@khirnov.net>2023-04-17 12:01:40 +0200
commita34f483291e5e635e55e0d326c23bb8c352852c3 (patch)
tree27c3a3e91bdb705c802f7e0ec85ae73a2ab5dcaa /fftools/ffmpeg_mux_init.c
parenta064aed4c37836468f4156e6b3aaf150a626fa50 (diff)
downloadffmpeg-a34f483291e5e635e55e0d326c23bb8c352852c3.tar.gz
fftools/ffmpeg: add muxer-input codec parameters to OutputStream
It stores codec parameters of the stream submitted to the muxer, which may be different from the codec parameters in AVStream due to bitstream filtering. This avoids the confusing back and forth synchronisation between the encoder, bitstream filters, and the muxer, now information flows only in one direction. It also reduces the need for non-muxing code to access AVStream.
Diffstat (limited to 'fftools/ffmpeg_mux_init.c')
-rw-r--r--fftools/ffmpeg_mux_init.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b53f5d278d..64a3e1ffe5 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -116,19 +116,19 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
if (!codec_name) {
- ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
+ ost->par_in->codec_id = av_guess_codec(s->oformat, NULL, s->url,
NULL, ost->type);
- *enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
+ *enc = avcodec_find_encoder(ost->par_in->codec_id);
if (!*enc) {
av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed "
"Default encoder for format %s (codec %s) is "
"probably disabled. Please choose an encoder manually.\n",
- s->oformat->name, avcodec_get_name(ost->st->codecpar->codec_id));
+ s->oformat->name, avcodec_get_name(ost->par_in->codec_id));
return AVERROR_ENCODER_NOT_FOUND;
}
} else if (strcmp(codec_name, "copy")) {
*enc = find_codec_or_die(ost, codec_name, ost->type, 1);
- ost->st->codecpar->codec_id = (*enc)->id;
+ ost->par_in->codec_id = (*enc)->id;
}
}
@@ -844,7 +844,7 @@ static int streamcopy_init(const Muxer *mux, const OptionsContext *o,
const InputStream *ist = ost->ist;
const InputFile *ifile = input_files[ist->file_index];
- AVCodecParameters *par = ost->st->codecpar;
+ AVCodecParameters *par = ost->par_in;
uint32_t codec_tag = par->codec_tag;
AVCodecContext *codec_ctx = NULL;
@@ -995,6 +995,10 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
ms = mux_stream_alloc(mux, type);
ost = &ms->ost;
+ ost->par_in = avcodec_parameters_alloc();
+ if (!ost->par_in)
+ report_and_exit(AVERROR(ENOMEM));
+
ms->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
if (!ms->muxing_queue)
report_and_exit(AVERROR(ENOMEM));
@@ -1003,6 +1007,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
ost->st = st;
ost->ist = ist;
ost->kf.ref_pts = AV_NOPTS_VALUE;
+ ost->par_in->codec_type = type;
st->codecpar->codec_type = type;
ret = choose_encoder(o, oc, ost, &enc);
@@ -1170,6 +1175,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o,
tag = AV_RL32(buf);
}
ost->st->codecpar->codec_tag = tag;
+ ost->par_in->codec_tag = tag;
if (ost->enc_ctx)
ost->enc_ctx->codec_tag = tag;
}
@@ -1523,8 +1529,8 @@ static void of_add_attachments(Muxer *mux, const OptionsContext *o)
ost = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL);
ost->attachment_filename = o->attachments[i];
- ost->st->codecpar->extradata = attachment;
- ost->st->codecpar->extradata_size = len;
+ ost->par_in->extradata = attachment;
+ ost->par_in->extradata_size = len;
p = strrchr(o->attachments[i], '/');
av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);