[longomatch] Revert "Use the new remuxer"



commit 324c447004ccf99986bcffacbe71dc0848da568b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Dec 6 17:57:33 2012 +0100

    Revert "Use the new remuxer"
    
    This reverts commit 8686de8beb459346f1f21d5668b2879d200bcc1f.

 LongoMatch.Multimedia/Utils/MpegRemuxer.cs |   65 +++++++++++++++++-----------
 1 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/LongoMatch.Multimedia/Utils/MpegRemuxer.cs b/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
index edb12f7..4d9f48f 100644
--- a/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
+++ b/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
@@ -17,32 +17,30 @@
 // 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
+using System.Threading;
 using Mono.Unix;
 using GLib;
 using Gtk;
 
-using LongoMatch.Interfaces.Multimedia;
-
 namespace LongoMatch.Video.Utils
 {
 	public class MpegRemuxer
 	{
-		static string[] EXTENSIONS =  {"mts", "m2ts", "m2t", "ts", "mpeg", "mpg"};
-		string filepath;
-		string newFilepath;
-		Dialog dialog;
-		ProgressBar pb;
-		IRemuxer remuxer;
-		IMultimediaToolkit multimedia;
-		uint timeout;
-		bool cancelled;
+		private static string[] EXTENSIONS =  {"mts", "m2ts", "m2t", "ts", "mpeg", "mpg"};
+		private string filepath;
+		private string newFilepath;
+		private Dialog dialog;
+		private ProgressBar pb;
+		private System.Threading.Thread remuxThread;
+		private uint timeout;
+		private bool cancelled;
 		
 		public MpegRemuxer (string filepath)
 		{
 			this.filepath = filepath;
-			this.multimedia = new MultimediaFactory();
-			newFilepath = Path.ChangeExtension(filepath, "webm");
+			newFilepath = Path.ChangeExtension(filepath, "mp4");
 		}
 		
 		public string Remux(Window parent) {
@@ -61,29 +59,22 @@ namespace LongoMatch.Video.Utils
 			
 			/* Add a button to cancell the task */
 			cancellButton = new Button("gtk-cancel");
-			cancellButton.Clicked += (sender, e) => Cancel (); 
+			cancellButton.Clicked += OnStop; 
 			cancellButton.Show();
 			dialog.VBox.Add(cancellButton);
 			
+			/* Start the remux task in a separate thread */
+			remuxThread = new System.Threading.Thread(new ThreadStart(RemuxTask));
+			remuxThread.Start();
+			
 			/* Add a timeout to refresh the progress bar */ 
 			pb.Pulse();
 			timeout = GLib.Timeout.Add (1000, new GLib.TimeoutHandler (Update));
 			
-			remuxer = multimedia.GetRemuxer(filepath, newFilepath);
-			remuxer.Progress += HandleRemuxerProgress;;
-			remuxer.Start();
-			
 			/* Wait until the thread call Destroy on the dialog */
 			dialog.Run();
 			return cancelled ? null : newFilepath;
 		}
-
-		void HandleRemuxerProgress (float progress)
-		{
-			if (progress == 1) {
-				Stop ();
-			}
-		}
 		
 		private bool Update() {
 			pb.Pulse();			
@@ -91,11 +82,33 @@ namespace LongoMatch.Video.Utils
 		}
 		
 		private void Stop() {
+			if (cancelled) {
+				if (remuxThread.IsAlive)
+					remuxThread.Interrupt();
+				File.Delete (newFilepath);
+			}
 			GLib.Source.Remove (timeout);
 			dialog.Destroy();
 		}
 		
-		void Cancel() {
+		private void RemuxTask(){
+			/* ffmpeg looks like the easiest and more accurate way to do the remux */
+			ProcessStartInfo startInfo = new ProcessStartInfo();
+			startInfo.CreateNoWindow = true;
+			startInfo.UseShellExecute = false;
+			startInfo.FileName = "ffmpeg";
+			startInfo.Arguments = String.Format("-i {0} -vcodec copy -acodec copy -y -sn {1} ",
+			                                    filepath, newFilepath);
+			using (System.Diagnostics.Process exeProcess = System.Diagnostics.Process.Start(startInfo))
+			{
+				exeProcess.WaitForExit();
+				Application.Invoke (delegate {
+					Stop();
+				});
+			}
+		}
+		
+		private void OnStop (object sender, System.EventArgs args) {
 			cancelled = true;
 			Stop();
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]