mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-01 10:11:01 +00:00
ffmpeg: store value of -filter and -filter_script per-stream option in OutputStream struct
Avoid the need for multiple potentially inconsistent access operations, slightly factorize code.
This commit is contained in:
parent
ef8f293472
commit
0f8bdfe3e8
2
ffmpeg.h
2
ffmpeg.h
@ -357,6 +357,8 @@ typedef struct OutputStream {
|
|||||||
|
|
||||||
OutputFilter *filter;
|
OutputFilter *filter;
|
||||||
char *avfilter;
|
char *avfilter;
|
||||||
|
char *filters; ///< filtergraph associated to the -filter option
|
||||||
|
char *filters_script; ///< filtergraph script associated to the -filter_script option
|
||||||
|
|
||||||
int64_t sws_flags;
|
int64_t sws_flags;
|
||||||
AVDictionary *opts;
|
AVDictionary *opts;
|
||||||
|
41
ffmpeg_opt.c
41
ffmpeg_opt.c
@ -1151,21 +1151,17 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
|
|||||||
OutputStream *ost)
|
OutputStream *ost)
|
||||||
{
|
{
|
||||||
AVStream *st = ost->st;
|
AVStream *st = ost->st;
|
||||||
char *filter = NULL, *filter_script = NULL;
|
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, st);
|
if (ost->filters_script && ost->filters) {
|
||||||
MATCH_PER_STREAM_OPT(filters, str, filter, oc, st);
|
|
||||||
|
|
||||||
if (filter_script && filter) {
|
|
||||||
av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
|
av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
|
||||||
"output stream #%d:%d.\n", nb_output_files, st->index);
|
"output stream #%d:%d.\n", nb_output_files, st->index);
|
||||||
exit_program(1);
|
exit_program(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_script)
|
if (ost->filters_script)
|
||||||
return read_file(filter_script);
|
return read_file(ost->filters_script);
|
||||||
else if (filter)
|
else if (ost->filters)
|
||||||
return av_strdup(filter);
|
return av_strdup(ost->filters);
|
||||||
|
|
||||||
return av_strdup(st->codec->codec_type == AVMEDIA_TYPE_VIDEO ?
|
return av_strdup(st->codec->codec_type == AVMEDIA_TYPE_VIDEO ?
|
||||||
"null" : "anull");
|
"null" : "anull");
|
||||||
@ -1174,16 +1170,13 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
|
|||||||
static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
|
static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
|
||||||
const OutputStream *ost, enum AVMediaType type)
|
const OutputStream *ost, enum AVMediaType type)
|
||||||
{
|
{
|
||||||
char *filter_script = NULL, *filter = NULL;
|
if (ost->filters_script || ost->filters) {
|
||||||
MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, ost->st);
|
|
||||||
MATCH_PER_STREAM_OPT(filters, str, filter, oc, ost->st);
|
|
||||||
if (filter_script || filter) {
|
|
||||||
av_log(NULL, AV_LOG_ERROR,
|
av_log(NULL, AV_LOG_ERROR,
|
||||||
"Filtergraph '%s' or filter_script '%s' was defined for %s output stream "
|
"Filtergraph '%s' or filter_script '%s' was defined for %s output stream "
|
||||||
"%d:%d but codec copy was selected.\n"
|
"%d:%d but codec copy was selected.\n"
|
||||||
"Filtering and streamcopy cannot be used together.\n",
|
"Filtering and streamcopy cannot be used together.\n",
|
||||||
(char *)av_x_if_null(filter, "(none)"),
|
(char *)av_x_if_null(ost->filters, "(none)"),
|
||||||
(char *)av_x_if_null(filter_script, "(none)"),
|
(char *)av_x_if_null(ost->filters_script, "(none)"),
|
||||||
av_get_media_type_string(type),
|
av_get_media_type_string(type),
|
||||||
ost->file_index, ost->index);
|
ost->file_index, ost->index);
|
||||||
exit_program(1);
|
exit_program(1);
|
||||||
@ -1218,6 +1211,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
|
|||||||
ost->frame_aspect_ratio = q;
|
ost->frame_aspect_ratio = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
|
||||||
|
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
|
||||||
|
|
||||||
if (!ost->stream_copy) {
|
if (!ost->stream_copy) {
|
||||||
const char *p = NULL;
|
const char *p = NULL;
|
||||||
char *frame_size = NULL;
|
char *frame_size = NULL;
|
||||||
@ -1349,6 +1345,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
|
|||||||
audio_enc = st->codec;
|
audio_enc = st->codec;
|
||||||
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
|
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||||
|
|
||||||
|
MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
|
||||||
|
MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
|
||||||
|
|
||||||
if (!ost->stream_copy) {
|
if (!ost->stream_copy) {
|
||||||
char *sample_fmt = NULL;
|
char *sample_fmt = NULL;
|
||||||
|
|
||||||
@ -1573,21 +1572,15 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
|
|||||||
exit_program(1);
|
exit_program(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ost->avfilter) {
|
if (ost->avfilter && (ost->filters || ost->filters_script)) {
|
||||||
char *filter_script = NULL, *filter = NULL;
|
|
||||||
MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, ost->st);
|
|
||||||
MATCH_PER_STREAM_OPT(filters, str, filter, oc, ost->st);
|
|
||||||
|
|
||||||
if (filter || filter_script) {
|
|
||||||
av_log(NULL, AV_LOG_ERROR,
|
av_log(NULL, AV_LOG_ERROR,
|
||||||
"Filter graph '%s' or filter script '%s' was specified through the -filter/-filter_script/-vf/-af option "
|
"Filter graph '%s' or filter script '%s' was specified through the -filter/-filter_script/-vf/-af option "
|
||||||
"for output stream %d:%d, which is fed from a complex filtergraph.\n"
|
"for output stream %d:%d, which is fed from a complex filtergraph.\n"
|
||||||
"-filter/-filter_script and -filter_complex cannot be used together for the same stream.\n",
|
"-filter/-filter_script and -filter_complex cannot be used together for the same stream.\n",
|
||||||
(char *)av_x_if_null(filter, "(none)"),
|
(char *)av_x_if_null(ost->filters, "(none)"),
|
||||||
(char *)av_x_if_null(filter_script, "(none)"),
|
(char *)av_x_if_null(ost->filters_script, "(none)"),
|
||||||
ost->file_index, ost->index);
|
ost->file_index, ost->index);
|
||||||
exit_program(1);
|
exit_program(1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) {
|
if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user