Skip to content

Commit ac3e461

Browse files
committed
fftools/ffmpeg_opt: factor manually mapping streams out of open_output_file()
1 parent 7531959 commit ac3e461

File tree

1 file changed

+81
-76
lines changed

1 file changed

+81
-76
lines changed

fftools/ffmpeg_opt.c

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,13 +2632,91 @@ static void map_auto_data(OutputFile *of, AVFormatContext *oc,
26322632
}
26332633
}
26342634

2635+
static void map_manual(OutputFile *of, AVFormatContext *oc,
2636+
OptionsContext *o, const StreamMap *map)
2637+
{
2638+
InputStream *ist;
2639+
OutputStream *ost;
2640+
2641+
if (map->disabled)
2642+
return;
2643+
2644+
if (map->linklabel) {
2645+
FilterGraph *fg;
2646+
OutputFilter *ofilter = NULL;
2647+
int j, k;
2648+
2649+
for (j = 0; j < nb_filtergraphs; j++) {
2650+
fg = filtergraphs[j];
2651+
for (k = 0; k < fg->nb_outputs; k++) {
2652+
AVFilterInOut *out = fg->outputs[k]->out_tmp;
2653+
if (out && !strcmp(out->name, map->linklabel)) {
2654+
ofilter = fg->outputs[k];
2655+
goto loop_end;
2656+
}
2657+
}
2658+
}
2659+
loop_end:
2660+
if (!ofilter) {
2661+
av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2662+
"in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2663+
exit_program(1);
2664+
}
2665+
init_output_filter(ofilter, o, oc);
2666+
} else {
2667+
int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2668+
2669+
ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2670+
if (ist->user_set_discard == AVDISCARD_ALL) {
2671+
av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2672+
map->file_index, map->stream_index);
2673+
exit_program(1);
2674+
}
2675+
if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
2676+
return;
2677+
if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2678+
return;
2679+
if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2680+
return;
2681+
if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2682+
return;
2683+
2684+
ost = NULL;
2685+
switch (ist->st->codecpar->codec_type) {
2686+
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2687+
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2688+
case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2689+
case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2690+
case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2691+
case AVMEDIA_TYPE_UNKNOWN:
2692+
if (copy_unknown_streams) {
2693+
ost = new_unknown_stream (o, oc, src_idx);
2694+
break;
2695+
}
2696+
default:
2697+
av_log(NULL, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
2698+
"Cannot map stream #%d:%d - unsupported type.\n",
2699+
map->file_index, map->stream_index);
2700+
if (!ignore_unknown_streams) {
2701+
av_log(NULL, AV_LOG_FATAL,
2702+
"If you want unsupported types ignored instead "
2703+
"of failing, please use the -ignore_unknown option\n"
2704+
"If you want them copied, please use -copy_unknown\n");
2705+
exit_program(1);
2706+
}
2707+
}
2708+
if (ost)
2709+
ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2710+
+ map->sync_stream_index];
2711+
}
2712+
}
2713+
26352714
static int open_output_file(OptionsContext *o, const char *filename)
26362715
{
26372716
AVFormatContext *oc;
26382717
int i, j, err;
26392718
OutputFile *of;
26402719
OutputStream *ost;
2641-
InputStream *ist;
26422720
AVDictionary *unused_opts = NULL, *format_opts = NULL;
26432721
const AVDictionaryEntry *e = NULL;
26442722

@@ -2718,81 +2796,8 @@ static int open_output_file(OptionsContext *o, const char *filename)
27182796
if (!o->data_disable)
27192797
map_auto_data(of, oc, o);
27202798
} else {
2721-
for (i = 0; i < o->nb_stream_maps; i++) {
2722-
StreamMap *map = &o->stream_maps[i];
2723-
2724-
if (map->disabled)
2725-
continue;
2726-
2727-
if (map->linklabel) {
2728-
FilterGraph *fg;
2729-
OutputFilter *ofilter = NULL;
2730-
int j, k;
2731-
2732-
for (j = 0; j < nb_filtergraphs; j++) {
2733-
fg = filtergraphs[j];
2734-
for (k = 0; k < fg->nb_outputs; k++) {
2735-
AVFilterInOut *out = fg->outputs[k]->out_tmp;
2736-
if (out && !strcmp(out->name, map->linklabel)) {
2737-
ofilter = fg->outputs[k];
2738-
goto loop_end;
2739-
}
2740-
}
2741-
}
2742-
loop_end:
2743-
if (!ofilter) {
2744-
av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2745-
"in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2746-
exit_program(1);
2747-
}
2748-
init_output_filter(ofilter, o, oc);
2749-
} else {
2750-
int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2751-
2752-
ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2753-
if (ist->user_set_discard == AVDISCARD_ALL) {
2754-
av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2755-
map->file_index, map->stream_index);
2756-
exit_program(1);
2757-
}
2758-
if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
2759-
continue;
2760-
if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2761-
continue;
2762-
if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2763-
continue;
2764-
if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2765-
continue;
2766-
2767-
ost = NULL;
2768-
switch (ist->st->codecpar->codec_type) {
2769-
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2770-
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2771-
case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2772-
case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2773-
case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2774-
case AVMEDIA_TYPE_UNKNOWN:
2775-
if (copy_unknown_streams) {
2776-
ost = new_unknown_stream (o, oc, src_idx);
2777-
break;
2778-
}
2779-
default:
2780-
av_log(NULL, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
2781-
"Cannot map stream #%d:%d - unsupported type.\n",
2782-
map->file_index, map->stream_index);
2783-
if (!ignore_unknown_streams) {
2784-
av_log(NULL, AV_LOG_FATAL,
2785-
"If you want unsupported types ignored instead "
2786-
"of failing, please use the -ignore_unknown option\n"
2787-
"If you want them copied, please use -copy_unknown\n");
2788-
exit_program(1);
2789-
}
2790-
}
2791-
if (ost)
2792-
ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2793-
+ map->sync_stream_index];
2794-
}
2795-
}
2799+
for (int i = 0; i < o->nb_stream_maps; i++)
2800+
map_manual(of, oc, o, &o->stream_maps[i]);
27962801
}
27972802

27982803
/* handle attached files */

0 commit comments

Comments
 (0)