[longomatch] Use matroska for live review and remux to the original format



commit 0d61d3e5d83dc7f70b07ac150cc5687257b9fbc1
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Feb 21 17:33:15 2013 +0100

    Use matroska for live review and remux to the original format

 .../Interfaces/Multimedia/IMultimediaToolkit.cs    |    2 +-
 LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs       |   44 +++++++++--
 .../Gui/Component/ProjectDetailsWidget.cs          |    4 +-
 LongoMatch.Multimedia/LongoMatch.Multimedia.mdp    |    2 +-
 LongoMatch.Multimedia/Makefile.am                  |    2 +-
 LongoMatch.Multimedia/MultimediaFactory.cs         |    4 +-
 LongoMatch.Multimedia/Remuxer/GstRemuxer.cs        |    7 +-
 .../Utils/{AsfRemuxer.cs => Remuxer.cs}            |   84 ++++++++++++++++----
 libcesarplayer/gst-remuxer.c                       |    8 ++-
 libcesarplayer/gst-remuxer.h                       |    3 +-
 po/POTFILES.in                                     |    2 +-
 11 files changed, 126 insertions(+), 36 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs 
b/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
index 786dacc..9ccb5a2 100644
--- a/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
+++ b/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
@@ -29,7 +29,7 @@ namespace LongoMatch.Interfaces.Multimedia
                
                IFramesCapturer GetFramesCapturer();
                
-               IRemuxer GetRemuxer(string inputFile, string outputFile);
+               IRemuxer GetRemuxer(string inputFile, string outputFile, VideoMuxerType muxer);
                
                MediaFile DiscoverFile(string path);
                
