forked from FFmpeg/FFmpeg
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.
This commit is contained in:
parent
a2892dbe06
commit
a4c940c86a
5 changed files with 36 additions and 22 deletions
|
@ -320,6 +320,8 @@ typedef struct OutputFilter {
|
||||||
* this stores the output linklabel, if any */
|
* this stores the output linklabel, if any */
|
||||||
uint8_t *linklabel;
|
uint8_t *linklabel;
|
||||||
|
|
||||||
|
char *apad;
|
||||||
|
|
||||||
enum AVMediaType type;
|
enum AVMediaType type;
|
||||||
|
|
||||||
atomic_uint_least64_t nb_frames_dup;
|
atomic_uint_least64_t nb_frames_dup;
|
||||||
|
@ -581,7 +583,6 @@ typedef struct OutputStream {
|
||||||
OutputFilter *filter;
|
OutputFilter *filter;
|
||||||
|
|
||||||
AVDictionary *encoder_opts;
|
AVDictionary *encoder_opts;
|
||||||
char *apad;
|
|
||||||
|
|
||||||
char *attachment_filename;
|
char *attachment_filename;
|
||||||
|
|
||||||
|
|
|
@ -969,6 +969,7 @@ void fg_free(FilterGraph **pfg)
|
||||||
|
|
||||||
av_freep(&ofilter->linklabel);
|
av_freep(&ofilter->linklabel);
|
||||||
av_freep(&ofilter->name);
|
av_freep(&ofilter->name);
|
||||||
|
av_freep(&ofilter->apad);
|
||||||
av_freep(&ofp->name);
|
av_freep(&ofp->name);
|
||||||
av_channel_layout_uninit(&ofp->ch_layout);
|
av_channel_layout_uninit(&ofp->ch_layout);
|
||||||
av_freep(&fg->outputs[j]);
|
av_freep(&fg->outputs[j]);
|
||||||
|
@ -1430,8 +1431,6 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
|
||||||
OutputFilter *ofilter, AVFilterInOut *out)
|
OutputFilter *ofilter, AVFilterInOut *out)
|
||||||
{
|
{
|
||||||
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
|
OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);
|
||||||
OutputStream *ost = ofilter->ost;
|
|
||||||
OutputFile *of = ost->file;
|
|
||||||
AVFilterContext *last_filter = out->filter_ctx;
|
AVFilterContext *last_filter = out->filter_ctx;
|
||||||
int pad_idx = out->pad_idx;
|
int pad_idx = out->pad_idx;
|
||||||
AVBPrint args;
|
AVBPrint args;
|
||||||
|
@ -1493,17 +1492,8 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
|
||||||
pad_idx = 0;
|
pad_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ost->apad && of->shortest) {
|
if (ofilter->apad)
|
||||||
int i;
|
AUTO_INSERT_FILTER("-apad", "apad", ofilter->apad);
|
||||||
|
|
||||||
for (i = 0; i < of->nb_streams; i++)
|
|
||||||
if (of->streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (i < of->nb_streams) {
|
|
||||||
AUTO_INSERT_FILTER("-apad", "apad", ost->apad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "trim for output %s", ofp->name);
|
snprintf(name, sizeof(name), "trim for output %s", ofp->name);
|
||||||
ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
|
ret = insert_trim(ofp->trim_start_us, ofp->trim_duration_us,
|
||||||
|
|
|
@ -815,7 +815,6 @@ static void ost_free(OutputStream **post)
|
||||||
av_expr_free(ost->kf.pexpr);
|
av_expr_free(ost->kf.pexpr);
|
||||||
|
|
||||||
av_freep(&ost->logfile_prefix);
|
av_freep(&ost->logfile_prefix);
|
||||||
av_freep(&ost->apad);
|
|
||||||
|
|
||||||
av_freep(&ost->attachment_filename);
|
av_freep(&ost->attachment_filename);
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,8 @@ typedef struct MuxStream {
|
||||||
#if FFMPEG_OPT_VSYNC_DROP
|
#if FFMPEG_OPT_VSYNC_DROP
|
||||||
int ts_drop;
|
int ts_drop;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *apad;
|
||||||
} MuxStream;
|
} MuxStream;
|
||||||
|
|
||||||
typedef struct Muxer {
|
typedef struct Muxer {
|
||||||
|
|
|
@ -828,6 +828,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
|
||||||
static int new_stream_audio(Muxer *mux, const OptionsContext *o,
|
static int new_stream_audio(Muxer *mux, const OptionsContext *o,
|
||||||
OutputStream *ost)
|
OutputStream *ost)
|
||||||
{
|
{
|
||||||
|
MuxStream *ms = ms_from_ost(ost);
|
||||||
AVFormatContext *oc = mux->fc;
|
AVFormatContext *oc = mux->fc;
|
||||||
AVStream *st = ost->st;
|
AVStream *st = ost->st;
|
||||||
|
|
||||||
|
@ -836,7 +837,6 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
|
||||||
int channels = 0;
|
int channels = 0;
|
||||||
char *layout = NULL;
|
char *layout = NULL;
|
||||||
char *sample_fmt = NULL;
|
char *sample_fmt = NULL;
|
||||||
const char *apad = NULL;
|
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
|
MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
|
||||||
if (channels) {
|
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(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(apad, str, apad, oc, st);
|
MATCH_PER_STREAM_OPT(apad, str, ms->apad, oc, st);
|
||||||
if (apad) {
|
|
||||||
ost->apad = av_strdup(apad);
|
|
||||||
if (!ost->apad)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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)) {
|
if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
|
||||||
av_dump_format(oc, nb_output_files - 1, oc->url, 1);
|
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");
|
av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue