History

avconv: add presets

Alexandra Khirnova committed 15 years ago

Commit 3ec34461 parent 51369f22 files · +93 −1Browse files

Unified · Split

2 files
  1. avconv.c +76 −1
  2. doc/avconv.texi +17 −0
avconv.c+76−1
@@ -326,6 +326,8 @@ typedef struct OptionsContext { · 325 unmodified lines
326326 int nb_inter_matrices;
327327 SpecifierOpt *top_field_first;
328328 int nb_top_field_first;
329+ SpecifierOpt *presets;
330+ int nb_presets;
329331 #if CONFIG_AVFILTER
330332 SpecifierOpt *filters;
331333 int nb_filters;
@@ -2966,15 +2968,62 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, · 2634 unmodified lines
29662968 }
29672969 }
29682970
2971+static uint8_t *get_line(AVIOContext *s)
2972+{
2973+ AVIOContext *line;
2974+ uint8_t *buf;
2975+ char c;
2976+
2977+ if (avio_open_dyn_buf(&line) < 0) {
2978+ av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
2979+ exit_program(1);
2980+ }
2981+
2982+ while ((c = avio_r8(s)) && c != '\n')
2983+ avio_w8(line, c);
2984+ avio_w8(line, 0);
2985+ avio_close_dyn_buf(line, &buf);
2986+
2987+ return buf;
2988+}
2989+
2990+static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
2991+{
2992+ int i, ret = 1;
2993+ char filename[1000];
2994+ const char *base[3] = { getenv("AVCONV_DATADIR"),
2995+ getenv("HOME"),
2996+ AVCONV_DATADIR,
2997+ };
2998+
2999+ for (i = 0; i < FF_ARRAY_ELEMS(base) && ret; i++) {
3000+ if (!base[i])
3001+ continue;
3002+ if (codec_name) {
3003+ snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
3004+ i != 1 ? "" : "/.avconv", codec_name, preset_name);
3005+ ret = avio_open(s, filename, AVIO_FLAG_READ);
3006+ }
3007+ if (ret) {
3008+ snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
3009+ i != 1 ? "" : "/.avconv", preset_name);
3010+ ret = avio_open(s, filename, AVIO_FLAG_READ);
3011+ }
3012+ }
3013+ return ret;
3014+}
3015+
29693016 static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
29703017 {
29713018 OutputStream *ost;
29723019 AVStream *st = av_new_stream(oc, oc->nb_streams < o->nb_streamid_map ? o->streamid_map[oc->nb_streams] : 0);
2973− int idx = oc->nb_streams - 1;
3020+ int idx = oc->nb_streams - 1, ret = 0;
29743021 int64_t max_frames = INT64_MAX;
29753022 char *bsf = NULL, *next, *codec_tag = NULL;
29763023 AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
29773024 double qscale = -1;
3025+ char *buf = NULL, *arg = NULL, *preset = NULL;
3026+ AVIOContext *s = NULL;
29783027
29793028 if (!st) {
29803029 av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
@@ -2996,6 +3045,31 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 15 unmodified lines
29963045 avcodec_get_context_defaults3(st->codec, ost->enc);
29973046 st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy
29983047
3048+ MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
3049+ if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
3050+ do {
3051+ buf = get_line(s);
3052+ if (!buf[0] || buf[0] == '#') {
3053+ av_free(buf);
3054+ continue;
3055+ }
3056+ if (!(arg = strchr(buf, '='))) {
3057+ av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
3058+ exit_program(1);
3059+ }
3060+ *arg++ = 0;
3061+ av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
3062+ av_free(buf);
3063+ } while (!s->eof_reached);
3064+ avio_close(s);
3065+ }
3066+ if (ret) {
3067+ av_log(NULL, AV_LOG_FATAL,
3068+ "Preset %s specified for stream %d:%d, but could not be opened.\n",
3069+ preset, ost->file_index, ost->index);
3070+ exit_program(1);
3071+ }
3072+
29993073 MATCH_PER_STREAM_OPT(max_frames, i64, max_frames, oc, st);
30003074 ost->max_frames = max_frames;
30013075
@@ -3906,6 +3980,7 @@ static const OptionDef options[] = { · 904 unmodified lines
39063980 { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
39073981 { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
39083982 { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
3983+ { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },
39093984 { "map", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map}, "set input stream mapping", "file.stream[:syncfile.syncstream]" },
39103985 { "map_metadata", HAS_ARG | OPT_EXPERT | OPT_FUNC2, {(void*)opt_map_metadata}, "set metadata information of outfile from infile",
39113986 "outfile[,metadata]:infile[,metadata]" },
doc/avconv.texi+17−0
@@ -186,6 +186,8 @@ codec-dependent. · 185 unmodified lines
186186 @var{filter_graph} is a description of the filter graph to apply to
187187 the stream. Use @code{-filters} to show all the available filters
188188 (including also sources and sinks).
189+@item -pre[:@var{stream_specifier}] @var{preset_name} (@emph{output,per-stream})
190+Specify the preset for matching stream(s).
189191
190192 @item -stats (@emph{global})
191193 Print encoding progress/statistics. On by default.
@@ -770,6 +772,21 @@ quality). · 578 unmodified lines
770772 @chapter Examples
771773 @c man begin EXAMPLES
772774
775+@section Preset files
776+
777+A preset file contains a sequence of @var{option=value} pairs, one for
778+each line, specifying a sequence of options which can be specified also on
779+the command line. Lines starting with the hash ('#') character are ignored and
780+are used to provide comments. Empty lines are also ignored. Check the
781+@file{ffpresets} directory in the Libav source tree for examples.
782+
783+Preset files are specified with the @code{pre} option, this option takes a
784+preset name as input. Avconv searches for a file named @var{preset_name}.avpreset in
785+the directories @file{$AVCONV_DATADIR} (if set), and @file{$HOME/.avconv}, and in
786+the data directory defined at configuration time (usually @file{$PREFIX/share/avconv})
787+in that order. For example, if the argument is @code{libx264-max}, it will
788+search for the file @file{libx264-max.avpreset}.
789+
773790 @section Video and Audio grabbing
774791
775792 If you specify the input format and device then avconv can grab video

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t