summaryrefslogtreecommitdiffstats
path: root/TOOLS
diff options
context:
space:
mode:
authoralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-02-18 23:24:21 +0000
committeralex <alex@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-02-18 23:24:21 +0000
commit857545e72590cf033d5309d44fe7bfebea00f801 (patch)
treecde6cc96fecc5b71b9f7008119e88fec1f94546d /TOOLS
parent7732afe15503653a2f63e0f8ddfdf351857bff85 (diff)
downloadmpv-857545e72590cf033d5309d44fe7bfebea00f801.tar.bz2
mpv-857545e72590cf033d5309d44fe7bfebea00f801.tar.xz
Controllable quality setting of VFW enconding, through the dumped state of the dialog box. Patch by Gianluigi Tiesi
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22270 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/vfw2menc.c257
1 files changed, 257 insertions, 0 deletions
diff --git a/TOOLS/vfw2menc.c b/TOOLS/vfw2menc.c
new file mode 100644
index 0000000000..fc746120da
--- /dev/null
+++ b/TOOLS/vfw2menc.c
@@ -0,0 +1,257 @@
+/*
+ * VFW Compressor Settings Tool
+ *
+ * Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this software; if not, write to the
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* On mingw compile with: gcc getopt.c vfw2menc.c -o vfw2menc.exe -lwinmm */
+/* Using wine: winegcc getopt.c vfw2menc.c -o vfw2menc -lwinmm */
+
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_DEPRECATE
+#pragma warning(disable: 4996)
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#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; }
+
+enum
+{
+ MODE_NONE = 0,
+ MODE_CHECK,
+ MODE_SAVE,
+ MODE_VIEW
+};
+
+int save_settings(HDRVR hDriver, const char *filename)
+{
+ 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;
+}
+
+int load_settings(HDRVR hDriver, const char *filename)
+{
+ 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 }
+};
+
+void help(const char *progname)
+{
+ printf("VFW to mencoder - Copyright 2006 - Gianluigi Tiesi <sherpya@netfarm.it>\n");
+ 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;
+
+ 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");
+ }
+ }
+
+
+ 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");
+
+ if (!(hDriver = OpenDriver(drvfile, 0, (fourcc) ? ((LPARAM) fourcc) : 0)))
+ BAIL("OpenDriver() failed\n");
+
+ if (SendDriverMessage(hDriver, ICM_CONFIGURE, -1, 0) != ICERR_OK)
+ BAIL("The driver doesn't provide a configure dialog");
+
+ 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:
+ if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)
+ BAIL("ICM_CONFIGURE failed");
+ 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);
+ return ret;
+}