diff options
author | Anton Khirnov <anton@khirnov.net> | 2024-04-04 10:51:53 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-04-09 10:34:18 +0200 |
commit | a4c940c86a46e817eea16d8535db383f9e19c25c (patch) | |
tree | 34184aa49f274d906365e8afedff13db058858f8 /fftools/ffmpeg_mux_init.c | |
parent | a2892dbe06161452ec6592bcdddd0cbe8b0f6780 (diff) | |
download | ffmpeg-a4c940c86a46e817eea16d8535db383f9e19c25c.tar.gz |
fftools/ffmpeg_filter: move most of -apad logic to the muxer
The decision whether -apad actually does anything is made based on muxer
properties, and so more properly belongs there. Filtering code only
receives the result.
Diffstat (limited to 'fftools/ffmpeg_mux_init.c')
-rw-r--r-- | fftools/ffmpeg_mux_init.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6e19b98abd..a483fffa6e 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -828,6 +828,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, static int new_stream_audio(Muxer *mux, const OptionsContext *o, OutputStream *ost) { + MuxStream *ms = ms_from_ost(ost); AVFormatContext *oc = mux->fc; AVStream *st = ost->st; @@ -836,7 +837,6 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, int channels = 0; char *layout = NULL; char *sample_fmt = NULL; - const char *apad = NULL; MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st); if (channels) { @@ -859,12 +859,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st); - MATCH_PER_STREAM_OPT(apad, str, apad, oc, st); - if (apad) { - ost->apad = av_strdup(apad); - if (!ost->apad) - return AVERROR(ENOMEM); - } + MATCH_PER_STREAM_OPT(apad, str, ms->apad, oc, st); } return 0; @@ -1890,6 +1885,33 @@ static int create_streams(Muxer *mux, const OptionsContext *o) } } + // handle -apad + if (mux->of.shortest) { + int have_video = 0; + + for (unsigned i = 0; i < mux->of.nb_streams; i++) + if (mux->of.streams[i]->type == AVMEDIA_TYPE_VIDEO) { + have_video = 1; + break; + } + + for (unsigned i = 0; have_video && i < mux->of.nb_streams; i++) { + MuxStream *ms = ms_from_ost(mux->of.streams[i]); + OutputFilter *ofilter = ms->ost.filter; + + if (ms->ost.type != AVMEDIA_TYPE_AUDIO || !ms->apad || !ofilter) + continue; + + ofilter->apad = av_strdup(ms->apad); + if (!ofilter->apad) + return AVERROR(ENOMEM); + } + } + for (unsigned i = 0; i < mux->of.nb_streams; i++) { + MuxStream *ms = ms_from_ost(mux->of.streams[i]); + ms->apad = NULL; + } + if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->url, 1); av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n"); |