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)
41 #define BAIL(msg) { printf("%s: %s\n", argv[0], msg); ret = -1; goto cleanup; }
44 UINT uDriverSignature
;
45 HINSTANCE hDriverModule
;
46 DRIVERPROC DriverProc
;
62 int save_settings(HDRVR hDriver
, const char *filename
)
65 DWORD cb
= (DWORD
) SendDriverMessage(hDriver
, ICM_GETSTATE
, 0, 0);
70 printf("ICM_GETSTATE returned 0 size\n");
74 pv
= (char *) malloc(cb
);
75 if (SendDriverMessage(hDriver
, ICM_GETSTATE
, (LPARAM
) pv
, (LPARAM
) &cb
) != ICERR_OK
)
77 printf("ICM_GETSTATE failed\n");
82 fd
= fopen(filename
, "wb");
85 printf("Cannot open file %s for writing\n", filename
);
90 if (fwrite(pv
, cb
, 1, fd
) != 1)
92 printf("fwrite() failed on %s\n", filename
);
102 int load_settings(HDRVR hDriver
, const char *filename
)
108 if (stat(filename
, &info
) < 0)
110 printf("stat() on %s failed\n", filename
);
114 pv
= (char *) malloc(info
.st_size
);
115 fd
= fopen(filename
, "rb");
119 printf("Cannot open file %s for reading\n", filename
);
124 if (fread(pv
, info
.st_size
, 1, fd
) != 1)
126 printf("fread() failed on %s\n", filename
);
132 if (!SendDriverMessage(hDriver
, ICM_SETSTATE
, (LPARAM
) pv
, (LPARAM
) info
.st_size
))
134 printf("ICM_SETSTATE failed\n");
142 static struct option long_options
[] =
144 { "help", no_argument
, NULL
, 'h' },
145 { "driver", required_argument
, NULL
, 'd' },
146 { "fourcc", required_argument
, NULL
, 'f' },
147 { "save", required_argument
, NULL
, 's' },
148 { "check", required_argument
, NULL
, 'c' },
149 { "view", no_argument
, NULL
, 'v' },
153 void help(const char *progname
)
155 printf("VFW to mencoder v"VERSION
" - Copyright 2007 - Gianluigi Tiesi <sherpya@netfarm.it>\n");
156 printf("This program is Free Software\n\n");
157 printf("Usage: %s\n", progname
);
158 printf(" -h|--help - displays this help\n");
159 printf(" -d|--driver filename - dll or drv to load\n");
160 printf(" -f|--fourcc fourcc - fourcc of selected driver (look at codecs.conf)\n");
161 printf(" -s|--save filename - save settings to file\n");
162 printf(" -c|--check filename - load and show setting in filename\n");
163 printf(" -v|--view - displays the config dialog and do nothing\n");
164 printf("\nExamples:\n");
165 printf(" %s -f VP62 -d vp6vfw.dll -s firstpass.mcf\n", progname
);
166 printf(" %s -f VP62 -d vp6vfw.dll -c firstpass.mcf\n", progname
);
167 printf(" %s -f VP62 -d vp6vfw.dll -v\n", progname
);
168 printf("\nIf the driver dialog doesn't work, you can try without specifing a fourcc,\n");
169 printf("but the compdata file will not work with mencoder.\n");
170 printf("Driver option is required and you must specify at least -s, -c -o -v\n");
171 printf("Usage with mencoder -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=settings.mcf\n");
174 int main(int argc
, char *argv
[])
178 char *filename
= NULL
;
179 unsigned char mode
= 0;
185 wchar_t drvfile
[MAX_PATH
];
186 HDRVR hDriver
= NULL
;
188 int c
= -1, long_options_index
= -1;
197 while ((c
= getopt_long(argc
, argv
, "hd:f:s:c:v", long_options
, &long_options_index
)) != -1)
206 driver
= strdup(optarg
);
209 fourcc
= strdup(optarg
);
210 if (strlen(optarg
) != 4) BAIL("Fourcc must be exactly 4 chars");
213 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
214 filename
= strdup(optarg
);
218 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
219 filename
= strdup(optarg
);
223 if (mode
!= MODE_NONE
) BAIL("Incompatible arguments");
227 printf("Wrong arguments!\n");
233 if (!(argc
== optind
) && (mode
!= MODE_NONE
) &&
234 driver
&& (filename
|| (mode
== MODE_VIEW
)))
240 if (!MultiByteToWideChar(CP_ACP
, 0, driver
, -1, drvfile
, MAX_PATH
))
241 BAIL("MultiByteToWideChar() failed\n");
243 if (fourcc
) memcpy(&dwFCC
, fourcc
, 4);
244 memset(&icopen
, 0, sizeof(icopen
));
246 icopen
.dwSize
= sizeof(icopen
);
247 icopen
.fccType
= ICTYPE_VIDEO
; /* VIDC */
248 icopen
.fccHandler
= dwFCC
;
249 icopen
.dwVersion
= 0x00001000; /* FIXME */
250 icopen
.dwFlags
= ICMODE_COMPRESS
;
252 icopen
.pV1Reserved
= NULL
;
253 icopen
.pV2Reserved
= NULL
;
254 icopen
.dnDevNode
= -1; /* FIXME */
256 coinit
= CoInitialize(NULL
);
258 if (!(hDriver
= OpenDriver(drvfile
, NULL
, (LPARAM
) &icopen
)))
259 BAIL("OpenDriver() failed\n");
262 memset(&icinfo, 0, sizeof(ICINFO));
263 icinfo.dwSize = sizeof(ICINFO);
264 SendDriverMessage(hDriver, ICM_GETINFO, (LPARAM) &icinfo, sizeof(ICINFO));
267 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, -1, 0) != ICERR_OK
)
268 BAIL("The driver doesn't provide a configure dialog");
274 if (load_settings(hDriver
, filename
))
275 BAIL("Cannot load settings from file");
276 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, 0, 0) != ICERR_OK
)
277 BAIL("ICM_CONFIGURE failed");
280 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, 0, 0) != ICERR_OK
)
281 BAIL("ICM_CONFIGURE failed");
282 if (save_settings(hDriver
, filename
))
283 BAIL("Cannot save settings to file");
287 HWND hwnd
= GetDesktopWindow();
288 if (SendDriverMessage(hDriver
, ICM_CONFIGURE
, (LPARAM
) hwnd
, 0) != ICERR_OK
)
289 BAIL("ICM_CONFIGURE failed");
293 BAIL("This should not happen :)");
297 if (driver
) free(driver
);
298 if (fourcc
) free(fourcc
);
299 if (filename
) free(filename
);
300 if (hDriver
) CloseDriver(hDriver
, 0, 0);
301 if ((coinit
== S_OK
) || coinit
== S_FALSE
) CoUninitialize();