commit:bad9a1a98ab950405c0a1c38703a0e1c8b9c11be
author:Chip Black
committer:Chip Black
date:Wed Apr 30 20:56:01 2008 -0500
parents:
Initial commit
diff --git a/Makefile b/Makefile
line changes: +6/-0
index 0000000..7902dc2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
+CSLIBS = -debug -pkg:gtk-sharp-2.0
+
+all: VFSEncoder.exe
+
+%.exe: %.cs
+	mcs $(CSLIBS) $< -out:$@

diff --git a/VFSEncoder.cs b/VFSEncoder.cs
line changes: +145/-0
index 0000000..84e5a05
--- /dev/null
+++ b/VFSEncoder.cs
@@ -0,0 +1,145 @@
+namespace VFSEncoder {
+	using Gtk;
+	using System;
+	using System.IO;
+	using System.Collections;
+	using System.Diagnostics;
+	using System.Text.RegularExpressions;
+
+	public class VFSEncoder {
+		static Hashtable encoder_commands;
+
+		static Window window;
+		static Table options;
+		static Label[] label = new Label[2];
+		static Label status;
+		static ComboBox profiles;
+		static FileChooserDialog filechooser;
+		static FileChooserButton browse;
+		static Button go;
+
+		static void load_encoder_commands() {
+			encoder_commands = new Hashtable();
+			StreamReader r = new StreamReader("profiles.txt");
+			string line;
+			while(true) {
+				try {
+					line = r.ReadLine();
+					if (line == null) break;
+				} catch(IOException e) {
+					Console.WriteLine(e.Message);
+					break;
+				}
+
+				int i = line.IndexOf(":");
+				if (i == -1) continue;
+
+				string k = line.Substring(0, i).Trim();
+				encoder_commands.Add(k, line.Substring(i+1).Trim());
+				Console.WriteLine("Added encoder command {0} : {1}", k, encoder_commands[k]);
+			}
+			r.Close();
+		}
+
+		static void delete_event(object obj, DeleteEventArgs args) {
+			Application.Quit();
+		}
+
+		static void go_click(object obj, EventArgs args) {
+			if (profiles.ActiveText == null) {
+				Console.WriteLine("NULL!");
+				return;
+			}
+
+			browse.Sensitive = false;
+			profiles.Sensitive = false;
+			go.Sensitive = false;
+
+			Console.WriteLine(encoder_commands[profiles.ActiveText]);
+			string outfile = Path.Combine("output",Path.ChangeExtension(Path.GetFileName(browse.Filename), "mp4"));
+
+			Process p = new Process();
+			p.StartInfo.FileName = "ffmpeg";
+			p.StartInfo.Arguments = "-y " + String.Format((string)encoder_commands[profiles.ActiveText], browse.Filename, outfile);
+			p.StartInfo.UseShellExecute = false;
+			p.StartInfo.RedirectStandardError = true;
+			p.Start();
+			
+			int c;
+			string s = "";
+			while (-1 != (c = p.StandardError.Read())) {
+				if (c == '\r' || c == '\n') {
+					status.Text = s;
+					s = "";
+					Application.RunIteration();
+				} else {
+					s += (char)c;
+				}
+			}
+			p.WaitForExit();
+
+			browse.Sensitive = true;
+			profiles.Sensitive = true;
+			go.Sensitive = true;
+		}
+
+		public static int Main(string[] args) {
+			FileFilter filter;
+			load_encoder_commands();
+
+			Application.Init();
+
+			window = new Window("VFS Encoder");
+			window.DeleteEvent += delete_event;
+			window.DefaultWidth = 300;
+
+			filechooser = new FileChooserDialog("Choose the file to encode", window, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
+			filter = new FileFilter();
+			filter.Name = "Video files";
+			filter.AddMimeType("video/mp4");
+			filter.AddPattern("*.mp4");
+			filter.AddMimeType("video/x-msvideo");
+			filter.AddPattern("*.avi");
+			filter.AddMimeType("video/quicktime");
+			filter.AddPattern("*.mov");
+			filter.AddMimeType("video/x-ms-wmv");
+			filter.AddPattern("*.wmv");
+			filter.AddMimeType("video/mpeg");
+			filter.AddPattern("*.mpg");
+			filechooser.AddFilter(filter);
+
+			filter = new FileFilter();
+			filter.Name = "All Files";
+			filter.AddPattern("*");
+			filechooser.AddFilter(filter);
+
+			options = new Table(2, 4, false);
+			label[0] = new Label("File");
+			options.Attach(label[0], 0, 1, 0, 1, AttachOptions.Shrink, 0, 4, 2);
+			label[1] = new Label("Encoder Profile");
+			options.Attach(label[1], 0, 1, 1, 2, AttachOptions.Shrink, 0, 4, 2);
+			browse = new FileChooserButton(filechooser);
+			options.Attach(browse, 1, 2, 0, 1);
+			profiles = ComboBox.NewText();
+			foreach (string k in encoder_commands.Keys)
+				profiles.AppendText(k);
+			options.Attach(profiles, 1, 2, 1, 2);
+			go = new Button("Go!");
+			go.Clicked += new EventHandler(go_click);
+			options.Attach(go, 0, 2, 2, 3);
+			status = new Label();
+			options.Attach(status, 0, 2, 3, 4, AttachOptions.Fill, AttachOptions.Shrink, 0, 2);
+			status.Justify = Justification.Left;
+			status.Text = "VFSEncoder Ready";
+
+			window.Add(options);
+			options.Show();
+			window.ShowAll();
+
+			Application.Run();
+			return 0;
+		}
+	}
+}
+
+// :vim:set ts=4 sw=4 sts=4:

diff --git a/profiles.txt b/profiles.txt
line changes: +2/-0
index 0000000..7ed95c9
--- /dev/null
+++ b/profiles.txt
@@ -0,0 +1,2 @@
+x264 lossless : -i {0} -vcodec x264 -cqp 0 {1}
+xvid q=1 : -i {0} -vcodec xvid -qscale 1 {1}