12
typedef struct FFArgs{
17
static FFArgs ffargs[1000];
18
static int nffargs = 0;
21
* exit with error code 1
23
static void error_exit(const char *msg){
24
fprintf(stderr, "E: %s\n", msg);
31
static void print_credits(int argc, char *argv[]){
32
printf("%s version %s\n", PACKAGE, VERSION);
33
printf("Usage: %s [OPTIONS] -- PRESET INFILE OUTFILE\n", argv[0]);
40
static void ffargs_set(const char *name, const char *value, int force){
41
/* check the length */
42
if(strlen(name) >= sizeof(ffargs[0].name))
43
error_exit("too long argument name detected");
44
if(strlen(value) >= sizeof(ffargs[0].value))
45
error_exit("too long argument value detected");
46
/* check if this argument is already added or not */
48
for(int i=0; i<nffargs; i++){
49
if(strcmp(ffargs[i].name, name) == 0){
59
if(index >= sizeof(ffargs))
60
error_exit("too match arguments specified");
62
strcpy(ffargs[index].name, name);
63
strcpy(ffargs[index].value, value);
66
static int preset_read(char *filename){
71
f = fopen(filename, "r");
75
if(fscanf(f, "%999[^\n]\n", line) != 1)
76
error_exit("too match characters in one line");
79
if(sscanf(line, "%999[^=]=%999[^\n]\n", name, value) != 2)
80
error_exit("invalid syntax");
81
ffargs_set(name, value, FALSE);
90
int main(int argc, char *argv[]){
92
print_credits(argc, argv);
96
for(int i=0; i<argc; i++){
97
if(strcmp(argv[i], "--") == 0){
101
if(argv[i][0] == '-'){
104
/* argument without value */
105
if(argv[i+1][0] == '-'){
106
ffargs_set(argv[i]+1, "", TRUE);
108
ffargs_set(argv[i]+1, argv[i+1], TRUE);
114
error_exit("'--' was not found");
116
/* read from preset files */
118
if(extras + 3 > argc)
119
error_exit("OUTFILE is not specified");
121
/* current directory */
123
getcwd(cwd, sizeof(cwd));
124
snprintf(filename, sizeof(filename), "%s/%s.ffpreset", cwd, argv[extras]);
125
if(preset_read(filename)) break;
126
/* $HOME/.ffpreset/PRESET.ffpreset */
127
snprintf(filename, sizeof(filename), "%s/%s.ffpreset", getenv("HOME"), argv[extras]);
128
if(preset_read(filename)) break;
130
snprintf(filename, sizeof(filename), "%s/%s/%s.ffpreset", DATADIR, PACKAGE, argv[extras]);
131
if(preset_read(filename)) break;
133
error_exit("preset file not found");
136
/* output configuration */
138
snprintf(cmd, sizeof(cmd), "ffmpeg -i \"%s\"", argv[extras+1]);
139
for(int i=0; i<nffargs; i++){
142
snprintf(cmd, sizeof(cmd), "%s -%s %s", tmp, ffargs[i].name, ffargs[i].value);
147
snprintf(cmd, sizeof(cmd), "%s \"%s\"", tmp, argv[extras+2]);
149
printf("Executing:\n%s\n", cmd);