-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e579df0
commit 547519b
Showing
13 changed files
with
833 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.33502.453 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebcamSetting", "WebcamSetting\WebcamSetting.csproj", "{22CE3334-7343-4D6E-985A-045E530E18B5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{22CE3334-7343-4D6E-985A-045E530E18B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{22CE3334-7343-4D6E-985A-045E530E18B5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{22CE3334-7343-4D6E-985A-045E530E18B5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{22CE3334-7343-4D6E-985A-045E530E18B5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9B533FF0-55F0-4604-89AD-3C538309F038} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" /> | ||
</startup> | ||
</configuration> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using AForge.Video; | ||
using AForge.Video.DirectShow; | ||
using System; | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace WebcamSetting | ||
{ | ||
public partial class Form1 : Form | ||
{ | ||
public Form1() | ||
{ | ||
InitializeComponent(); | ||
panel1.BackColor = Color.FromArgb(0, Color.Black); | ||
comboBox1.SelectionChangeCommitted += new EventHandler(comboBox1_SelectionChangeCommitted); | ||
comboBox2.SelectionChangeCommitted += new EventHandler(comboBox2_SelectionChangeCommitted); | ||
button1.Click += new EventHandler(button1_Click); | ||
|
||
|
||
GetCamera(); | ||
|
||
} | ||
|
||
public event EventHandler SelectionChangeCommitted; | ||
FilterInfoCollection filterInfoCollection; | ||
VideoCaptureDevice videoCaptureDevice; | ||
|
||
string videoSourceName; | ||
|
||
private void GetCamera() | ||
{ | ||
comboBox1.Items.Add("Select Camera"); | ||
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice); | ||
foreach (FilterInfo filterInfo in filterInfoCollection) | ||
{ | ||
comboBox1.Items.Add(filterInfo.Name); | ||
} | ||
comboBox1.SelectedIndex = 0; | ||
videoSourceName = comboBox1.SelectedItem.ToString(); | ||
|
||
} | ||
|
||
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) | ||
{ | ||
|
||
videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[comboBox1.SelectedIndex - 1].MonikerString); | ||
videoSourceName = comboBox1.SelectedItem.ToString(); | ||
videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame; | ||
videoCaptureDevice.Start(); | ||
|
||
foreach (var resolution in videoCaptureDevice.VideoCapabilities) | ||
{ | ||
comboBox2.Items.Add(resolution.FrameSize.Width + "x" + resolution.FrameSize.Height); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e) | ||
{ | ||
videoCaptureDevice.Stop(); | ||
videoCaptureDevice.VideoResolution = videoCaptureDevice.VideoCapabilities[comboBox2.SelectedIndex]; | ||
videoCaptureDevice.Start(); | ||
} | ||
|
||
private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs) | ||
{ | ||
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); | ||
} | ||
|
||
//On form close | ||
|
||
//Run Bat file to setting webcam | ||
private void button1_Click(object sender, EventArgs e) | ||
{ | ||
Setting(); | ||
} | ||
|
||
|
||
private void Setting() | ||
{ | ||
try | ||
{ | ||
if (videoCaptureDevice.IsRunning != null && videoCaptureDevice.IsRunning) | ||
{ | ||
//check if setting.bat is exist at Documents/WebcamSetting/setting.bat | ||
if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\setting.bat")) | ||
{ | ||
|
||
ExcecuteBat(); | ||
} | ||
else | ||
{ | ||
//Show yes no dialog | ||
MessageBox.Show("setting.bat not found, do you want to create it?", "Warning", MessageBoxButtons.YesNo); | ||
//if not exist, create it | ||
Writebat(); | ||
//Run bat file | ||
|
||
} | ||
} | ||
else | ||
{ | ||
MessageBox.Show("Please select camera", "Warning", MessageBoxButtons.OK); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show("Please Select Camera", "Error", MessageBoxButtons.OK); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
private void Writebat() | ||
{ | ||
//Create new path file at Documents/WebcamSetting/setting.bat | ||
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\setting.bat"; | ||
|
||
//Create new folder at Documents/WebcamSetting | ||
System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting"); | ||
|
||
//Copy ffmpeg.exe to Documents/WebcamSetting/ffmpeg.exe | ||
System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WebcamSetting\\ffmpeg.exe", true); | ||
//Write bat file | ||
string[] lines = { "chcp 65001 > nul", "ffmpeg -f dshow -show_video_device_dialog true -i video=" + '"' + videoSourceName + '"' }; | ||
System.IO.File.WriteAllLines(path, lines); | ||
MessageBox.Show("Exported to " + path); | ||
|
||
} | ||
|
||
private void ExcecuteBat() | ||
{ | ||
try | ||
{ | ||
//get root path | ||
string path = AppDomain.CurrentDomain.BaseDirectory + "setting.bat"; | ||
//Open bat file | ||
System.Diagnostics.Process.Start(path); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show("File not found", "Error", MessageBoxButtons.OK); | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
Oops, something went wrong.