commit:0c977a82fa5c7352c9b36d4dc8e996f8c2a12bbe
author:Chip Black
committer:Chip Black
date:Thu May 1 14:27:32 2008 -0500
parents:a404d1c43af3650f2f17c00879a75b9efb2ce6bd
Switched to gmcs, added the ability to stop ffmpeg slave process.
diff --git a/Makefile b/Makefile
line changes: +1/-1
index 7902dc2..f0dfc64
--- a/Makefile
+++ b/Makefile
@@ -3,4 +3,4 @@ CSLIBS = -debug -pkg:gtk-sharp-2.0
 all: VFSEncoder.exe
 
 %.exe: %.cs
-	mcs $(CSLIBS) $< -out:$@
+	gmcs $(CSLIBS) $< -out:$@

diff --git a/VFSEncoder.cs b/VFSEncoder.cs
line changes: +30/-21
index 05add64..b62ef62
--- a/VFSEncoder.cs
+++ b/VFSEncoder.cs
@@ -7,8 +7,8 @@ namespace VFSEncoder {
 	using System.Text.RegularExpressions;
 
 	public class VFSEncoder {
-		static ArrayList<string> encoder_names;
-		static ArrayList<string> encoder_commands;
+		static ArrayList encoder_names;
+		static ArrayList encoder_commands;
 
 		static Window window;
 		static Table options;
@@ -17,14 +17,16 @@ namespace VFSEncoder {
 		static ComboBox profiles;
 		static FileChooserDialog filechooser;
 		static FileChooserButton browse;
-		static Button go;
+		static Button go, stop;
+		static Process p;
 
 		static void load_encoder_commands() {
+			encoder_names = new ArrayList();
 			encoder_commands = new ArrayList();
 			StreamReader r = new StreamReader("profiles.txt");
 			string line;
 			try {
-				while(null != (line = r.ReadLine()) {
+				while(null != (line = r.ReadLine())) {
 
 					int i = line.IndexOf(":");
 					if (i == -1) continue;
@@ -34,7 +36,6 @@ namespace VFSEncoder {
 				}
 			} catch(IOException e) {
 				Console.WriteLine(e.Message);
-				break;
 			}
 			r.Close();
 		}
@@ -43,6 +44,12 @@ namespace VFSEncoder {
 			Application.Quit();
 		}
 
+		static void stop_click(object obj, EventArgs args) {
+			p.StandardInput.Write("q");
+			p.StandardInput.Flush();
+			p.WaitForExit();
+		}
+
 		static void go_click(object obj, EventArgs args) {
 			if (browse.Filename == null) {
 				status.Text = "No file selected!";
@@ -51,33 +58,32 @@ namespace VFSEncoder {
 
 			browse.Sensitive = false;
 			profiles.Sensitive = false;
-			go.Sensitive = false;
+			go.Visible = false;
+			stop.Visible = true;
 
 			string outfile = Path.Combine("output", Path.ChangeExtension(Path.GetFileName(browse.Filename), "mp4"));
 
-			Process p = new Process();
+			p = new Process();
 			p.StartInfo.FileName = "ffmpeg";
-			p.StartInfo.Arguments = "-y " + String.Format(encoder_commands[profiles.Active], browse.Filename, outfile);
+			p.StartInfo.Arguments = "-y " + String.Format((string)encoder_commands[profiles.Active], browse.Filename, outfile);
 			p.StartInfo.UseShellExecute = false;
-			p.StartInfo.RedirectStandardError = true;
+			p.StartInfo.RedirectStandardInput = true;
+
+			status.Text = "Encoding...";
 			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;
-				}
+			while (!p.HasExited) {
+				Application.RunIteration();
 			}
 			p.WaitForExit();
+			p.Close();
+
+			status.Text = String.Format("Finished encoding {0}.", outfile);
 
 			browse.Sensitive = true;
 			profiles.Sensitive = true;
-			go.Sensitive = true;
+			stop.Visible = false;
+			go.Visible = true;
 		}
 
 		public static int Main(string[] args) {
@@ -129,6 +135,9 @@ namespace VFSEncoder {
 			go = new Button("Go!");
 			go.Clicked += new EventHandler(go_click);
 			options.Attach(go, 0, 2, 2, 3);
+			stop = new Button("Stop");
+			stop.Clicked += new EventHandler(stop_click);
+			options.Attach(stop, 0, 2, 2, 3);
 			status = new Label();
 			options.Attach(status, 0, 2, 3, 4, AttachOptions.Fill, AttachOptions.Shrink, 0, 2);
 			status.Justify = Justification.Left;
@@ -144,4 +153,4 @@ namespace VFSEncoder {
 	}
 }
 
-// :vim:set ts=4 sw=4 sts=4:
+// vim:set ts=4 sw=4 sts=4: