Commit 49df97b2 authored by Clément Bœsch's avatar Clément Bœsch

ffmpeg: stronger ffpresets parsing.

This fixes at least issues with empty lines, and also allows CRLF lines
(in case a user makes its own preset on a MS plateform).
parent ec271c95
...@@ -5528,7 +5528,7 @@ static int opt_data_frames(OptionsContext *o, const char *opt, const char *arg) ...@@ -5528,7 +5528,7 @@ static int opt_data_frames(OptionsContext *o, const char *opt, const char *arg)
static int opt_preset(OptionsContext *o, const char *opt, const char *arg) static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
{ {
FILE *f=NULL; FILE *f=NULL;
char filename[1000], tmp[1000], tmp2[1000], line[1000]; char filename[1000], line[1000], tmp_line[1000];
const char *codec_name = *opt == 'v' ? video_codec_name : const char *codec_name = *opt == 'v' ? video_codec_name :
*opt == 'a' ? audio_codec_name : *opt == 'a' ? audio_codec_name :
subtitle_codec_name; subtitle_codec_name;
...@@ -5541,25 +5541,26 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg) ...@@ -5541,25 +5541,26 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
exit_program(1); exit_program(1);
} }
while(!feof(f)){ while (fgets(line, sizeof(line), f)) {
int e= fscanf(f, "%999[^\n]\n", line) - 1; char *key = tmp_line, *value, *endptr;
if(line[0] == '#' && !e)
if (strcspn(line, "#\n\r") == 0)
continue; continue;
e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2; strcpy(tmp_line, line);
if(e){ if (!av_strtok(key, "=", &value) ||
!av_strtok(value, "\r\n", &endptr)) {
av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line); av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
exit_program(1); exit_program(1);
} }
if(!strcmp(tmp, "acodec")){ av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
opt_audio_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "vcodec")){ if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
opt_video_codec(o, tmp, tmp2); else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
}else if(!strcmp(tmp, "scodec")){ else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
opt_subtitle_codec(o, tmp, tmp2); else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
}else if(!strcmp(tmp, "dcodec")){ else if (opt_default(key, value) < 0) {
opt_data_codec(o, tmp, tmp2); av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
}else if(opt_default(tmp, tmp2) < 0){ filename, line, key, value);
av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
exit_program(1); exit_program(1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment