C# app을 사용하여 IP 카메라를 연결하는 동안 Aforge/Samples/Player에서 간단한 플레이어를 발견했습니다. 그냥 ip 문자열을 수정하여 광산을 추가해야합니다. admin : [email protected] : 81/videostream.cgi? rate = 11 MJPEG 비디오 스트림을 얻으려면. 컴파일시 나는 이라는 오류 메시지가 표시됩니다. 원격 서버가 오류 (401) 권한을 반환했습니다. Andre Kirillow가 MJPEGstream.cs 파일에 언급했습니다. 일부 카메라는 표준을 엄격하게 준수하지 않는 HTTP 헤더를 생성하고 .NET 예외를 발생시킵니다. 이 예외를 피하려면 useUnsafeHeaderParsing 구성 옵션 httpWebRequest을 설정해야합니다. 응용 프로그램 구성 파일을 사용하여 수행 할 수 있습니다.IP Camera 401 unauthorized Error
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
에 의해 제안 된대로이를 수행하는 방법은 두 가지가 있습니다. 위의 코드와 함께 .config 파일을 추가하고 또한 programmaticaly 않았다 그러나 동일한 오류가 지속됩니다. 그럼 난 사용하여 구축 된 최근 Sean Tearney에 의해 ISPY 소프트웨어를 사용 내가 일부 오픈 IP 카메라를 추가하고 거기에 비디오 스트림을 캡처 잘 작동하지만 내 카메라가 오류 401 반환 된
구글에서using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Reflection;
using System.Net.Configuration;
using System.Net;
namespace Player
{
public partial class MainForm : Form
{
private Stopwatch stopWatch = null;
// Class constructor
public MainForm()
{
InitializeComponent();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
CloseCurrentVideoSource();
}
// "Exit" menu item clicked
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
// Open local video capture device
private void localVideoCaptureDeviceToolStripMenuItem_Click(object sender, EventArgs e)
{
VideoCaptureDeviceForm form = new VideoCaptureDeviceForm();
if (form.ShowDialog(this) == DialogResult.OK)
{
// create video source
VideoCaptureDevice videoSource = form.VideoDevice;
// open it
OpenVideoSource(videoSource);
}
}
// Open video file using DirectShow
private void openVideofileusingDirectShowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
// create video source
FileVideoSource fileSource = new FileVideoSource(openFileDialog.FileName);
// open it
OpenVideoSource(fileSource);
}
}
// Open JPEG URL
private void openJPEGURLToolStripMenuItem_Click(object sender, EventArgs e)
{
URLForm form = new URLForm();
form.Description = "Enter URL of an updating JPEG from a web camera:";
form.URLs = new string[]
{
"http://195.243.185.195/axis-cgi/jpg/image.cgi?camera=1",
};
if (form.ShowDialog(this) == DialogResult.OK)
{
// create video source
JPEGStream jpegSource = new JPEGStream(form.URL);
// open it
OpenVideoSource(jpegSource);
}
}
// Open MJPEG URL
private void openMJPEGURLToolStripMenuItem_Click(object sender, EventArgs e)
{
URLForm form = new URLForm();
form.Description = "Enter URL of an MJPEG video stream:";
form.URLs = new string[]
{
"http://[email protected]:81/videostream.cgi?rate=11",
"mjpegSource by mobby"
};
if (form.ShowDialog(this) == DialogResult.OK)
{
// create video source
MJPEGStream mjpegSource = new MJPEGStream(form.URL);
// open it
OpenVideoSource(mjpegSource);
}
}
// Open video source
private void OpenVideoSource(IVideoSource source)
{
// set busy cursor
this.Cursor = Cursors.WaitCursor;
// stop current video source
//CloseCurrentVideoSource();
// start new video source
videoSourcePlayer.VideoSource = source;
videoSourcePlayer.Start();
// reset stop watch
stopWatch = null;
// start timer
timer.Start();
this.Cursor = Cursors.Default;
}
// Close video source if it is running
private void CloseCurrentVideoSource()
{
if (videoSourcePlayer.VideoSource != null)
{
videoSourcePlayer.SignalToStop();
// wait ~ 3 seconds
for (int i = 0; i < 30; i++)
{
if (!videoSourcePlayer.IsRunning)
break;
System.Threading.Thread.Sleep(100);
}
if (videoSourcePlayer.IsRunning)
{
videoSourcePlayer.Stop();
}
videoSourcePlayer.VideoSource = null;
}
}
// New frame received by the player
private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
{
DateTime now = DateTime.Now;
Graphics g = Graphics.FromImage(image);
// paint current time
SolidBrush brush = new SolidBrush(Color.Red);
g.DrawString(now.ToString(), this.Font, brush, new PointF(5, 5));
brush.Dispose();
g.Dispose();
}
// On timer event - gather statistics
private void timer_Tick(object sender, EventArgs e)
{
IVideoSource videoSource = videoSourcePlayer.VideoSource;
if (videoSource != null)
{
// get number of frames since the last timer tick
int framesReceived = videoSource.FramesReceived;
if (stopWatch == null)
{
stopWatch = new Stopwatch();
stopWatch.Start();
}
else
{
stopWatch.Stop();
float fps = 1000.0f * framesReceived/stopWatch.ElapsedMilliseconds;
fpsLabel.Text = fps.ToString("F2") + " fps";
stopWatch.Reset();
stopWatch.Start();
}
}
}
public static bool SetAllowUnsafeHeaderParsing20()
{
//Get the assembly that contains the internal class
Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
if (aNetAssembly != null)
{
//Use the assembly in order to get the internal type for the internal class
Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
if (aSettingsType != null)
{
//Use the internal static property to get an instance of the internal settings class.
//If the static instance isn't created allready the property will create it for us.
object anInstance = aSettingsType.InvokeMember("Section",
BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
if (anInstance != null)
{
//Locate the private bool field that tells the framework is unsafe header parsing should be allowed or not
FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
if (aUseUnsafeHeaderParsing != null)
{
aUseUnsafeHeaderParsing.SetValue(anInstance, true);
return true;
}
}
}
}
return false;
}
}
}
플레이어 프로그램 코딩입니다 동일한 Aforge 라이브러리 및 카메라의 비디오 스트림 캡처 : p. 이제는 단순한 플레이어의 코딩이 무엇이 잘못되었는지 알지 못합니다. 어떤 사람이 카메라에서 비디오 스트림을 받도록 도와 줄 수 있다면 좋겠다. 감사합니다