X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=fftools%2Fffmpeg_opt.c;h=c0b9f023bd64ad6e967e0a4961fab28d98119a83;hb=3749eede66c3774799766b1f246afae8a6ffc9bb;hp=07308ccc8b80c3e7def2278333afdaff9880736b;hpb=81c462ad95f143837a6a21126117515577f0977b;p=ffmpeg diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 07308ccc8b8..c0b9f023bd6 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -55,6 +55,7 @@ static const char *const opt_name_codec_names[] = {"c", "codec", " static const char *const opt_name_audio_channels[] = {"ac", NULL}; static const char *const opt_name_audio_sample_rate[] = {"ar", NULL}; static const char *const opt_name_frame_rates[] = {"r", NULL}; +static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL}; static const char *const opt_name_frame_sizes[] = {"s", NULL}; static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL}; static const char *const opt_name_ts_scale[] = {"itsscale", NULL}; @@ -736,11 +737,11 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar return 0; } -static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder) +static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder) { const AVCodecDescriptor *desc; const char *codec_string = encoder ? "encoder" : "decoder"; - AVCodec *codec; + const AVCodec *codec; codec = encoder ? avcodec_find_encoder_by_name(name) : @@ -765,13 +766,13 @@ static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int e return codec; } -static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st) +static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st) { char *codec_name = NULL; MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); if (codec_name) { - AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); + const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0); st->codecpar->codec_id = codec->id; return codec; } else @@ -1067,7 +1068,7 @@ static int open_input_file(OptionsContext *o, const char *filename) { InputFile *f; AVFormatContext *ic; - AVInputFormat *file_iformat = NULL; + const AVInputFormat *file_iformat = NULL; int err, i, ret; int64_t timestamp; AVDictionary *unused_opts = NULL; @@ -1116,20 +1117,22 @@ static int open_input_file(OptionsContext *o, const char *filename) av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0); } if (o->nb_audio_channels) { + const AVClass *priv_class; /* because we set audio_channels based on both the "ac" and * "channel_layout" options, we need to check that the specified * demuxer actually has the "channels" option before setting it */ - if (file_iformat && file_iformat->priv_class && - av_opt_find(&file_iformat->priv_class, "channels", NULL, 0, + if (file_iformat && (priv_class = file_iformat->priv_class) && + av_opt_find(&priv_class, "channels", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) { av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0); } } if (o->nb_frame_rates) { + const AVClass *priv_class; /* set the format-level framerate option; * this is important for video grabbers, e.g. x11 */ - if (file_iformat && file_iformat->priv_class && - av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0, + if (file_iformat && (priv_class = file_iformat->priv_class) && + av_opt_find(&priv_class, "framerate", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) { av_dict_set(&o->g->format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0); @@ -1279,6 +1282,9 @@ static int open_input_file(OptionsContext *o, const char *filename) f->loop = o->loop; f->duration = 0; f->time_base = (AVRational){ 1, 1 }; + f->pkt = av_packet_alloc(); + if (!f->pkt) + exit_program(1); #if HAVE_THREADS f->thread_queue_size = o->thread_queue_size; #endif @@ -1570,7 +1576,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e 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); + ost->max_muxing_queue_size *= sizeof(ost->pkt); ost->muxing_queue_data_size = 0; @@ -1688,7 +1694,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in AVStream *st; OutputStream *ost; AVCodecContext *video_enc; - char *frame_rate = NULL, *frame_aspect_ratio = NULL; + char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL; ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); st = ost->st; @@ -1699,8 +1705,21 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate); exit_program(1); } - if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH) - av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid output files\n"); + + MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st); + if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) { + av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate); + exit_program(1); + } + + if (frame_rate && max_frame_rate) { + av_log(NULL, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n"); + exit_program(1); + } + + if ((frame_rate || max_frame_rate) && + video_sync_method == VSYNC_PASSTHROUGH) + av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r/-fpsmax can produce invalid output files\n"); MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st); if (frame_aspect_ratio) { @@ -2423,19 +2442,6 @@ loop_end: avio_closep(&pb); } -#if FF_API_LAVF_AVCTX - for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file - AVDictionaryEntry *e; - ost = output_streams[i]; - - if ((ost->stream_copy || ost->attachment_filename) - && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX)) - && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6))) - if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0) - exit_program(1); - } -#endif - if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { av_dump_format(oc, nb_output_files - 1, oc->url, 1); av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1); @@ -3599,6 +3605,9 @@ const OptionDef options[] = { { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) }, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, + { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC | + OPT_OUTPUT, { .off = OFFSET(max_frame_rates) }, + "set max frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", OPT_VIDEO | HAS_ARG | OPT_SUBTITLE | OPT_STRING | OPT_SPEC | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) }, "set frame size (WxH or abbreviation)", "size" },