MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / opt_preset

Function opt_preset

fftools/ffmpeg_opt.c:1108–1165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106}
1107
1108static int opt_preset(void *optctx, const char *opt, const char *arg)
1109{
1110 OptionsContext *o = optctx;
1111 FILE *f=NULL;
1112 char filename[1000], line[1000], tmp_line[1000];
1113 const char *codec_name = NULL;
1114 int ret = 0;
1115 int depth = o->depth;
1116
1117 if (depth > 2) {
1118 av_log(NULL, AV_LOG_ERROR, "too deep recursion\n");
1119 return AVERROR(EINVAL);
1120 }
1121
1122 codec_name = opt_match_per_type_str(&o->codec_names, *opt);
1123
1124 if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
1125 if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
1126 av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
1127 }else
1128 av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
1129 return AVERROR(ENOENT);
1130 }
1131
1132 o->depth ++;
1133 while (fgets(line, sizeof(line), f)) {
1134 char *key = tmp_line, *value, *endptr;
1135
1136 if (strcspn(line, "#\n\r") == 0)
1137 continue;
1138 av_strlcpy(tmp_line, line, sizeof(tmp_line));
1139 if (!av_strtok(key, "=", &value) ||
1140 !av_strtok(value, "\r\n", &endptr)) {
1141 av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
1142 ret = AVERROR(EINVAL);
1143 goto fail;
1144 }
1145 av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
1146
1147 if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
1148 else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
1149 else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
1150 else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
1151 else if ((parse_option(o, key, value, options) < 0) &&
1152 (opt_default_new(o, key, value) < 0)) {
1153 av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
1154 filename, line, key, value);
1155 ret = AVERROR(EINVAL);
1156 goto fail;
1157 }
1158 }
1159
1160fail:
1161 o->depth = depth;
1162 fclose(f);
1163
1164 return ret;
1165}

Callers

nothing calls this directly

Calls 11

av_logFunction · 0.85
opt_match_per_type_strFunction · 0.85
get_preset_fileFunction · 0.85
av_strlcpyFunction · 0.85
av_strtokFunction · 0.85
opt_audio_codecFunction · 0.85
opt_video_codecFunction · 0.85
opt_subtitle_codecFunction · 0.85
opt_data_codecFunction · 0.85
parse_optionFunction · 0.85
opt_default_newFunction · 0.85

Tested by

no test coverage detected