Now supports two (or more!) pass encoding. Profiles.txt format changed
accordingly, and new and interesting formats added.
namespace VFSEncoder {
using Gtk;
using System;
+ using System.Threading;
using System.IO;
using System.Collections;
using System.Diagnostics;
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);
p.StandardInput.Write("q");
p.StandardInput.Flush();
p.WaitForExit();
+ cancel_encode = true;
}
static void go_click(object obj, EventArgs args) {
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);
profiles.Sensitive = true;
stop.Visible = false;
go.Visible = true;
+ cancel_encode = false;
}
public static int Main(string[] args) {
-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