2007-02-18 23:24:21 +00:00
|
|
|
/*
|
|
|
|
* VFW Compressor Settings Tool
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
|
|
|
|
*
|
2007-02-22 18:20:14 +00:00
|
|
|
* Official Website : http://oss.netfarm.it/mplayer-win32.php
|
|
|
|
*
|
2007-02-18 23:24:21 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2007-02-19 00:20:48 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2007-02-18 23:24:21 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
2007-02-19 00:20:48 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2007-02-18 23:24:21 +00:00
|
|
|
*
|
2007-02-19 00:20:48 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2007-02-18 23:24:21 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2007-02-19 00:20:48 +00:00
|
|
|
* Lesser General Public License for more details.
|
2007-02-18 23:24:21 +00:00
|
|
|
*
|
2007-02-19 00:20:48 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2007-02-19 01:26:17 +00:00
|
|
|
* License along with this program; if not, write to the the Free Software
|
2007-02-18 23:24:21 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2007-03-04 15:48:20 +00:00
|
|
|
/* On MinGW compile with: gcc vfw2menc.c -o vfw2menc.exe -lwinmm -lole32 */
|
|
|
|
/* Using Wine: winegcc vfw2menc.c -o vfw2menc -lwinmm -lole32 */
|
|
|
|
/* MSVC requires getopt.c and getopt.h available at the original website */
|
2007-02-18 23:24:21 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define _CRT_SECURE_NO_DEPRECATE
|
|
|
|
#pragma warning(disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2007-03-06 14:15:37 +00:00
|
|
|
#define VERSION "0.1"
|
2007-02-22 19:03:36 +00:00
|
|
|
|
2007-02-18 23:24:21 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-04-30 14:03:32 +00:00
|
|
|
#include <string.h>
|
2007-02-18 23:24:21 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <vfw.h>
|
|
|
|
|
|
|
|
#define BAIL(msg) { printf("%s: %s\n", argv[0], msg); ret = -1; goto cleanup; }
|
|
|
|
|
2007-02-22 19:03:36 +00:00
|
|
|
typedef struct {
|
|
|
|
UINT uDriverSignature;
|
|
|
|
HINSTANCE hDriverModule;
|
|
|
|
DRIVERPROC DriverProc;
|
|
|
|
DWORD dwDriverID;
|
|
|
|
} DRVR;
|
|
|
|
|
|
|
|
typedef DRVR *PDRVR;
|
|
|
|
typedef DRVR *NPDRVR;
|
|
|
|
typedef DRVR *LPDRVR;
|
|
|
|
|
2007-02-18 23:24:21 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MODE_NONE = 0,
|
|
|
|
MODE_CHECK,
|
|
|
|
MODE_SAVE,
|
|
|
|
MODE_VIEW
|
|
|
|
};
|
|
|
|
|
2008-04-30 13:53:40 +00:00
|
|
|
static int save_settings(HDRVR hDriver, const char *filename)
|
2007-02-18 23:24:21 +00:00
|
|
|
{
|
|
|
|
FILE *fd = NULL;
|
|
|
|
DWORD cb = (DWORD) SendDriverMessage(hDriver, ICM_GETSTATE, 0, 0);
|
|
|
|
char *pv = NULL;
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
{
|
|
|
|
printf("ICM_GETSTATE returned 0 size\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pv = (char *) malloc(cb);
|
|
|
|
if (SendDriverMessage(hDriver, ICM_GETSTATE, (LPARAM) pv, (LPARAM) &cb) != ICERR_OK)
|
|
|
|
{
|
|
|
|
printf("ICM_GETSTATE failed\n");
|
|
|
|
free(pv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fopen(filename, "wb");
|
|
|
|
if (!fd)
|
|
|
|
{
|
|
|
|
printf("Cannot open file %s for writing\n", filename);
|
|
|
|
free(pv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fwrite(pv, cb, 1, fd) != 1)
|
|
|
|
{
|
|
|
|
printf("fwrite() failed on %s\n", filename);
|
|
|
|
free(pv);
|
|
|
|
fclose(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
free(pv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-30 13:53:40 +00:00
|
|
|
static int load_settings(HDRVR hDriver, const char *filename)
|
2007-02-18 23:24:21 +00:00
|
|
|
{
|
|
|
|
struct stat info;
|
|
|
|
FILE *fd = NULL;
|
|
|
|
char *pv;
|
|
|
|
|
|
|
|
if (stat(filename, &info) < 0)
|
|
|
|
{
|
|
|
|
printf("stat() on %s failed\n", filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pv = (char *) malloc(info.st_size);
|
|
|
|
fd = fopen(filename, "rb");
|
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
{
|
|
|
|
printf("Cannot open file %s for reading\n", filename);
|
|
|
|
free(pv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fread(pv, info.st_size, 1, fd) != 1)
|
|
|
|
{
|
|
|
|
printf("fread() failed on %s\n", filename);
|
|
|
|
free(pv);
|
|
|
|
fclose(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
if (!SendDriverMessage(hDriver, ICM_SETSTATE, (LPARAM) pv, (LPARAM) info.st_size))
|
|
|
|
{
|
|
|
|
printf("ICM_SETSTATE failed\n");
|
|
|
|
free(pv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(pv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "driver", required_argument, NULL, 'd' },
|
|
|
|
{ "fourcc", required_argument, NULL, 'f' },
|
|
|
|
{ "save", required_argument, NULL, 's' },
|
|
|
|
{ "check", required_argument, NULL, 'c' },
|
|
|
|
{ "view", no_argument, NULL, 'v' },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2008-04-30 13:53:40 +00:00
|
|
|
static void help(const char *progname)
|
2007-02-18 23:24:21 +00:00
|
|
|
{
|
2007-03-06 14:15:37 +00:00
|
|
|
printf("VFW to mencoder v"VERSION" - Copyright 2007 - Gianluigi Tiesi <sherpya@netfarm.it>\n");
|
2007-02-18 23:24:21 +00:00
|
|
|
printf("This program is Free Software\n\n");
|
|
|
|
printf("Usage: %s\n", progname);
|
|
|
|
printf(" -h|--help - displays this help\n");
|
|
|
|
printf(" -d|--driver filename - dll or drv to load\n");
|
|
|
|
printf(" -f|--fourcc fourcc - fourcc of selected driver (look at codecs.conf)\n");
|
|
|
|
printf(" -s|--save filename - save settings to file\n");
|
|
|
|
printf(" -c|--check filename - load and show setting in filename\n");
|
|
|
|
printf(" -v|--view - displays the config dialog and do nothing\n");
|
|
|
|
printf("\nExamples:\n");
|
|
|
|
printf(" %s -f VP62 -d vp6vfw.dll -s firstpass.mcf\n", progname);
|
|
|
|
printf(" %s -f VP62 -d vp6vfw.dll -c firstpass.mcf\n", progname);
|
|
|
|
printf(" %s -f VP62 -d vp6vfw.dll -v\n", progname);
|
|
|
|
printf("\nIf the driver dialog doesn't work, you can try without specifing a fourcc,\n");
|
|
|
|
printf("but the compdata file will not work with mencoder.\n");
|
|
|
|
printf("Driver option is required and you must specify at least -s, -c -o -v\n");
|
|
|
|
printf("Usage with mencoder -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=settings.mcf\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *driver = NULL;
|
|
|
|
char *fourcc = NULL;
|
|
|
|
char *filename = NULL;
|
|
|
|
unsigned char mode = 0;
|
2007-02-22 19:03:36 +00:00
|
|
|
DWORD dwFCC = 0;
|
|
|
|
ICOPEN icopen;
|
2007-10-17 02:24:50 +00:00
|
|
|
HRESULT coinit = -1;
|
2007-02-22 19:03:36 +00:00
|
|
|
/* ICINFO icinfo; */
|
2007-02-18 23:24:21 +00:00
|
|
|
|
|
|
|
wchar_t drvfile[MAX_PATH];
|
|
|
|
HDRVR hDriver = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
int c = -1, long_options_index = -1;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
help(argv[0]);
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, "hd:f:s:c:v", long_options, &long_options_index)) != -1)
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
help(argv[0]);
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
case 'd':
|
|
|
|
driver = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fourcc = strdup(optarg);
|
|
|
|
if (strlen(optarg) != 4) BAIL("Fourcc must be exactly 4 chars");
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (mode != MODE_NONE) BAIL("Incompatible arguments");
|
|
|
|
filename = strdup(optarg);
|
|
|
|
mode = MODE_SAVE;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (mode != MODE_NONE) BAIL("Incompatible arguments");
|
|
|
|
filename = strdup(optarg);
|
|
|
|
mode = MODE_CHECK;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
if (mode != MODE_NONE) BAIL("Incompatible arguments");
|
|
|
|
mode = MODE_VIEW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Wrong arguments!\n");
|
2007-02-22 19:03:36 +00:00
|
|
|
help(argv[0]);
|
|
|
|
goto cleanup;
|
2007-02-18 23:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(argc == optind) && (mode != MODE_NONE) &&
|
|
|
|
driver && (filename || (mode == MODE_VIEW)))
|
|
|
|
{
|
|
|
|
help(argv[0]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar(CP_ACP, 0, driver, -1, drvfile, MAX_PATH))
|
|
|
|
BAIL("MultiByteToWideChar() failed\n");
|
|
|
|
|
2007-02-22 19:03:36 +00:00
|
|
|
if (fourcc) memcpy(&dwFCC, fourcc, 4);
|
|
|
|
memset(&icopen, 0, sizeof(icopen));
|
|
|
|
|
|
|
|
icopen.dwSize = sizeof(icopen);
|
|
|
|
icopen.fccType = ICTYPE_VIDEO; /* VIDC */
|
|
|
|
icopen.fccHandler = dwFCC;
|
|
|
|
icopen.dwVersion = 0x00001000; /* FIXME */
|
|
|
|
icopen.dwFlags = ICMODE_COMPRESS;
|
|
|
|
icopen.dwError = 0;
|
|
|
|
icopen.pV1Reserved = NULL;
|
|
|
|
icopen.pV2Reserved = NULL;
|
|
|
|
icopen.dnDevNode = -1; /* FIXME */
|
|
|
|
|
|
|
|
coinit = CoInitialize(NULL);
|
|
|
|
|
|
|
|
if (!(hDriver = OpenDriver(drvfile, NULL, (LPARAM) &icopen)))
|
2007-02-18 23:24:21 +00:00
|
|
|
BAIL("OpenDriver() failed\n");
|
|
|
|
|
2007-02-22 19:03:36 +00:00
|
|
|
/*
|
|
|
|
memset(&icinfo, 0, sizeof(ICINFO));
|
|
|
|
icinfo.dwSize = sizeof(ICINFO);
|
|
|
|
SendDriverMessage(hDriver, ICM_GETINFO, (LPARAM) &icinfo, sizeof(ICINFO));
|
|
|
|
*/
|
|
|
|
|
2007-02-18 23:24:21 +00:00
|
|
|
if (SendDriverMessage(hDriver, ICM_CONFIGURE, -1, 0) != ICERR_OK)
|
|
|
|
BAIL("The driver doesn't provide a configure dialog");
|
|
|
|
|
2007-02-22 19:03:36 +00:00
|
|
|
|
2007-02-18 23:24:21 +00:00
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case MODE_CHECK:
|
|
|
|
if (load_settings(hDriver, filename))
|
|
|
|
BAIL("Cannot load settings from file");
|
|
|
|
if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)
|
|
|
|
BAIL("ICM_CONFIGURE failed");
|
|
|
|
break;
|
|
|
|
case MODE_SAVE:
|
|
|
|
if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)
|
|
|
|
BAIL("ICM_CONFIGURE failed");
|
|
|
|
if (save_settings(hDriver, filename))
|
|
|
|
BAIL("Cannot save settings to file");
|
|
|
|
break;
|
|
|
|
case MODE_VIEW:
|
2007-02-22 19:03:36 +00:00
|
|
|
{
|
|
|
|
HWND hwnd = GetDesktopWindow();
|
|
|
|
if (SendDriverMessage(hDriver, ICM_CONFIGURE, (LPARAM) hwnd, 0) != ICERR_OK)
|
|
|
|
BAIL("ICM_CONFIGURE failed");
|
|
|
|
}
|
2007-02-18 23:24:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BAIL("This should not happen :)");
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (driver) free(driver);
|
|
|
|
if (fourcc) free(fourcc);
|
|
|
|
if (filename) free(filename);
|
|
|
|
if (hDriver) CloseDriver(hDriver, 0, 0);
|
2007-09-23 20:37:33 +00:00
|
|
|
if ((coinit == S_OK) || coinit == S_FALSE) CoUninitialize();
|
2007-02-18 23:24:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|