diff --git a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
index c27602d..5b59604 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -200,16 +200,23 @@ namespace LongoMatch.Gui
                }
 
                private void SetProperties() {
+                       VideoMuxerType muxer;
+                       
                        if(capturer == null)
                                return;
-
+                       
+                       /* We need to use Matroska for live replay and remux when the capture is done */
+                       muxer = captureProps.EncodingSettings.EncodingProfile.Muxer;
+                       if (muxer == VideoMuxerType.Avi || muxer == VideoMuxerType.Mp4)
+                               muxer = VideoMuxerType.Matroska;
+                               
                        capturer.DeviceID = captureProps.DeviceID;
                        capturer.OutputFile = captureProps.EncodingSettings.OutputFile;
                        capturer.OutputHeight = captureProps.EncodingSettings.VideoStandard.Height;
                        capturer.OutputWidth = captureProps.EncodingSettings.VideoStandard.Width;
                        capturer.SetVideoEncoder(captureProps.EncodingSettings.EncodingProfile.VideoEncoder);
                        capturer.SetAudioEncoder(captureProps.EncodingSettings.EncodingProfile.AudioEncoder);
-                       capturer.SetVideoMuxer(captureProps.EncodingSettings.EncodingProfile.Muxer);
+                       capturer.SetVideoMuxer(muxer);
                        capturer.SetSource(captureProps.CaptureSourceType);
                        capturer.VideoBitrate = captureProps.EncodingSettings.VideoBitrate;
                        capturer.AudioBitrate = captureProps.EncodingSettings.AudioBitrate;
@@ -248,18 +255,43 @@ namespace LongoMatch.Gui
                        res = md.Run();
                        md.Destroy();
                        if(res == (int)ResponseType.Yes) {
-                               md = new MessageDialog((Gtk.Window)this.Toplevel, DialogFlags.Modal, 
MessageType.Info, ButtonsType.None,
-                                                      Catalog.GetString("Finalizing file. This can take a 
while"));
-                               md.Show();
                                Stop();
-                               md.Destroy();
                                recbutton.Visible = true;
                                pausebutton.Visible = false;
                                stopbutton.Visible = false;
+                               
+                               RemuxOutputFile (captureProps.EncodingSettings);
+                               
                                if(CaptureFinished != null)
                                        CaptureFinished(this, new EventArgs());
                        }
                }
+               
+               void RemuxOutputFile (EncodingSettings settings) {
+                       VideoMuxerType muxer;
+                               
+                       /* We need to remux to the original format */
+                       muxer = settings.EncodingProfile.Muxer;
+                       if (muxer == VideoMuxerType.Avi || muxer == VideoMuxerType.Mp4) {
+                               string outFile = settings.OutputFile;
+                               string tmpFile = settings.OutputFile;
+                               
+                               while (System.IO.File.Exists (tmpFile)) {
+                                       tmpFile = tmpFile + ".tmp";
+                               }
+                               
+                               System.IO.File.Move (outFile, tmpFile);
+                               Remuxer remuxer = new Remuxer(tmpFile, outFile, muxer);
+                               
+                               /* Remuxing suceed, delete old file */
+                               if (remuxer.Remux(this.Toplevel as Gtk.Window) == outFile) {
+                                       System.IO.File.Delete (tmpFile);
+                               } else {
+                                       System.IO.File.Delete (outFile);
+                                       System.IO.File.Move (tmpFile, outFile);
+                               }
+                       }
+               }
 
                protected virtual void OnTick(int ellapsedTime) {
                        timelabel.Text = "Time: " + TimeString.MSecondsToSecondsString(CurrentTime);
diff --git a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs 
b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
index 7d34441..f7ff0dc 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
@@ -428,8 +428,8 @@ namespace LongoMatch.Gui.Component
                        sizecombobox.Active = 0;
 
                        encProfileList = new ListStore(typeof(string), typeof (EncodingProfile));
-                       encProfileList.AppendValues(EncodingProfiles.MatroskaH264.Name, 
EncodingProfiles.MatroskaH264);
-                       encProfileList.AppendValues(EncodingProfiles.MatroskaMpeg4.Name, 
EncodingProfiles.MatroskaMpeg4);
+                       encProfileList.AppendValues(EncodingProfiles.MP4.Name, EncodingProfiles.MP4);
+                       encProfileList.AppendValues(EncodingProfiles.Avi.Name, EncodingProfiles.Avi);
                        encProfileList.AppendValues(EncodingProfiles.WebM.Name, EncodingProfiles.WebM);
                        videoformatcombobox.Model = encProfileList;
                        videoformatcombobox.Active = 0;
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
index d8307ba..e1d7fb3 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
@@ -58,7 +58,7 @@
     <File subtype="Directory" buildaction="Compile" name="Remuxer" />
     <File subtype="Code" buildaction="Compile" name="Remuxer/GstRemuxer.cs" />
     <File subtype="Code" buildaction="Compile" name="Remuxer/ObjectManager.cs" />
-    <File subtype="Code" buildaction="Compile" name="Utils/AsfRemuxer.cs" />
+    <File subtype="Code" buildaction="Compile" name="Utils/Remuxer.cs" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="libcesarplayer" />
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index 9280c6b..075d19e 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -19,7 +19,7 @@ SOURCES = \
        Player/ObjectManager.cs \
        Remuxer/GstRemuxer.cs \
        Remuxer/ObjectManager.cs \
-       Utils/AsfRemuxer.cs \
+       Utils/Remuxer.cs \
        Utils/FramesCapturer.cs \
        Utils/GStreamer.cs \
        Utils/IMetadataReader.cs \
diff --git a/LongoMatch.Multimedia/MultimediaFactory.cs b/LongoMatch.Multimedia/MultimediaFactory.cs
index 6cd201b..b3dbed7 100644
--- a/LongoMatch.Multimedia/MultimediaFactory.cs
+++ b/LongoMatch.Multimedia/MultimediaFactory.cs
@@ -114,8 +114,8 @@ namespace LongoMatch.Video
                        }
                }
                
-               public IRemuxer GetRemuxer(string inputFile, string outputFile) {
-                       return new GstRemuxer (inputFile, outputFile);
+               public IRemuxer GetRemuxer(string inputFile, string outputFile, VideoMuxerType muxer) {
+                       return new GstRemuxer (inputFile, outputFile, muxer);
                }
                
                public MediaFile DiscoverFile (string file) {
diff --git a/LongoMatch.Multimedia/Remuxer/GstRemuxer.cs b/LongoMatch.Multimedia/Remuxer/GstRemuxer.cs
index cc036bc..98406a4 100644
--- a/LongoMatch.Multimedia/Remuxer/GstRemuxer.cs
+++ b/LongoMatch.Multimedia/Remuxer/GstRemuxer.cs
@@ -34,16 +34,17 @@ namespace LongoMatch.Video.Remuxer {
                public event LongoMatch.Handlers.ErrorHandler Error;
 
                [DllImport("libcesarplayer.dll")]
-               static extern unsafe IntPtr gst_remuxer_new(IntPtr input_file, IntPtr output_file, out IntPtr 
err);
+               static extern unsafe IntPtr gst_remuxer_new(IntPtr input_file, IntPtr output_file, 
VideoMuxerType muxer, out IntPtr err);
 
-               public unsafe GstRemuxer(string inputFile, string outputFile) : base(IntPtr.Zero)
+               public unsafe GstRemuxer(string inputFile, string outputFile, VideoMuxerType muxer) : 
base(IntPtr.Zero)
                {
                        if(GetType() != typeof(GstRemuxer)) {
                                throw new InvalidOperationException("Can't override this constructor.");
                        }
                        IntPtr error = IntPtr.Zero;
                        Raw = gst_remuxer_new(GLib.Marshaller.StringToPtrGStrdup(inputFile),
-                                                     GLib.Marshaller.StringToPtrGStrdup(outputFile), out 
error);
+                                             GLib.Marshaller.StringToPtrGStrdup(outputFile),
+                                             muxer, out error);
                        if(error != IntPtr.Zero) throw new GLib.GException(error);
                        
                        PercentCompleted += delegate(object o, PercentCompletedArgs args) {
diff --git a/LongoMatch.Multimedia/Utils/AsfRemuxer.cs b/LongoMatch.Multimedia/Utils/Remuxer.cs
similarity index 63%
rename from LongoMatch.Multimedia/Utils/AsfRemuxer.cs
rename to LongoMatch.Multimedia/Utils/Remuxer.cs
index 99e0ce7..90eec86 100644
--- a/LongoMatch.Multimedia/Utils/AsfRemuxer.cs
+++ b/LongoMatch.Multimedia/Utils/Remuxer.cs
@@ -23,12 +23,12 @@ using GLib;
 using Gtk;
 
 using LongoMatch.Interfaces.Multimedia;
+using LongoMatch.Common;
 
 namespace LongoMatch.Video.Utils
 {
-       public class AsfRemuxer
+       public class Remuxer
        {
-               static string[] EXTENSIONS =  {"asf", "wmv"};
                string filepath;
                string newFilepath;
                Dialog dialog;
@@ -37,27 +37,38 @@ namespace LongoMatch.Video.Utils
                IMultimediaToolkit multimedia;
                uint timeout;
                bool cancelled;
+               VideoMuxerType muxer;
+               Window parent;
                
-               public AsfRemuxer (string filepath)
+               public Remuxer (string filepath, string newFilepath, VideoMuxerType targetMuxer)
                {
                        this.filepath = filepath;
+                       this.newFilepath = newFilepath;
                        this.multimedia = new MultimediaFactory();
-                       newFilepath = Path.ChangeExtension(filepath, "webm");
+                       this.muxer = targetMuxer;
                }
                
                public string Remux(Window parent) {
+                       VBox box;
+                       Label label;
                        Button cancellButton;
                        
+                       this.parent = parent;
+                       
                        /* Create the dialog */
                        dialog = new Dialog(Catalog.GetString("Remuxing file..."), parent, DialogFlags.Modal);
                        dialog.AllowGrow = false;
                        dialog.AllowShrink = false;
                        dialog.Deletable = false;
                        
-                       /* Add a progress bar */
+                       /* Add label and progress bar */
+                       box = new VBox();
+                       label = new Label(Catalog.GetString("Remuxing file, this might take while..."));
+                       box.PackStart(label);
                        pb = new ProgressBar();
-                       pb.Show();
-                       dialog.VBox.Add(pb);
+                       box.PackStart(pb);
+                       box.ShowAll();
+                       dialog.VBox.Add(box);
                        
                        /* Add a button to cancell the task */
                        cancellButton = new Button("gtk-cancel");
@@ -69,8 +80,9 @@ namespace LongoMatch.Video.Utils
                        pb.Pulse();
                        timeout = GLib.Timeout.Add (1000, new GLib.TimeoutHandler (Update));
                        
-                       remuxer = multimedia.GetRemuxer(filepath, newFilepath);
-                       remuxer.Progress += HandleRemuxerProgress;;
+                       remuxer = multimedia.GetRemuxer(filepath, newFilepath, muxer);
+                       remuxer.Progress += HandleRemuxerProgress;
+                       remuxer.Error += HandleRemuxerError;
                        remuxer.Start();
                        
                        /* Wait until the thread call Destroy on the dialog */
@@ -78,6 +90,16 @@ namespace LongoMatch.Video.Utils
                        return cancelled ? null : newFilepath;
                }
 
+               void HandleRemuxerError (object o, string error)
+               {
+                       Cancel();
+                       MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error,
+                                                            ButtonsType.Ok,
+                                                            Catalog.GetString("Error remuxing file:" + "\n" 
+ error));
+                       md.Run();
+                       md.Destroy();
+               }
+
                void HandleRemuxerProgress (float progress)
                {
                        if (progress == 1) {
@@ -85,6 +107,24 @@ namespace LongoMatch.Video.Utils
                        }
                }
                
+               static protected string GetExtension (VideoMuxerType muxer) {
+                       switch (muxer) {
+                       case VideoMuxerType.Avi:
+                               return "avi";
+                       case VideoMuxerType.Matroska:
+                               return "mkv";
+                       case VideoMuxerType.Mp4:
+                               return "mp4";
+                       case VideoMuxerType.MpegPS:
+                               return "mpeg";
+                       case VideoMuxerType.Ogg:
+                               return "ogg";
+                       case VideoMuxerType.WebM:
+                               return "webm";
+                       }
+                       throw new Exception("Muxer format not supported");
+               }
+               
                private bool Update() {
                        pb.Pulse();                     
                        return true;
@@ -99,13 +139,7 @@ namespace LongoMatch.Video.Utils
                        cancelled = true;
                        Stop();
                }
-               
-               public static bool FileIsAsf(string filepath) {
-                       string extension = Path.GetExtension(filepath).Replace(".", "").ToLower();
-                       var extensions = new List<string> (AsfRemuxer.EXTENSIONS);
-                       return extensions.Contains(extension);
-               }
-               
+       
                public static bool AskForConversion(Window parent) {
                        bool ret;
                        MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Question,
@@ -120,4 +154,22 @@ namespace LongoMatch.Video.Utils
                        return ret;
                }
        }
+       
+       public class AsfRemuxer: Remuxer
+       {
+               static string[] EXTENSIONS = {"asf", "wmv"};
+               
+               public AsfRemuxer (string filepath): base(filepath,
+                                                         Path.ChangeExtension(filepath, 
GetExtension(VideoMuxerType.Matroska)),
+                                                         VideoMuxerType.Matroska)
+               {
+               }
+               
+               public static bool FileIsAsf(string filepath) {
+                       string extension = Path.GetExtension(filepath).Replace(".", "").ToLower();
+                       var extensions = new List<string> (AsfRemuxer.EXTENSIONS);
+                       return extensions.Contains(extension);
+               }
+               
+       }
 }
\ No newline at end of file
diff --git a/libcesarplayer/gst-remuxer.c b/libcesarplayer/gst-remuxer.c
index 166996b..36b8261 100644
--- a/libcesarplayer/gst-remuxer.c
+++ b/libcesarplayer/gst-remuxer.c
@@ -351,6 +351,9 @@ gst_remuxer_have_type_cb (GstElement *typefind, guint prob,
   } else if (g_strrstr (mime, "video/x-ms-asf")) {
     GST_INFO_OBJECT (remuxer, "Using asfdemux as demuxer");
     demuxer = gst_element_factory_make ("asfdemux", NULL);
+  } else if (g_strrstr (mime, "video/x-matroska")) {
+    GST_INFO_OBJECT (remuxer, "Using mastroskademux as demuxer");
+    demuxer = gst_element_factory_make ("matroskademux", NULL);
   } else if (g_strrstr (mime, "video/mpeg")) {
     gboolean sysstream;
 
@@ -507,7 +510,8 @@ gst_remuxer_cancel (GstRemuxer * remuxer)
 }
 
 GstRemuxer *
-gst_remuxer_new (gchar * input_file, gchar *output_file, GError ** err)
+gst_remuxer_new (gchar * input_file, gchar *output_file,
+    VideoMuxerType muxer, GError ** err)
 {
   GstRemuxer *remuxer = NULL;
 
@@ -522,7 +526,7 @@ gst_remuxer_new (gchar * input_file, gchar *output_file, GError ** err)
 
   remuxer->priv->input_file = input_file;
   remuxer->priv->output_file = output_file;
-  remuxer->priv->video_muxer_type = VIDEO_MUXER_MATROSKA;
+  remuxer->priv->video_muxer_type = muxer;
 
   gst_remuxer_initialize (remuxer);
 
diff --git a/libcesarplayer/gst-remuxer.h b/libcesarplayer/gst-remuxer.h
index e3818bd..fd7becb 100644
--- a/libcesarplayer/gst-remuxer.h
+++ b/libcesarplayer/gst-remuxer.h
@@ -64,7 +64,8 @@ struct _GstRemuxer
 EXPORT GType gst_remuxer_get_type (void) G_GNUC_CONST;
 
 EXPORT void gst_remuxer_init_backend (int *argc, char ***argv);
-EXPORT GstRemuxer *gst_remuxer_new (gchar *in_filename, gchar *out_filename, GError ** err);
+EXPORT GstRemuxer *gst_remuxer_new (gchar *in_filename, gchar *out_filename,
+                                    VideoMuxerType muxer, GError ** err);
 EXPORT void gst_remuxer_start (GstRemuxer * remuxer);
 EXPORT void gst_remuxer_cancel (GstRemuxer * remuxer);
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index caf9361..1942b69 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -199,7 +199,7 @@ LongoMatch.Multimedia/Interfaces/IPlayer.cs
 LongoMatch.Multimedia/MultimediaFactory.cs
 LongoMatch.Multimedia/Player/GstPlayer.cs
 LongoMatch.Multimedia/Player/ObjectManager.cs
-LongoMatch.Multimedia/Utils/AsfRemuxer.cs
+LongoMatch.Multimedia/Utils/Remuxer.cs
 LongoMatch.Multimedia/Utils/FramesCapturer.cs
 LongoMatch.Multimedia/Utils/GStreamer.cs
 LongoMatch.Multimedia/Utils/IMetadataReader.cs


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