[longomatch] Do remuxing based on the container and include flv
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Do remuxing based on the container and include flv
- Date: Wed, 26 Jun 2013 09:55:41 +0000 (UTC)
commit 1404b9d5a12c27fa8f05deeee8c5da763097a4bc
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Jun 26 11:55:00 2013 +0200
Do remuxing based on the container and include flv
.../Interfaces/Multimedia/IMultimediaToolkit.cs | 2 +-
LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs | 3 +-
.../Gui}/Utils/Remuxer.cs | 56 +++----
.../LongoMatch.GUI.Multimedia.mdp | 2 +
LongoMatch.GUI.Multimedia/Makefile.am | 3 +-
.../Gui/Component/ProjectDetailsWidget.cs | 33 ++---
LongoMatch.Multimedia/LongoMatch.Multimedia.mdp | 7 +-
LongoMatch.Multimedia/Makefile.am | 3 +-
LongoMatch.Multimedia/MultimediaFactory.cs | 10 +-
LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs | 105 +++++++++++++
LongoMatch.Multimedia/Utils/GStreamer.cs | 15 ++
LongoMatch.Multimedia/Utils/MpegRemuxer.cs | 157 --------------------
12 files changed, 177 insertions(+), 219 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
b/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
index 49c9463..6849890 100644
--- a/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
+++ b/LongoMatch.Core/Interfaces/Multimedia/IMultimediaToolkit.cs
@@ -31,7 +31,7 @@ namespace LongoMatch.Interfaces.Multimedia
IFramesCapturer GetFramesCapturer();
- IRemuxer GetRemuxer(string inputFile, string outputFile, VideoMuxerType muxer);
+ IRemuxer GetRemuxer(MediaFile 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 3688e4c..de6f970 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -283,7 +283,8 @@ namespace LongoMatch.Gui
}
System.IO.File.Move (outFile, tmpFile);
- Remuxer remuxer = new Remuxer(tmpFile, outFile, muxer);
+ Remuxer remuxer = new Remuxer(PreviewMediaFile.DiscoverFile(tmpFile),
+ outFile, muxer);
/* Remuxing suceed, delete old file */
if (remuxer.Remux(this.Toplevel as Gtk.Window) == outFile) {
diff --git a/LongoMatch.Multimedia/Utils/Remuxer.cs b/LongoMatch.GUI.Multimedia/Gui/Utils/Remuxer.cs
similarity index 81%
rename from LongoMatch.Multimedia/Utils/Remuxer.cs
rename to LongoMatch.GUI.Multimedia/Gui/Utils/Remuxer.cs
index 90eec86..176397d 100644
--- a/LongoMatch.Multimedia/Utils/Remuxer.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/Utils/Remuxer.cs
@@ -24,13 +24,14 @@ using Gtk;
using LongoMatch.Interfaces.Multimedia;
using LongoMatch.Common;
+using LongoMatch.Store;
namespace LongoMatch.Video.Utils
{
public class Remuxer
{
- string filepath;
- string newFilepath;
+ MediaFile inputFile;
+ string outputFilepath;
Dialog dialog;
ProgressBar pb;
IRemuxer remuxer;
@@ -40,12 +41,19 @@ namespace LongoMatch.Video.Utils
VideoMuxerType muxer;
Window parent;
- public Remuxer (string filepath, string newFilepath, VideoMuxerType targetMuxer)
+ public Remuxer (MediaFile inputFile, string outputFilepath = null,
+ VideoMuxerType muxer = VideoMuxerType.Mp4)
{
- this.filepath = filepath;
- this.newFilepath = newFilepath;
+ this.inputFile = inputFile;
+ this.muxer = muxer;
+
+ if (outputFilepath != null) {
+ this.outputFilepath = outputFilepath;
+ } else {
+ this.outputFilepath = Path.ChangeExtension(inputFile.FilePath,
+ GetExtension(muxer));
+ }
this.multimedia = new MultimediaFactory();
- this.muxer = targetMuxer;
}
public string Remux(Window parent) {
@@ -80,30 +88,34 @@ namespace LongoMatch.Video.Utils
pb.Pulse();
timeout = GLib.Timeout.Add (1000, new GLib.TimeoutHandler (Update));
- remuxer = multimedia.GetRemuxer(filepath, newFilepath, muxer);
+ remuxer = multimedia.GetRemuxer(inputFile, outputFilepath, muxer);
remuxer.Progress += HandleRemuxerProgress;
remuxer.Error += HandleRemuxerError;
remuxer.Start();
/* Wait until the thread call Destroy on the dialog */
dialog.Run();
- return cancelled ? null : newFilepath;
+ return cancelled ? null : outputFilepath;
}
-
- void HandleRemuxerError (object o, string error)
- {
- Cancel();
+
+ void Error (string error) {
MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Error,
ButtonsType.Ok,
Catalog.GetString("Error remuxing file:" + "\n"
+ error));
md.Run();
md.Destroy();
+ Cancel();
+ }
+
+ void HandleRemuxerError (object o, string error)
+ {
+ Application.Invoke (delegate {Error (error);});
}
void HandleRemuxerProgress (float progress)
{
if (progress == 1) {
- Stop ();
+ Application.Invoke (delegate {Stop ();});
}
}
@@ -154,22 +166,4 @@ 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/LongoMatch.GUI.Multimedia/LongoMatch.GUI.Multimedia.mdp
b/LongoMatch.GUI.Multimedia/LongoMatch.GUI.Multimedia.mdp
index d788493..a289b13 100644
--- a/LongoMatch.GUI.Multimedia/LongoMatch.GUI.Multimedia.mdp
+++ b/LongoMatch.GUI.Multimedia/LongoMatch.GUI.Multimedia.mdp
@@ -27,6 +27,8 @@
<File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.PlayerBin.cs" />
<File subtype="Code" buildaction="Compile" name="Gui/PlayerCapturerBin.cs" />
<File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.PlayerCapturerBin.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Gui/Utils" />
+ <File subtype="Code" buildaction="Compile" name="Gui/Utils/Remuxer.cs" />
</Contents>
<MonoDevelop.Autotools.MakefileInfo RelativeMakefileName="Makefile.am" RelativeConfigureInPath="../">
<BuildFilesVar Name="FILES" />
diff --git a/LongoMatch.GUI.Multimedia/Makefile.am b/LongoMatch.GUI.Multimedia/Makefile.am
index 757d5ba..a8436ad 100644
--- a/LongoMatch.GUI.Multimedia/Makefile.am
+++ b/LongoMatch.GUI.Multimedia/Makefile.am
@@ -12,7 +12,8 @@ SOURCES = \
Gui/CapturerBin.cs \
Gui/PlayerBin.cs \
Gui/PlayerCapturerBin.cs \
- Gui/VolumeWindow.cs
+ Gui/VolumeWindow.cs \
+ Gui/Utils/Remuxer.cs
RESOURCES = \
gtk-gui/objects.xml \
diff --git a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
index 8c19ebf..ee02fea 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using Gtk;
+using Mono.Unix;
using LongoMatch.Common;
using LongoMatch.Gui.Dialog;
using LongoMatch.Gui.Popup;
@@ -29,9 +30,9 @@ using LongoMatch.Interfaces;
using LongoMatch.Store;
using LongoMatch.Store.Templates;
using LongoMatch.Video.Utils;
-using Mono.Unix;
using LongoMatch.Gui.Helpers;
using Misc = LongoMatch.Gui.Helpers.Misc;
+using LongoMatch.Multimedia.Utils;
namespace LongoMatch.Gui.Component
{
@@ -470,22 +471,6 @@ namespace LongoMatch.Gui.Component
string filename = fChooser.Filename;
fChooser.Destroy();
- if (MpegRemuxer.FileIsMpeg(filename) &&
- MpegRemuxer.AskForConversion(this.Toplevel as Gtk.Window)) {
- var remux = new MpegRemuxer(filename);
- var newFilename = remux.Remux(this.Toplevel as Gtk.Window);
- if (newFilename != null)
- filename = newFilename;
- }
-
- if (AsfRemuxer.FileIsAsf(filename) &&
- MpegRemuxer.AskForConversion(this.Toplevel as Gtk.Window)) {
- var remux = new AsfRemuxer(filename);
- var newFilename = remux.Remux(this.Toplevel as Gtk.Window);
- if (newFilename != null)
- filename = newFilename;
- }
-
try {
md = new MessageDialog((Gtk.Window)this.Toplevel,
DialogFlags.Modal,
@@ -499,9 +484,17 @@ namespace LongoMatch.Gui.Component
throw new Exception(Catalog.GetString("This file
doesn't contain a video stream."));
if(mFile.HasVideo && mFile.Length == 0)
throw new Exception(Catalog.GetString("This file
contains a video stream but its length is 0."));
-
-
- fileEntry.Text = filename;
+ if (GStreamer.FileNeedsRemux(mFile)) {
+ string q = Catalog.GetString("The file you are trying
to load is not properly supported. " +
+ "Would you like to
convert it into a more suitable format?");
+ if (MessagesHelpers.QuestionMessage (this, q)) {
+ var remux = new Remuxer(mFile);
+ var newFilename = remux.Remux(this.Toplevel
as Gtk.Window);
+ if (newFilename != null)
+ mFile = PreviewMediaFile.DiscoverFile
(newFilename);
+ }
+ }
+ fileEntry.Text = mFile.FilePath;
}
catch(Exception ex) {
MessagesHelpers.ErrorMessage (this, ex.Message);
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
index 08ba8b1..8a98d9f 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
@@ -31,7 +31,6 @@
<File subtype="Code" buildaction="Compile" name="Utils/FramesCapturer.cs" />
<File subtype="Code" buildaction="Compile" name="Utils/IMetadataReader.cs" />
<File subtype="Code" buildaction="Compile" name="Utils/PreviewMediaFile.cs" />
- <File subtype="Code" buildaction="Compile" name="Utils/MpegRemuxer.cs" />
<File subtype="Directory" buildaction="Compile" name="Utils" />
<File subtype="Directory" buildaction="Compile" name="Common" />
<File subtype="Directory" buildaction="Compile" name="Common" />
@@ -58,19 +57,19 @@
<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/Remuxer.cs" />
<File subtype="Directory" buildaction="Compile" name="Converter" />
<File subtype="Code" buildaction="Compile" name="Converter/GstVideoConverter.cs" />
<File subtype="Code" buildaction="Compile" name="Converter/ObjectManager.cs" />
<File subtype="Code" buildaction="Compile" name="Utils/Seeker.cs" />
+ <File subtype="Code" buildaction="Compile" name="Remuxer/MpegRemuxer.cs" />
</Contents>
<References>
<ProjectReference type="Project" localcopy="True" refto="libcesarplayer" />
- <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
<ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
- <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
<ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=0738eb9f132ed756" />
<ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Gac" localcopy="False" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
+ <ProjectReference type="Gac" localcopy="False" refto="gdk-sharp, Version=2.12.0.0, Culture=neutral,
PublicKeyToken=35e10195dab3c99f" />
</References>
</Project>
\ No newline at end of file
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index 978c4cc..af4e30d 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -20,12 +20,11 @@ SOURCES = \
Player/GstPlayer.cs \
Player/ObjectManager.cs \
Remuxer/GstRemuxer.cs \
+ Remuxer/MpegRemuxer.cs \
Remuxer/ObjectManager.cs \
- Utils/Remuxer.cs \
Utils/FramesCapturer.cs \
Utils/GStreamer.cs \
Utils/IMetadataReader.cs \
- Utils/MpegRemuxer.cs \
Utils/PreviewMediaFile.cs \
Utils/Seeker.cs \
Utils/TimeString.cs \
diff --git a/LongoMatch.Multimedia/MultimediaFactory.cs b/LongoMatch.Multimedia/MultimediaFactory.cs
index 80413b1..75253a8 100644
--- a/LongoMatch.Multimedia/MultimediaFactory.cs
+++ b/LongoMatch.Multimedia/MultimediaFactory.cs
@@ -119,8 +119,14 @@ namespace LongoMatch.Video
}
}
- public IRemuxer GetRemuxer(string inputFile, string outputFile, VideoMuxerType muxer) {
- return new GstRemuxer (inputFile, outputFile, muxer);
+ public IRemuxer GetRemuxer(MediaFile inputFile, string outputFile, VideoMuxerType muxer) {
+ if (inputFile.Container == GStreamer.MPEG1_PS ||
+ inputFile.Container == GStreamer.MPEG2_PS ||
+ inputFile.Container == GStreamer.MPEG2_TS) {
+ return new MpegRemuxer (inputFile.FilePath, outputFile);
+ } else {
+ return new GstRemuxer (inputFile.FilePath, outputFile, muxer);
+ }
}
public MediaFile DiscoverFile (string file) {
diff --git a/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs b/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs
new file mode 100644
index 0000000..e93b7b7
--- /dev/null
+++ b/LongoMatch.Multimedia/Remuxer/MpegRemuxer.cs
@@ -0,0 +1,105 @@
+//
+// Copyright (C) 2011 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Threading;
+using Mono.Unix;
+using GLib;
+using LongoMatch.Store;
+using LongoMatch.Interfaces.Multimedia;
+using LongoMatch.Handlers;
+using Gtk;
+
+namespace LongoMatch.Video.Remuxer
+{
+ public class MpegRemuxer: IRemuxer
+ {
+ public event ErrorHandler Error;
+ public event ProgressHandler Progress;
+ const string FORMAT = "mp4";
+ const string BACKUP_FORMAT = "mkv";
+ string inputFilepath;
+ string outputFilepath;
+ System.Threading.Thread remuxThread;
+
+ public MpegRemuxer (string inputFilepath, string outputFilepath)
+ {
+ this.inputFilepath = inputFilepath;
+ this.outputFilepath = outputFilepath;
+ }
+
+ public void Start() {
+ remuxThread = new System.Threading.Thread(new ThreadStart(RemuxTask));
+ remuxThread.Start();
+ }
+
+ public void Cancel() {
+ if (remuxThread.IsAlive)
+ remuxThread.Interrupt();
+ try {
+ File.Delete (this.outputFilepath);
+ } catch {
+ }
+ }
+
+ private int LaunchRemuxer () {
+ int ret = 1;
+
+ ProcessStartInfo startInfo = new ProcessStartInfo();
+ startInfo.CreateNoWindow = true;
+ if (System.Environment.OSVersion.Platform != PlatformID.Win32NT) {
+ startInfo.UseShellExecute = false;
+ }
+ startInfo.FileName = "avconv";
+ startInfo.Arguments = String.Format("-i {0} -vcodec copy -acodec copy -y -sn {1} ",
+ inputFilepath, outputFilepath);
+
+ using (System.Diagnostics.Process exeProcess =
System.Diagnostics.Process.Start(startInfo))
+ {
+ exeProcess.WaitForExit();
+ ret = exeProcess.ExitCode;
+ }
+ return ret;
+ }
+
+ private void RemuxTask(){
+ int ret;
+ ret = LaunchRemuxer ();
+ if (ret != 0) {
+ /* Try with the backup format instead */
+ System.IO.File.Delete (outputFilepath);
+ outputFilepath = Path.ChangeExtension(inputFilepath, BACKUP_FORMAT);
+ ret = LaunchRemuxer ();
+ }
+
+ if (ret != 0) {
+ if (Error != null) {
+ Application.Invoke (delegate {Error (this, "Unkown error");});
+ }
+ } else {
+ if (Progress != null) {
+ Application.Invoke (delegate {Progress (1);});
+ Progress (1);
+ }
+ }
+ }
+ }
+}
+
diff --git a/LongoMatch.Multimedia/Utils/GStreamer.cs b/LongoMatch.Multimedia/Utils/GStreamer.cs
index 8211223..f4f16bd 100644
--- a/LongoMatch.Multimedia/Utils/GStreamer.cs
+++ b/LongoMatch.Multimedia/Utils/GStreamer.cs
@@ -22,6 +22,7 @@ using Gtk;
using LongoMatch.Video;
using Mono.Unix;
using LongoMatch.Common;
+using LongoMatch.Store;
namespace LongoMatch.Multimedia.Utils
{
@@ -35,6 +36,12 @@ namespace LongoMatch.Multimedia.Utils
[DllImport("libgstreamer-0.10.dll") /* willfully unmapped */ ]
static extern void gst_object_unref (IntPtr raw);
+ public const string MPEG1_PS = "MPEG-1 System Stream";
+ public const string MPEG2_PS = "MPEG-2 System Stream";
+ public const string MPEG2_TS = "MPEG-2 Transport Stream";
+ public const string ASF = "Advanced Streaming Format (ASF)";
+ public const string FLV = "Flash";
+
private const string GST_DIRECTORY = ".gstreamer-0.10";
private const string REGISTRY_PATH = "registry.bin";
@@ -57,6 +64,14 @@ namespace LongoMatch.Multimedia.Utils
return true;
}
+ public static bool FileNeedsRemux (MediaFile file) {
+ if (file.Container == MPEG1_PS || file.Container == MPEG2_PS ||
+ file.Container == MPEG2_TS || file.Container == FLV ||
+ file.Container == ASF)
+ return true;
+ return false;
+ }
+
private static void SetUpEnvironment () {
string gstDirectory, registryPath;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]