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).
This commit is contained in:
Clément Bœsch 2012-05-03 23:07:24 +02:00
parent ec271c9579
commit 49df97b282
1 changed files with 17 additions and 16 deletions

View File

@ -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)
{
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 :
*opt == 'a' ? audio_codec_name :
subtitle_codec_name;
@ -5541,25 +5541,26 @@ static int opt_preset(OptionsContext *o, const char *opt, const char *arg)
exit_program(1);
}
while(!feof(f)){
int e= fscanf(f, "%999[^\n]\n", line) - 1;
if(line[0] == '#' && !e)
while (fgets(line, sizeof(line), f)) {
char *key = tmp_line, *value, *endptr;
if (strcspn(line, "#\n\r") == 0)
continue;
e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
if(e){
strcpy(tmp_line, line);
if (!av_strtok(key, "=", &value) ||
!av_strtok(value, "\r\n", &endptr)) {
av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
exit_program(1);
}
if(!strcmp(tmp, "acodec")){
opt_audio_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "vcodec")){
opt_video_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "scodec")){
opt_subtitle_codec(o, tmp, tmp2);
}else if(!strcmp(tmp, "dcodec")){
opt_data_codec(o, tmp, tmp2);
}else if(opt_default(tmp, tmp2) < 0){
av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
else if (opt_default(key, value) < 0) {
av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
filename, line, key, value);
exit_program(1);
}
}