[chronojump] webcam play with ffmpeg instead of mplayer
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] webcam play with ffmpeg instead of mplayer
- Date: Tue, 13 Nov 2018 16:08:59 +0000 (UTC)
commit a93db4fe99b303a2880a0baeb883492cc76dac4b
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Nov 13 17:08:34 2018 +0100
webcam play with ffmpeg instead of mplayer
src/gui/chronojump.cs | 2 +-
src/webcam.cs | 2 +-
src/webcamFfmpeg.cs | 41 ++++++++++++++++++++++++++++++++++-------
src/webcamMplayer.cs | 10 +++++-----
4 files changed, 41 insertions(+), 14 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index e854849a..174dfe05 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -6105,7 +6105,7 @@ LogB.Debug("mc finished 5");
//Not used on encoder
private bool playVideo(string fileName, bool play)
{
- webcam = new WebcamMplayer ();
+ webcam = new WebcamFfmpeg (UtilAll.GetOSEnum());
Webcam.Result result = webcam.Play(fileName);
/*
diff --git a/src/webcam.cs b/src/webcam.cs
index 28feec38..bd877c22 100644
--- a/src/webcam.cs
+++ b/src/webcam.cs
@@ -97,7 +97,7 @@ public abstract class Webcam
protected Process process;
protected string videoDevice;
protected StreamWriter streamWriter;
- protected string captureExecutable = "";
+ protected string executable = "";
// Result struct holds the output, error and success operations. It's used to pass
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index 7d5ec6d3..2ee74fec 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -34,20 +34,26 @@ public class WebcamFfmpeg : Webcam
this.os = os;
this.videoDevice = videoDevice;
- captureExecutable = "ffmpeg";
+ executable = "ffmpeg";
if(os == UtilAll.OperatingSystems.WINDOWS)
- captureExecutable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
+ executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
Running = false;
}
/*
* constructor for Play
+ */
- public WebcamFfmpeg ()
+ public WebcamFfmpeg (UtilAll.OperatingSystems os)
{
+ this.os = os;
+
+ executable = "ffplay";
+ if(os == UtilAll.OperatingSystems.WINDOWS)
+ executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffplay.exe");
}
- */
+
public override Result CapturePrepare (CaptureTypes captureType)
{
@@ -59,7 +65,20 @@ public class WebcamFfmpeg : Webcam
public override Result Play(string filename)
{
- //only implemented on mplayer
+ if(process != null || filename == "")
+ return new Result (false, "");
+
+ List<string> parameters = createParametersPlay(filename);
+
+ process = new Process();
+ bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false);
+ if(! success)
+ {
+ process = null;
+ return new Result (false, "", programFfmpegNotInstalled);
+ }
+
+ Running = true;
return new Result (true, "");
}
public override bool Snapshot()
@@ -73,7 +92,7 @@ public class WebcamFfmpeg : Webcam
process = new Process();
List<string> parameters = createParametersOnlyCapture();
//List<string> parameters = createParametersCaptureAndDelayedView();
- bool success = ExecuteProcess.RunAtBackground (ref process, captureExecutable, parameters,
true); //redirectInput
+ bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true);
//redirectInput
if(! success)
{
streamWriter = null;
@@ -88,6 +107,14 @@ public class WebcamFfmpeg : Webcam
return new Result (true, "");
}
+ private List<string> createParametersPlay(string filename)
+ {
+ // ffplay out.mp4
+ List<string> parameters = new List<string>();
+ parameters.Insert (0, filename);
+ return parameters;
+ }
+
private List<string> createParametersOnlyCapture()
{
// ffmpeg -y -f v4l2 -framerate 30 -video_size 640x480 -input_format mjpeg -i /dev/video0
out.mp4
@@ -219,7 +246,7 @@ public class WebcamFfmpeg : Webcam
do {
LogB.Information("waiting 100 ms to end Ffmpeg");
System.Threading.Thread.Sleep(100);
- } while(ExecuteProcess.IsRunning3(processID, captureExecutable));
+ } while(ExecuteProcess.IsRunning3(processID, executable));
streamWriter = null;
process = null;
diff --git a/src/webcamMplayer.cs b/src/webcamMplayer.cs
index 11d49e41..74c3bd9a 100644
--- a/src/webcamMplayer.cs
+++ b/src/webcamMplayer.cs
@@ -37,7 +37,7 @@ public class WebcamMplayer : Webcam
public WebcamMplayer ()
{
- captureExecutable = "mplayer";
+ executable = "mplayer";
}
public override Result CapturePrepare (CaptureTypes captureType)
@@ -71,7 +71,7 @@ public class WebcamMplayer : Webcam
parameters.Insert (i ++, "screenshot=" +
Util.GetMplayerPhotoTempFileNamePre(videoDeviceToFilename()));
process = new Process();
- bool success = ExecuteProcess.RunAtBackground (ref process, captureExecutable, parameters,
true); //redirectInput
+ bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true);
//redirectInput
if(! success)
{
streamWriter = null;
@@ -87,7 +87,7 @@ public class WebcamMplayer : Webcam
parametersB[4] =
"driver=v4l2:gain=1:width=400:height=400:device=/dev/video1:fps=10:outfmt=rgb16";
parametersB[7] = "screenshot=/tmp/b/chronojump-last-photo";
Process processB = new Process();
- ExecuteProcess.RunAtBackground (processB, captureExecutable, parametersB, true);
//redirectInput
+ ExecuteProcess.RunAtBackground (processB, executable, parametersB, true); //redirectInput
*/
/*
* experimental double camera end
@@ -105,7 +105,7 @@ public class WebcamMplayer : Webcam
if(process != null || filename == "")
return new Result (false, "");
- string executable = "mplayer";
+ executable = "mplayer";
List<string> parameters = new List<string>();
parameters.Insert (0, filename);
//parameters.Insert (0, "-noborder"); //on X11 can be: title "Chronojump"". -noborder makes
no accept 's', or 'q'
@@ -262,7 +262,7 @@ public class WebcamMplayer : Webcam
private bool convertImagesToVideo()
{
- string executable = "ffmpeg";
+ executable = "ffmpeg";
List<string> parameters = new List<string>();
//ffmpeg -framerate 20 -y -i chronojump-last-photo%04d.png output.mp4
parameters.Insert (0, "-framerate");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]