【发布时间】:2019-11-12 15:35:47
【问题描述】:
我正在成功使用以下代码来传输公共 IP 网络摄像头的 URL。
现在,我已经设置了自己的 IP 摄像头,我现在正试图捕捉这个提要,但没有成功。
我不确定我是否应该分享正确的 URL,因为如果每个人都在检查它可能会超载。
但是,- URL 的确切格式在 Chrome 中有效,我可以在其中看到提要:
http://admin:admin@79.123.101.121:1024/web/admin.html(不是真实 IP)
chrome 中的 feed 看起来像这样,它是 IP Camera 软件
然后我尝试使用以下代码仅捕获图像流本身,但我没有成功。我在下面尝试过,但完全没有成功。图像控件中没有任何内容:
http://admin:admin@79.123.101.121:1024/web/admin.html
http://admin:admin@79.123.101.121:1024
http://79.123.101.121:1024
正如所见,我添加了用户名和密码,它们是:admin 和 admin,这是查看流所必需的。
这可能是什么问题?
(我正在使用库:“Emgu.CV”版本 v4.1.1.3497,它存在于 Nuget 中,可以安装)
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
private VideoCapture _capture = null;
private bool _captureInProgress;
Emgu.CV.UI.ImageBox imageBox = new Emgu.CV.UI.ImageBox();
public Form1()
{
InitializeComponent();
imageBox.Width = 700;
imageBox.Height = 500;
panel19.Controls.Add(imageBox);
CvInvoke.UseOpenCL = false;
try
{
_capture = new VideoCapture("http://77.243.103.105:8081/mjpg/video.mjpg");
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt) { MessageBox.Show(excpt.Message); }
}
private void button1_Click(object sender, EventArgs e)
{
if (_capture == null)
{
try
{
_capture = new VideoCapture();
}
catch (NullReferenceException excpt) { MessageBox.Show(excpt.Message); }
}
if (_capture != null)
{
if (_captureInProgress)
{
button1.Text = "Start!"; //if camera is getting frames then stop the capture and set button Text "Start" for resuming capture
Application.Idle -= ProcessFrame;
}
else
{
button1.Text = "Stop"; //if camera is NOT getting frames then start the capture and set button Text to "Stop" for pausing capture
Application.Idle += ProcessFrame;
}
_captureInProgress = !_captureInProgress;
}
}
Mat frame = new Mat();
private void ProcessFrame(object sender, EventArgs arg)
{
//_capture.Retrieve(frame, 0); //(1st try)
_capture.Read(frame); //This calls Grab() as grabbing a frame and then Retrieve(); (2nd try)
imageBox.Image = frame; //line 2
}
编辑:
当我在 Chrome 浏览器中输入 IP 摄像机时,我使用了 wireshark 来嗅探发生了什么。我已经更改了下面的 IP,所以并不是每个人都在看我在相机上开发的内容:
这是我得到的信息:
GET /web/cgi-bin/hi3510/param.cgi?cmd=getvencattr&-chn=11&cmd=getvencattr&-chn=12&cmd=getsetupflag&cmd=getaudioflag&cmd=getrtmpattr HTTP/1.1
Host: 79.129.110.182:1024
Connection: keep-alive
Authorization: Basic YWRtaW46YWRtaW4=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
Accept: */*
Referer: http://79.129.110.182:1024/web/mainpage.html
Accept-Encoding: gzip, deflate
Accept-Language: sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: streamselect=1; cookmun=1; language0=1
HTTP/1.1 200 OK
Server: Hipcam
Cache-Control: no-cache
Content-Type:text/html
Connection: close
Content-Length: 379
如果我从上面的信息中构建一个 URL,如下所示:
http://79.129.110.182:1024/web/cgi-bin/hi3510/param.cgi?cmd=getvencattr&-chn=11&cmd=getvencattr&-chn=12&cmd=getsetupflag&cmd=getaudioflag&cmd=getrtmpattr
我在 chrome 中得到这个结果,这实际上是 IP 摄像机的设置:
var bps_1="1536"; var fps_1="25"; var gop_1="50"; var brmode_1="1"; var imagegrade_1="4"; var width_1="1280"; var height_1="720"; var bps_2="448"; var fps_2="5"; var gop_2="50"; var brmode_2="1"; var imagegrade_2="2"; var width_2="640"; var height_2="352"; var name0="admin"; var password0="admin"; var authLevel0="15"; var audioflag="1"; var rtmpport="1935";
【问题讨论】:
-
最好的方法是使用嗅探器,就像我在之前的帖子中所说的那样。当您连接时,您的应用程序(客户端)和设备(服务器)之间会发送一个请求。连接的选项位于第一个请求的标头中。您需要将 Chrome 中的标头与 c# 应用程序中的标头进行比较。然后修复 c#,使标题与 Chrome 设置匹配。视频应用程序的选项设置不正确。
-
谢谢你我会试试wireshark 我以前也听说过这个名字。我会看看我是否能理解并看到你提到的标题。这似乎是一个很好的起点。
-
我不知道你说的是什么:“视频应用程序的选项设置不正确”?
-
URL 的
username:password部分是人为的,由您的浏览器解释为 HTTP 身份验证标头。在实际的 Web 请求中,您应该相应地对其进行格式化。 Wireshark 是查看实际情况的好方法。只要记住在你开始工作后更改凭据;) -
是的,wireshark 看起来很有趣。这将是我第一次使用它,所以我会看看我能从中理解什么;)我现在就开始吧:)