commit:54ff45d6230c9d76e82e968bb6fd43cbf06cebff
author:Chip Black
committer:Chip Black
date:Thu May 1 15:40:52 2008 -0500
parents:0c977a82fa5c7352c9b36d4dc8e996f8c2a12bbe
Now supports two (or more!) pass encoding. Profiles.txt format changed
accordingly, and new and interesting formats added.
diff --git a/VFSEncoder.cs b/VFSEncoder.cs
line changes: +39/-19
index b62ef62..f7be974
--- a/VFSEncoder.cs
+++ b/VFSEncoder.cs
@@ -1,6 +1,7 @@
 namespace VFSEncoder {
 	using Gtk;
 	using System;
+	using System.Threading;
 	using System.IO;
 	using System.Collections;
 	using System.Diagnostics;
@@ -20,19 +21,32 @@ namespace VFSEncoder {
 		static Button go, stop;
 		static Process p;
 
+		static bool cancel_encode = false;
+
 		static void load_encoder_commands() {
 			encoder_names = new ArrayList();
 			encoder_commands = new ArrayList();
 			StreamReader r = new StreamReader("profiles.txt");
+			Regex section_re = new Regex(@"^\[(.+)\]$");
+			ArrayList current = null;
+
 			string line;
 			try {
 				while(null != (line = r.ReadLine())) {
-
-					int i = line.IndexOf(":");
-					if (i == -1) continue;
-
-					encoder_names.Add(line.Substring(0, i).Trim());
-					encoder_commands.Add(line.Substring(i+1).Trim());
+					if (line.Length == 0) continue;
+
+					Match m = section_re.Match(line);
+					if (m.Success) {
+						Console.WriteLine(m.Groups[1].ToString());
+						encoder_names.Add(m.Groups[1].ToString());
+						current = new ArrayList();
+						encoder_commands.Add(current);
+					} else {
+						if (current != null) {
+							Console.WriteLine("args: {0}", line);
+							current.Add(line);
+						}
+					}
 				}
 			} catch(IOException e) {
 				Console.WriteLine(e.Message);
@@ -48,6 +62,7 @@ namespace VFSEncoder {
 			p.StandardInput.Write("q");
 			p.StandardInput.Flush();
 			p.WaitForExit();
+			cancel_encode = true;
 		}
 
 		static void go_click(object obj, EventArgs args) {
@@ -63,20 +78,24 @@ namespace VFSEncoder {
 
 			string outfile = Path.Combine("output", Path.ChangeExtension(Path.GetFileName(browse.Filename), "mp4"));
 
-			p = new Process();
-			p.StartInfo.FileName = "ffmpeg";
-			p.StartInfo.Arguments = "-y " + String.Format((string)encoder_commands[profiles.Active], browse.Filename, outfile);
-			p.StartInfo.UseShellExecute = false;
-			p.StartInfo.RedirectStandardInput = true;
-
-			status.Text = "Encoding...";
-			p.Start();
-			
-			while (!p.HasExited) {
-				Application.RunIteration();
+			foreach (string ffargs in (ArrayList)encoder_commands[profiles.Active]) {
+				p = new Process();
+				p.StartInfo.FileName = "ffmpeg";
+				p.StartInfo.Arguments = String.Format("-y -i \"{0}\" {2} \"{1}\"", browse.Filename, outfile, ffargs);
+				p.StartInfo.UseShellExecute = false;
+				p.StartInfo.RedirectStandardInput = true;
+
+				status.Text = "Encoding...";
+				p.Start();
+				
+				while (!p.HasExited) {
+					Application.RunIteration(false);
+					Thread.Sleep(50);
+				}
+				p.WaitForExit();
+				if (cancel_encode || p.ExitCode != 0)
+					break;
 			}
-			p.WaitForExit();
-			p.Close();
 
 			status.Text = String.Format("Finished encoding {0}.", outfile);
 
@@ -84,6 +103,7 @@ namespace VFSEncoder {
 			profiles.Sensitive = true;
 			stop.Visible = false;
 			go.Visible = true;
+			cancel_encode = false;
 		}
 
 		public static int Main(string[] args) {

diff --git a/profiles.txt b/profiles.txt
line changes: +13/-2
index a6e28c2..68d11fd
--- a/profiles.txt
+++ b/profiles.txt
@@ -1,2 +1,13 @@
-x264 lossless : -i "{0}" -vcodec h264 -cqp 0 "{1}"
-xvid q=1 : -i "{0}" -vcodec xvid -qscale 1 "{1}"
+[x264 lossless]
+-vcodec h264 -cqp 0
+
+[xvid q=1]
+-vcodec xvid -qscale 1
+
+[xvid 1500kbit 2pass]
+-vcodec xvid -flags +trell+aic+4mv -b 1500k -an -pass 1
+-vcodec xvid -flags +trell+aic+4mv -b 1500k -acodec aac -ab 128k -ar 22050 -pass 2
+
+[x264 1500kbit 2pass]
+-vcodec x264 -qmax 50 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me hex -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -b 1500k -an -pass 1
+-vcodec x264 -qmax 50 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me hex -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -b 1500k -acodec aac -ab 128k -ar 22050 -pass 2