Browse code

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.

Stefano Sabatini authored on 2013/11/04 18:02:27
Showing 2 changed files
... ...
@@ -357,6 +357,8 @@ typedef struct OutputStream {
357 357
 
358 358
     OutputFilter *filter;
359 359
     char *avfilter;
360
+    char *filters;         ///< filtergraph associated to the -filter option
361
+    char *filters_script;  ///< filtergraph script associated to the -filter_script option
360 362
 
361 363
     int64_t sws_flags;
362 364
     AVDictionary *opts;
... ...
@@ -1151,21 +1151,17 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
1151 1151
                              OutputStream *ost)
1152 1152
 {
1153 1153
     AVStream *st = ost->st;
1154
-    char *filter = NULL, *filter_script = NULL;
1155 1154
 
1156
-    MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, st);
1157
-    MATCH_PER_STREAM_OPT(filters, str, filter, oc, st);
1158
-
1159
-    if (filter_script && filter) {
1155
+    if (ost->filters_script && ost->filters) {
1160 1156
         av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1161 1157
                "output stream #%d:%d.\n", nb_output_files, st->index);
1162 1158
         exit_program(1);
1163 1159
     }
1164 1160
 
1165
-    if (filter_script)
1166
-        return read_file(filter_script);
1167
-    else if (filter)
1168
-        return av_strdup(filter);
1161
+    if (ost->filters_script)
1162
+        return read_file(ost->filters_script);
1163
+    else if (ost->filters)
1164
+        return av_strdup(ost->filters);
1169 1165
 
1170 1166
     return av_strdup(st->codec->codec_type == AVMEDIA_TYPE_VIDEO ?
1171 1167
                      "null" : "anull");
... ...
@@ -1174,16 +1170,13 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
1174 1174
 static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
1175 1175
                                      const OutputStream *ost, enum AVMediaType type)
1176 1176
 {
1177
-    char *filter_script = NULL, *filter = NULL;
1178
-    MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, ost->st);
1179
-    MATCH_PER_STREAM_OPT(filters,        str, filter,        oc, ost->st);
1180
-    if (filter_script || filter) {
1177
+    if (ost->filters_script || ost->filters) {
1181 1178
         av_log(NULL, AV_LOG_ERROR,
1182 1179
                "Filtergraph '%s' or filter_script '%s' was defined for %s output stream "
1183 1180
                "%d:%d but codec copy was selected.\n"
1184 1181
                "Filtering and streamcopy cannot be used together.\n",
1185
-               (char *)av_x_if_null(filter, "(none)"),
1186
-               (char *)av_x_if_null(filter_script, "(none)"),
1182
+               (char *)av_x_if_null(ost->filters, "(none)"),
1183
+               (char *)av_x_if_null(ost->filters_script, "(none)"),
1187 1184
                av_get_media_type_string(type),
1188 1185
                ost->file_index, ost->index);
1189 1186
         exit_program(1);
... ...
@@ -1218,6 +1211,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
1218 1218
         ost->frame_aspect_ratio = q;
1219 1219
     }
1220 1220
 
1221
+    MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1222
+    MATCH_PER_STREAM_OPT(filters,        str, ost->filters,        oc, st);
1223
+
1221 1224
     if (!ost->stream_copy) {
1222 1225
         const char *p = NULL;
1223 1226
         char *frame_size = NULL;
... ...
@@ -1349,6 +1345,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
1349 1349
     audio_enc = st->codec;
1350 1350
     audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1351 1351
 
1352
+    MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1353
+    MATCH_PER_STREAM_OPT(filters,        str, ost->filters,        oc, st);
1354
+
1352 1355
     if (!ost->stream_copy) {
1353 1356
         char *sample_fmt = NULL;
1354 1357
 
... ...
@@ -1573,21 +1572,15 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
1573 1573
         exit_program(1);
1574 1574
     }
1575 1575
 
1576
-    if (ost->avfilter) {
1577
-        char *filter_script = NULL, *filter = NULL;
1578
-        MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, ost->st);
1579
-        MATCH_PER_STREAM_OPT(filters, str, filter, oc, ost->st);
1580
-
1581
-        if (filter || filter_script) {
1576
+    if (ost->avfilter && (ost->filters || ost->filters_script)) {
1582 1577
             av_log(NULL, AV_LOG_ERROR,
1583 1578
                    "Filter graph '%s' or filter script '%s' was specified through the -filter/-filter_script/-vf/-af option "
1584 1579
                    "for output stream %d:%d, which is fed from a complex filtergraph.\n"
1585 1580
                    "-filter/-filter_script and -filter_complex cannot be used together for the same stream.\n",
1586
-                   (char *)av_x_if_null(filter, "(none)"),
1587
-                   (char *)av_x_if_null(filter_script, "(none)"),
1581
+                   (char *)av_x_if_null(ost->filters, "(none)"),
1582
+                   (char *)av_x_if_null(ost->filters_script, "(none)"),
1588 1583
                    ost->file_index, ost->index);
1589 1584
             exit_program(1);
1590
-        }
1591 1585
     }
1592 1586
 
1593 1587
     if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) {