X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_opt.c;h=ceebcfea5b9a9f1f84c9b6fbc9c607ef36a1abc2;hb=05cf687d130a976d96051f6f6bdb63cf724d3709;hp=a356cadab4dbdd150a6888157e1271f557fe8cca;hpb=4c42c66935a7bdaded8667fa76dc0945ae66e867;p=ffmpeg diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index a356cadab4d..ceebcfea5b9 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -42,6 +42,8 @@ #include "libavutil/pixfmt.h" #include "libavutil/time_internal.h" +#define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass" + #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ {\ int i, ret;\ @@ -1468,6 +1470,40 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in !(ost->logfile_prefix = av_strdup(ost->logfile_prefix))) exit_program(1); + if (do_pass) { + char logfilename[1024]; + FILE *f; + + snprintf(logfilename, sizeof(logfilename), "%s-%d.log", + ost->logfile_prefix ? ost->logfile_prefix : + DEFAULT_PASS_LOGFILENAME_PREFIX, + i); + if (!strcmp(ost->enc->name, "libx264")) { + av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE); + } else { + if (video_enc->flags & CODEC_FLAG_PASS2) { + char *logbuffer = read_file(logfilename); + + if (!logbuffer) { + av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n", + logfilename); + exit_program(1); + } + video_enc->stats_in = logbuffer; + } + if (video_enc->flags & CODEC_FLAG_PASS1) { + f = av_fopen_utf8(logfilename, "wb"); + if (!f) { + av_log(NULL, AV_LOG_FATAL, + "Cannot write log file '%s' for pass-1 encoding: %s\n", + logfilename, strerror(errno)); + exit_program(1); + } + ost->logfile = f; + } + } + } + MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st); if (ost->forced_keyframes) ost->forced_keyframes = av_strdup(ost->forced_keyframes); @@ -1746,8 +1782,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, { OutputStream *ost; - switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads, - ofilter->out_tmp->pad_idx)) { + switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break; case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break; default: @@ -1780,13 +1815,21 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, exit_program(1); } - if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) { - av_log(NULL, AV_LOG_FATAL, "Error configuring filter.\n"); - exit_program(1); - } avfilter_inout_free(&ofilter->out_tmp); } +static int init_complex_filters(void) +{ + int i, ret = 0; + + for (i = 0; i < nb_filtergraphs; i++) { + ret = init_complex_filtergraph(filtergraphs[i]); + if (ret < 0) + return ret; + } + return 0; +} + static int configure_complex_filters(void) { int i, ret = 0; @@ -1809,10 +1852,6 @@ static int open_output_file(OptionsContext *o, const char *filename) AVDictionary *unused_opts = NULL; AVDictionaryEntry *e = NULL; - if (configure_complex_filters() < 0) { - av_log(NULL, AV_LOG_FATAL, "Error configuring filters.\n"); - exit_program(1); - } if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { o->stop_time = INT64_MAX; @@ -1867,8 +1906,7 @@ static int open_output_file(OptionsContext *o, const char *filename) if (!ofilter->out_tmp || ofilter->out_tmp->name) continue; - switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads, - ofilter->out_tmp->pad_idx)) { + switch (ofilter->type) { case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break; case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break; case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break; @@ -2092,7 +2130,7 @@ loop_end: avio_read(pb, attachment, len); ost = new_attachment_stream(o, oc, -1); - ost->stream_copy = 0; + ost->stream_copy = 1; ost->attachment_filename = o->attachments[i]; ost->finished = 1; ost->st->codec->extradata = attachment; @@ -2114,6 +2152,12 @@ loop_end: exit_program(1); } + if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { + av_dump_format(oc, nb_output_files - 1, oc->filename, 1); + av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1); + exit_program(1); + } + /* check if all codec options have been used */ unused_opts = strip_specifiers(o->g->codec_opts); for (i = of->ost_index; i < nb_output_streams; i++) { @@ -2156,6 +2200,17 @@ loop_end: } av_dict_free(&unused_opts); + /* set the encoding/decoding_needed flags */ + for (i = of->ost_index; i < nb_output_streams; i++) { + OutputStream *ost = output_streams[i]; + + ost->encoding_needed = !ost->stream_copy; + if (ost->encoding_needed && ost->source_index >= 0) { + InputStream *ist = input_streams[ost->source_index]; + ist->decoding_needed |= DECODING_FOR_OST; + } + } + /* check filename in case of an image number is expected */ if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { @@ -2869,6 +2924,13 @@ int ffmpeg_parse_options(int argc, char **argv) goto fail; } + /* create the complex filtergraphs */ + ret = init_complex_filters(); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n"); + goto fail; + } + /* open output files */ ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file); if (ret < 0) { @@ -2876,6 +2938,13 @@ int ffmpeg_parse_options(int argc, char **argv) goto fail; } + /* configure the complex filtergraphs */ + ret = configure_complex_filters(); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error configuring complex filters.\n"); + goto fail; + } + fail: uninit_parse_context(&octx); if (ret < 0) {