2 * VFW Compressor Settings Tool
4 * Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
6 * Official Website : http://oss.netfarm.it/mplayer-win32.php
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /* On MinGW compile with: gcc vfw2menc.c -o vfw2menc.exe -lwinmm -lole32 */
24 /* Using Wine: winegcc vfw2menc.c -o vfw2menc -lwinmm -lole32 */
25 /* MSVC requires getopt.c and getopt.h available at the original website */
28 #define _CRT_SECURE_NO_DEPRECATE
29 #pragma warning(disable: 4996)
42 #define BAIL(msg) { printf("%s: %s\n", argv[0], msg); ret = -1; goto cleanup; }
45 UINT uDriverSignature
;
46 HINSTANCE hDriverModule
;
47 DRIVERPROC DriverProc
;
63 static int save_settings(HDRVR hDriver
, const char *filename
)
66 DWORD cb
= (DWORD
) SendDriverMessage(hDriver
, ICM_GETSTATE
, 0, 0);
71 printf("ICM_GETSTATE returned 0 size\n");
75 pv
= (char *) malloc(cb
);
76 if (SendDriverMessage(hDriver
, ICM_GETSTATE
, (LPARAM
) pv
, (LPARAM
) &cb
) != ICERR_OK
)
78 printf("ICM_GETSTATE failed\n");
83 fd
= fopen(filename
, "wb");
86 printf("Cannot open file %s for writing\n", filename
);
91 if (fwrite(pv
, cb
, 1, fd
) != 1)
93 printf("fwrite() failed on %s\n", filename
);
103 static int load_settings(HDRVR hDriver
, const char *filename
)
109 if (stat(filename
, &info
) < 0)
111 printf("stat() on %s failed\n", filename
);
115 pv
= (char *) malloc(info
.st_size
);
116 fd
= fopen(filename
, "rb");
120 printf("Cannot open file %s for reading\n", filename
);
125 if (fread(pv
, info
.st_size
, 1, fd
) != 1)
127 printf("fread() failed on %s\n", filename
);
133 if (!SendDriverMessage(hDriver
, ICM_SETSTATE
, (LPARAM
) pv
, (LPARAM
) info
.st_size
))
135 printf("ICM_SETSTATE failed\n");
143 static struct option long_options
[] =
145 { "help", no_argument
, NULL
, 'h' },
146 { "driver", required_argument
, NULL
, 'd' },
147 { "fourcc", required_argument
, NULL
, 'f' },
148 { "save", required_argument
, NULL
, 's' },
149 { "check", required_argument
, NULL
, 'c' },
150 { "view", no_argument
, NULL
, 'v' },
154 static void help(const char *progname
)
156 printf("VFW to mencoder v"VERSION
" - Copyright 2007 - Gianluigi Tiesi <sherpya@netfarm.it>\n");
157 printf("This program is Free Software\n\n");
158 printf("Usage: %s\n", progname
);
159 printf(" -h|--help - displays this help\n");
160 printf(" -d|--driver filename - dll or drv to load\n");
161 printf(" -f|--fourcc fourcc - fourcc of selected driver (look at codecs.conf)\n");
162 printf(" -s|--save filename - save settings to file\n");
163 printf(" -c|--check filename - load and show setting in filename\n");
164 printf(" -v|--view - displays the config dialog and do nothing\n");
165 printf("\nExamples:\n");
166 printf(" %s -f VP62 -d vp6vfw.dll -s firstpass.mcf\n", progname
);
167 printf(" %s -f VP62 -d vp6vfw.dll -c firstpass.mcf\n", progname
);
168 printf(" %s -f VP62 -d vp6vfw.dll -v\n", progname
);
169 printf("\nIf the driver dialog doesn't work, you can try without specifing a fourcc,\n");
170 printf("but the compdata file will not work with mencoder.\n");
171 printf("Driver option is required and you must specify at least -s, -c -o -v\n");
172 printf("Usage with mencoder -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=settings.mcf\n");
175 int main(int argc
, char *argv
[])
179 char *filename
= NULL
;
180 unsigned char mode
= 0;
186 wchar_t drvfile
[MAX_PATH
];
187 HDRVR hDriver
= NULL
;
189 int c
= -1, long_options_index
= -1;
198 while ((c
= getopt_long(argc
, argv
, "hd:f:s:c:v", long_options
, &long_options_index
)) != -1)
207 driver
= strdup(optarg
);
210 fourcc
= strdup(optarg
);
211 if (strlen(optarg
) != 4) BAIL("Fourcc must be exactly 4 chars");
214 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
215 filename
= strdup(optarg
);
219 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
220 filename
= strdup(optarg
);
224 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
228 printf("Wrong arguments!\n");
234 if (!(argc
== optind
) && (mode
!= MODE_NONE
) &&
235 driver
&& (filename
|| (mode
== MODE_VIEW
)))
241 if (!MultiByteToWideChar(CP_ACP
, 0, driver
, -1, drvfile
, MAX_PATH
))
242 BAIL("MultiByteToWideChar() failed\n");
244 if (fourcc
) memcpy(&dwFCC
, fourcc
, 4);
245 memset(&icopen
, 0, sizeof(icopen
));
247 icopen
.dwSize
= sizeof(icopen
);
248 icopen
.fccType
= ICTYPE_VIDEO
; /* VIDC */
249 icopen
.fccHandler
= dwFCC
;
250 icopen
.dwVersion
= 0x00001000; /* FIXME */
251 icopen
.dwFlags
= ICMODE_COMPRESS
;
253 icopen
.pV1Reserved
= NULL
;
254 icopen
.pV2Reserved
= NULL
;
255 icopen
.dnDevNode
= -1; /* FIXME */
257 coinit
= CoInitialize(NULL
);
259 if (!(hDriver
= OpenDriver(drvfile
, NULL
, (LPARAM
) &icopen
)))
260 BAIL("OpenDriver() failed\n");
263 memset(&icinfo, 0, sizeof(ICINFO));
264 icinfo.dwSize = sizeof(ICINFO);
265 SendDriverMessage(hDriver, ICM_GETINFO, (LPARAM) &icinfo, sizeof(ICINFO));
268 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, -1, 0) != ICERR_OK
)
269 BAIL("The driver doesn't provide a configure dialog");
275 if (load_settings(hDriver
, filename
))
276 BAIL("Cannot load settings from file");
277 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, 0, 0) != ICERR_OK
)
278 BAIL("ICM_CONFIGURE failed");
281 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, 0, 0) != ICERR_OK
)
282 BAIL("ICM_CONFIGURE failed");
283 if (save_settings(hDriver
, filename
))
284 BAIL("Cannot save settings to file");
288 HWND hwnd
= GetDesktopWindow();
289 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, (LPARAM
) hwnd
, 0) != ICERR_OK
)
290 BAIL("ICM_CONFIGURE failed");
294 BAIL("This should not happen :)");
298 if (driver
) free(driver
);
299 if (fourcc
) free(fourcc
);
300 if (filename
) free(filename
);
301 if (hDriver
) CloseDriver(hDriver
, 0, 0);
302 if ((coinit
== S_OK
) || coinit
== S_FALSE
) CoUninitialize();