+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: