Switched to gmcs, added the ability to stop ffmpeg slave process.
all: VFSEncoder.exe
%.exe: %.cs
- mcs $(CSLIBS) $< -out:$@
+ gmcs $(CSLIBS) $< -out:$@
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;
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;
}
} catch(IOException e) {
Console.WriteLine(e.Message);
- break;
}
r.Close();
}
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!";
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) {
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;
}
}
-// :vim:set ts=4 sw=4 sts=4:
+// vim:set ts=4 sw=4 sts=4: