Commit 50aa563c authored by Xavier de Blas's avatar Xavier de Blas

webcam get supported modes for mac (done!)

parent 56e1cac8
......@@ -3774,6 +3774,27 @@ Other</property>
<widget class="GtkVBox" id="vbox30">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<widget class="GtkButton" id="button_video_get_supported_modes">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_button_video_get_supported_modes_clicked" swapped="no"/>
<child>
<widget class="GtkLabel" id="label86">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Get supported modes</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_video_preview">
<property name="visible">True</property>
......@@ -3793,8 +3814,8 @@ Other</property>
<property name="stock">gtk-missing-image</property>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
......@@ -3816,7 +3837,7 @@ Other</property>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
</widget>
......
......@@ -784,6 +784,24 @@ public class PreferencesWindow
Util.TestSound = false;
}
//for mac and maybe windows, because in Linux it founds a default mode and it works
private void on_button_video_get_supported_modes_clicked (object o, EventArgs args)
{
string cameraCode = wd_list.GetCodeOfFullname(UtilGtk.ComboGetActive(combo_camera));
if(cameraCode == "")
return;
Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
cameraCode, "8000x8000", "8000"); //select and impossible mode just to get an error on mac, this error will give us the "Supported modes"
Webcam.Result result = webcamPlay.PlayPreviewNoBackgroundWantStdoutAndStderr();
//display the result (if any)
if(result.output != "")
new DialogMessage("Chronojump - Modes of this webcam",
Constants.MessageTypes.INFO, result.output);
}
private void on_button_video_preview_clicked (object o, EventArgs args)
{
string cameraCode = wd_list.GetCodeOfFullname(UtilGtk.ComboGetActive(combo_camera));
......
......@@ -145,6 +145,7 @@ public abstract class Webcam
public abstract Result PlayPreview();
public abstract Result PlayPreviewNoBackground();
public abstract Result PlayPreviewNoBackgroundWantStdoutAndStderr();
public abstract Result PlayFile(string filename);
......
......@@ -104,6 +104,26 @@ public class WebcamFfmpeg : Webcam
return new Result (true, "");
}
//used to know "Supported modes" on mac and maybe on windows
public override Result PlayPreviewNoBackgroundWantStdoutAndStderr() //experimental
{
List<string> parameters = createParametersPlayPreview();
process = new Process();
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, true);
//LogB.Information("Stdout: ", execute_result.stdout);
//LogB.Information("Stderr: ", execute_result.stderr);
LogB.Information("allOutput: ", execute_result.allOutput);
string parsed = parseSupportedModes(execute_result.allOutput);
if(! execute_result.success)
{
return new Result (false, parsed);
}
return new Result (true, parsed);
}
//snapshot in 2 seconds
public override bool Snapshot ()
......@@ -439,6 +459,100 @@ public class WebcamFfmpeg : Webcam
Running = false;
}
private string parseSupportedModes(string allOutput)
{
string str = "";
/*
* break the big string in \n strings
* https://stackoverflow.com/a/1547483
*/
string[] lines = allOutput.Split(
new[] { Environment.NewLine },
StringSplitOptions.None
);
bool started = false;
foreach(string l in lines)
{
LogB.Information("line: " + l);
//devices start after the videoDevString line
if(! started)
{
if(l.Contains("Supported modes"))
started = true;
continue;
}
str = parseSupportedMode(l) + "\nstdout";
//after the list of video devices comes the list of audio devices, skip it
if(l.Contains("Input/output"))
break;
}
return str;
}
private string parseSupportedMode(string l) //TODO: currently only for mac
{
if(! l.Contains("avfoundation"))
return "";
//parse this:
// [avfoundation @ 0x7f849a8be800] 1280x720@[23.999981 23.999981]fps
//use: https://regex101.com/r/lZ5mN8/50
// (\d+)x(\d+)@\[(\d+).(\d+)\s+
Match match = Regex.Match(l, @"(\d+)x(\d+)@\[(\d+).(\d+)\s+");
LogB.Information("match group count: ", match.Groups.Count.ToString());
if(match.Groups.Count != 5) //first is all match, second is the first int (width), last one is the decimals of the resolution
return "";
return string.Format("Resolution: {0}x{1}, Framerate: {2}.{3}",
match.Groups[1].Value, match.Groups[2].Value,
match.Groups[3].Value, match.Groups[4].Value);
}
/* test ParseSupportModes
*
WebcamFfmpeg.parseSupportedModes(@"[avfoundation @ 0x7f849a8be800] Supported modes:
[avfoundation @ 0x7f849a8be800] 160x120@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 160x120@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 160x120@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 160x120@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 176x144@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 176x144@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 176x144@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 176x144@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 320x240@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 320x240@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 320x240@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 320x240@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 352x288@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 352x288@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 352x288@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 352x288@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 640x480@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 640x480@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 640x480@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 640x480@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 960x540@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 960x540@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 960x540@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 960x540@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 1024x576@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 1024x576@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 1024x576@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 1024x576@[14.999993 14.999993]fps
[avfoundation @ 0x7f849a8be800] 1280x720@[29.970000 29.970000]fps
[avfoundation @ 0x7f849a8be800] 1280x720@[25.000000 25.000000]fps
[avfoundation @ 0x7f849a8be800] 1280x720@[23.999981 23.999981]fps
[avfoundation @ 0x7f849a8be800] 1280x720@[14.999993 14.999993]fps
0: Input/output error");
*/
/*
* protected methods
*/
......
......@@ -110,6 +110,11 @@ public class WebcamMplayer : Webcam
//not implemented
return new Result (false, "");
}
public override Result PlayPreviewNoBackgroundWantStdoutAndStderr() //experimental
{
//not implemented
return new Result (false, "");
}
public override Result PlayFile (string filename)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment