summaryrefslogtreecommitdiff
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2012-05-03 23:07:24 +0200
committerClément Bœsch <ubitux@gmail.com>2012-05-04 18:47:50 +0200
commit49df97b282d64a52db5dd628c44ba845d2acf9ae (patch)
treeb148171fb9165350a2faf8653ff613f6d501c488 /ffmpeg.c
parentec271c95794693ce1376a95b0f319e5892460123 (diff)
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).
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 43a1b0a90c..1b2d345641 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -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);
}
}