X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=avconv_opt.c;h=ba37a3a31d6811dcb8fa28a488904d8355a4a8f4;hb=6354957a95022864746180525680cca872ab0e0a;hp=2a4f71a6ff613051387696f9237ee3cca2aaeef8;hpb=5fa255b65c7887cc913f097aed1b581fbf1a8745;p=ffmpeg diff --git a/avconv_opt.c b/avconv_opt.c index 2a4f71a6ff6..ba37a3a31d6 100644 --- a/avconv_opt.c +++ b/avconv_opt.c @@ -553,10 +553,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: - ist->resample_height = ist->dec_ctx->height; - ist->resample_width = ist->dec_ctx->width; - ist->resample_pix_fmt = ist->dec_ctx->pix_fmt; - MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st); if (framerate && av_parse_video_rate(&ist->framerate, framerate) < 0) { @@ -616,12 +612,6 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) break; case AVMEDIA_TYPE_AUDIO: guess_input_channel_layout(ist); - - ist->resample_sample_fmt = ist->dec_ctx->sample_fmt; - ist->resample_sample_rate = ist->dec_ctx->sample_rate; - ist->resample_channels = ist->dec_ctx->channels; - ist->resample_channel_layout = ist->dec_ctx->channel_layout; - break; case AVMEDIA_TYPE_DATA: case AVMEDIA_TYPE_SUBTITLE: @@ -1035,26 +1025,54 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st); while (bsfs && *bsfs) { const AVBitStreamFilter *filter; - char *bsf; + const char *bsf, *bsf_options_str, *bsf_name; + AVDictionary *bsf_options = NULL; - bsf = av_get_token(&bsfs, ","); + bsf = bsf_options_str = av_get_token(&bsfs, ","); if (!bsf) exit_program(1); + bsf_name = av_get_token(&bsf_options_str, "="); + if (!bsf_name) + exit_program(1); - filter = av_bsf_get_by_name(bsf); + filter = av_bsf_get_by_name(bsf_name); if (!filter) { - av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf); + av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name); exit_program(1); } + if (*bsf_options_str++) { + ret = av_dict_parse_string(&bsf_options, bsf_options_str, "=", ":", 0); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name); + exit_program(1); + } + } av_freep(&bsf); - ost->bitstream_filters = av_realloc_array(ost->bitstream_filters, - ost->nb_bitstream_filters + 1, - sizeof(*ost->bitstream_filters)); - if (!ost->bitstream_filters) + ost->bsf_ctx = av_realloc_array(ost->bsf_ctx, + ost->nb_bitstream_filters + 1, + sizeof(*ost->bsf_ctx)); + if (!ost->bsf_ctx) exit_program(1); - ost->bitstream_filters[ost->nb_bitstream_filters++] = filter; + ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n"); + exit_program(1); + } + ost->nb_bitstream_filters++; + + if (bsf_options) { + ret = av_opt_set_dict(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, &bsf_options); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error setting options for bitstream filter %s\n", bsf_name); + exit_program(1); + } + assert_avoptions(bsf_options); + av_dict_free(&bsf_options); + } + av_freep(&bsf_name); + if (*bsfs) bsfs++; } @@ -1073,6 +1091,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } + ost->max_muxing_queue_size = 128; + MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st); + ost->max_muxing_queue_size *= sizeof(AVPacket); + if (oc->oformat->flags & AVFMT_GLOBALHEADER) ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; @@ -1083,6 +1105,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->pix_fmts[0] = ost->pix_fmts[1] = AV_PIX_FMT_NONE; ost->last_mux_dts = AV_NOPTS_VALUE; + ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); + if (!ost->muxing_queue) + exit_program(1); + return ost; } @@ -1465,6 +1491,7 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, ost->filter = ofilter; ofilter->ost = ost; + ofilter->format = -1; if (ost->stream_copy) { av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, " @@ -1488,17 +1515,6 @@ static int init_complex_filters(void) return 0; } -static int configure_complex_filters(void) -{ - int i, ret = 0; - - for (i = 0; i < nb_filtergraphs; i++) - if (!filtergraph_is_simple(filtergraphs[i]) && - (ret = configure_filtergraph(filtergraphs[i])) < 0) - return ret; - return 0; -} - static int open_output_file(OptionsContext *o, const char *filename) { AVFormatContext *oc; @@ -1809,6 +1825,67 @@ loop_end: } } + /* set the filter output constraints */ + if (ost->filter) { + OutputFilter *f = ost->filter; + int count; + switch (ost->enc_ctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + f->frame_rate = ost->frame_rate; + f->width = ost->enc_ctx->width; + f->height = ost->enc_ctx->height; + if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { + f->format = ost->enc_ctx->pix_fmt; + } else if (ost->enc->pix_fmts) { + count = 0; + while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE) + count++; + f->formats = av_mallocz_array(count + 1, sizeof(*f->formats)); + if (!f->formats) + exit_program(1); + memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats)); + } + break; + case AVMEDIA_TYPE_AUDIO: + if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) { + f->format = ost->enc_ctx->sample_fmt; + } else if (ost->enc->sample_fmts) { + count = 0; + while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE) + count++; + f->formats = av_mallocz_array(count + 1, sizeof(*f->formats)); + if (!f->formats) + exit_program(1); + memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats)); + } + if (ost->enc_ctx->sample_rate) { + f->sample_rate = ost->enc_ctx->sample_rate; + } else if (ost->enc->supported_samplerates) { + count = 0; + while (ost->enc->supported_samplerates[count]) + count++; + f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates)); + if (!f->sample_rates) + exit_program(1); + memcpy(f->sample_rates, ost->enc->supported_samplerates, + (count + 1) * sizeof(*f->sample_rates)); + } + if (ost->enc_ctx->channels) { + f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels); + } else if (ost->enc->channel_layouts) { + count = 0; + while (ost->enc->channel_layouts[count]) + count++; + f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts)); + if (!f->channel_layouts) + exit_program(1); + memcpy(f->channel_layouts, ost->enc->channel_layouts, + (count + 1) * sizeof(*f->channel_layouts)); + } + break; + } + } + } /* check filename in case of an image number is expected */ @@ -2385,13 +2462,6 @@ int avconv_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) { @@ -2648,6 +2718,9 @@ const OptionDef options[] = { { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) }, "A comma-separated list of bitstream filters", "bitstream_filters" }, + { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) }, + "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" }, + /* data codec support */ { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec }, "force data codec ('copy' to copy stream)", "codec" },