1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
diff -Naur wargus-2.4.1/wartool.cpp wargus-2.4.1.patched/wartool.cpp
--- wargus-2.4.1/wartool.cpp 2016-11-08 10:26:25.000000000 -0500
+++ wargus-2.4.1.patched/wartool.cpp 2021-11-19 15:04:56.300380502 -0500
@@ -1901,25 +1901,27 @@
int ConvertMusic(void)
{
struct stat st;
- char buf[1024];
+ char buf[8192] = {'\0'};
char *cmd;
+ int cmdlen;
int ret, i;
int count = 0;
for ( i = 0; MusicNames[i]; ++i ) {
- sprintf(buf, "%s/%s/%s.wav", Dir, MUSIC_PATH, MusicNames[i]);
+ snprintf(buf, 4095, "%s/%s/%s.wav", Dir, MUSIC_PATH, MusicNames[i]);
CheckPath(buf);
if (stat(buf, &st))
continue;
- cmd = (char*) calloc(strlen("ffmpeg2theora --optimize \"") + strlen(buf) + strlen("\" -o \"") + strlen(buf) + strlen("\"") + 1, 1);
+ cmdlen = strlen("ffmpeg -y -i \"") + strlen(buf) + strlen("\" \"") + strlen(buf) + strlen("\" ");
+ cmd = (char*) calloc(cmdlen + 1, 1);
if (!cmd) {
fprintf(stderr, "Memory error\n");
exit(-1);
}
- sprintf(cmd, "ffmpeg2theora --optimize \"%s\" -o \"%s/%s/%s.ogg\"", buf, Dir, MUSIC_PATH, MusicNames[i]);
+ snprintf(cmd, cmdlen, "ffmpeg -y -i \"%s\" \"%s/%s/%s.ogg\"", buf, Dir, MUSIC_PATH, MusicNames[i]);
ret = system(cmd);
@@ -1927,7 +1929,7 @@
remove(buf);
if (ret != 0) {
- printf("Can't convert wav sound %s to ogv format. Is ffmpeg2theora installed in PATH?\n", MusicNames[i]);
+ printf("Can't convert wav sound %s to ogg format. Is ffmpeg installed in PATH?\n", MusicNames[i]);
fflush(stdout);
}
@@ -1941,13 +1943,14 @@
if (stat(buf, &st))
continue;
- cmd = (char*) calloc(strlen("ffmpeg2theora --optimize \"") + strlen(buf) + strlen("\" -o \"") + strlen(buf) + strlen("\"") + 1, 1);
+ cmdlen = strlen("ffmpeg -y -i \"") + strlen(buf) + strlen("\" \"") + strlen(buf) + strlen("\" ");
+ cmd = (char*) calloc(cmdlen + 1, 1);
if (!cmd) {
fprintf(stderr, "Memory error\n");
exit(-1);
}
- sprintf(cmd, "ffmpeg2theora --optimize \"%s\" -o \"%s/%s/%s.ogg\"", buf, Dir, MUSIC_PATH, BNEMusicNames[i]);
+ snprintf(cmd, cmdlen, "ffmpeg -y -i \"%s\" \"%s/%s/%s.ogg\"", buf, Dir, MUSIC_PATH, BNEMusicNames[i]);
ret = system(cmd);
@@ -1955,7 +1958,7 @@
remove(buf);
if (ret != 0) {
- printf("Can't convert wav sound %s to ogv format. Is ffmpeg2theora installed in PATH?\n", BNEMusicNames[i]);
+ printf("Can't convert wav sound %s to ogg format. Is ffmpeg installed in PATH?\n", BNEMusicNames[i]);
fflush(stdout);
}
@@ -1979,13 +1982,15 @@
int ConvertVideo(const char* file, int video, bool justconvert = false)
{
unsigned char* vidp;
- char buf[1024];
+ char buf[8192] = {'\0'};
char* cmd;
FILE* f;
size_t l;
int ret;
+ int cmdlen;
+ char outputfile[8192] = {'\0'};
- sprintf(buf,"%s/%s.smk", Dir, file);
+ snprintf(buf,4095,"%s/%s.smk", Dir, file);
CheckPath(buf);
if (justconvert == false) {
vidp = ExtractEntry(ArchiveOffsets[video], &l);
@@ -2005,21 +2010,36 @@
fclose(f);
}
- cmd = (char*) calloc(strlen("ffmpeg2theora --optimize \"") + strlen(buf) + strlen("\" -o \"") + strlen(buf) + strlen("\"") + 1, 1);
+ if (CDType & CD_BNE) {
+ cmdlen = strlen("ffmpeg -y -i \"") + strlen(buf) + strlen("\" -codec:v libtheora -qscale:v 31 -codec:a libvorbis -qscale:a 15 -pix_fmt yuv420p -aspect 4:3 -vf scale=640x0,setsar=1:1 \"") + strlen(buf) + strlen("\" ");
+ } else {
+ cmdlen = strlen("ffmpeg -y -i \"") + strlen(buf) + strlen("\" -codec:v libtheora -qscale:v 31 -codec:a libvorbis -qscale:a 15 -pix_fmt yuv420p \"") + strlen(buf) + strlen("\" ");
+ }
+ cmd = (char*) calloc(cmdlen + 1, 1);
if (!cmd) {
fprintf(stderr, "Memory error\n");
exit(-1);
}
- sprintf(cmd, "ffmpeg2theora --optimize \"%s/%s.smk\" -o \"%s/%s.ogv\"", Dir, file, Dir, file);
-
+ if (CDType & CD_BNE) {
+ snprintf(cmd, cmdlen, "ffmpeg -y -i \"%s/%s.smk\" -codec:v libtheora -qscale:v 31 -codec:a libvorbis -qscale:a 15 -pix_fmt yuv420p -aspect 4:3 -vf scale=640:0,setsar=1:1 \"%s/%s.ogv\"", Dir, file, Dir, file);
+ } else {
+ snprintf(cmd, cmdlen, "ffmpeg -y -i \"%s/%s.smk\" -codec:v libtheora -qscale:v 31 -codec:a libvorbis -qscale:a 15 -pix_fmt yuv420p \"%s/%s.ogv\"", Dir, file, Dir, file);
+ }
+ printf("%s\n", cmd);
ret = system(cmd);
free(cmd);
remove(buf);
if (ret != 0) {
- printf("Can't convert video %s to ogv format. Is ffmpeg2theora installed in PATH?\n", file);
+ sprintf(outputfile, "%s/%s.ogv", Dir, file);
+#ifdef WIN32
+ _unlink(outputfile);
+#else
+ unlink(outputfile);
+#endif
+ printf("Can't convert video %s to ogv format. Is ffmpeg installed in PATH?\n", file);
fflush(stdout);
return ret;
}
|