使用 ffmpeg 从 IP 摄像机获取流并保存为 jpeg(图像)文件
我如何从IP摄像机获取流,它使用RTP,流是MPEG4,我有多播地址和端口,并且我有IP摄像机的IP地址和端口号。
例如,我无法通过 http (http://ip/jpeg) 访问,而且我也无法使用 VLC 播放器访问流。例如 (rtp://ipadressofcam:port) 和 (rtp://multicastaddress:port)
那么 ffmpeg 命令是什么?
我有Windows操作系统,我现在只用C#编写代码。
但是制作人创建了自己的 ocx 用于查看摄像头,该插件可以在 .net 上工作,但我不想使用它,因为它没有太多功能,我的意思是你无法获取摄像头的当前图片或快照,这就是为什么我必须我自己做。
How i can get stream from Ip Camera, Its using RTP, stream is MPEG4, i have multicast address and port,and i have ip camera's IP address and Port Number.
And I cant reach via http forexample (http://ip/jpeg) And I cant reach stream with VLC Player too. forexample (rtp://ipadressofcam:port) and (rtp://multicastaddress:port)
So What is ffmpeg command of that?
I have windows OS, I only write code with C# right now.
But producer created their own ocx which used for viewing cam,that plugin can work on .net but i dont want to use it becouse it doesnt have much funcionality, I mean you cant get current picture or snapshot of cams, thats why i have to do it myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定该流不受密码保护吗?
尝试了解为什么您的相机拒绝 VLC 请求。操作方法如下:安装 Wireshark,启动它,然后为摄像头地址设置过滤器,例如:ip.addr == camera_ip (xxxx.xxxx.xxxx.xxxx)。然后,尝试连接 VLC,并查看交换的消息。如果您看到 DROP、UNAUTH 或告诉您使用 passwd 的内容,请介绍它。 (VLC 将首先尝试使用未经身份验证的程序进行连接,如果失败,将要求输入密码。)
如果失败原因不同,Wireshark 将为您提供线索。
请记住,如果 VLC 无法访问它,那么找到其他方法来实现它的机会几乎为零。除非你是视频大师。
希望有帮助!
Are you sure the stream is not password-protected?
Try to see why your camera rejects VLC requests. And this is how to do it: Install Wireshark, start it, and put a filter for the camera address, like: ip.addr == camera_ip (xxxx.xxxx.xxxx.xxxx). Then, try to connect with VLC, and look there at the messages exchanged. If you see a DROP, UNAUTH, or something that tells you to use a passwd, introduce it. (VLC will first try to connect using an unauthenticated procedure, and if it fails, will ask for a passwd.)
Wireshark will give you clues if the failure reason is something different.
And keep in mind that if VLC can't access it, the chance to find some other way to do it is almost zero. Unless you're a video guru.
Hope it helps!
你可以使用VLC来做这样的事情,它是ActiveX控件,也可用于.NET,只需要安装VLC媒体播放器,你可以在VS工具箱上设置它的控件
http://forum.videolan.org/viewtopic.php?f=32&t=54969
更新
如果您准备好为此内容付费,您可以使用 http://www.mainconcept.com/products/sdks/video.html 这个公司产品通过解码和编码来推进,在那里你可以找到一个巨大的库。
You can use VLC for such a thing ,and it's ActiveX control which is available for .NET also ,just need to install VLC Media Player and you can set it's control on VS toolbox
http://forum.videolan.org/viewtopic.php?f=32&t=54969
UPDATE
If you are ready to pay for this stuff you can use http://www.mainconcept.com/products/sdks/video.html this Company product's to advance with Decoding and Encoding ,where you can find a huge Library .
因此,您想要从摄像机接收视频流并将单个帧转换为 JPEG 文件。这听起来不错,而且实际上听起来很自然:为什么不呢?网络上正在发送视频源,我们不需要太多,只需选择单个帧即可。
原始流是 MPEG-4(第 2 部分),所需的目标编码是 JPEG。这将任务分解为获取 MPEG-4 视频源、将其解码为未压缩图像以及编码为 JPEG 等部分。让我们从上一篇向后回顾一下这些内容。
JPEG 是一种流行的编码,有多种具有不同接口的编解码器能够压缩为 JPEG。选项包括 GDI+ API、IJG JPEG 库 libjpeg,用于具有 DirectShow 和其他接口的视频的 JPEG 库和编解码器。
MPEG-4 解码器是一个复杂的组件,但幸运的是它标准化良好,并且可以通过不同的接口和多个来源使用。特别是 MPEG-4 第 2 部分视频解码器 作为
DMO
(也通过 )随 Windows 7 一起提供。解码器还可以作为 ffdshow、Intel Media SDK 中的 DirectShow 过滤器使用。回到第一步,您需要从网络获取 MPEG-4 流。首先,您表明摄像机可在多播 UDP 地址上使用。这使您打开一个套接字并放入多播组中,以便开始接收 RTP 数据。您收到的数据还不是纯 MPEG-4,并且根据 MPEG 的 RTP 有效负载格式进行格式化-4 音频/视频流,当您接收 RTP 消息流时,您必须准备好接收无序片段、数据包丢失等。您应该接收您可以接收的内容,请检查 RTP标头,并尽力重建 MPEG-4 提要。
最终,您需要从应用程序中涵盖这些步骤(不一定是直接的,您宁愿使用第三方库,包括其他答案中提到的那些),并构建一个将从网络接收和转码连接在一起的管道。
So you want to receive video stream from camera and convert individual frame into JPEG file. This sounds good and actually sounds natural: why not? there is a video feed being sent on network and we don't need much, just to pick individual frame.
The original stream is MPEG-4 (Part 2) and desired target encoding is JPEG. This breaks the task into parts of getting MPEG-4 video feed, decoding it into uncompressed images, and encoding into JPEG. Let us go through these from the last one backwards.
JPEG is a popular encoding and there are various codecs with different interface capable of compressing into JPEG. Options include GDI+ API, IJG JPEG library libjpeg, JPEG libraries and codecs for video with DirectShow and other interfaces.
MPEG-4 decoder is a complicated component, however is luckily well standardized and available in different interfaces and from several sources. In particular MPEG-4 Part 2 Video Decoder is shipped as
DMO
(and also through ) with Windows 7. Decoder is also available as DirectShow filter in ffdshow, Intel Media SDK.Back to the first step, you need to reach MPEG-4 stream from network. First of all you indicated that the camera is available on multi-cast UDP address. This makes you open a socket and put into onto multi-cast group in order to start receiving RTP data. The data you would receive is not pure MPEG-4 yet, and is formatted according to RTP Payload Format for MPEG-4 Audio/Visual Streams and as you receive RTP stream of messages you will have to be prepared to receive out of order fragments, packet losses etc. You are supposed to receive what you can receive, check the RTP headers, and do your best in reconstructing MPEG-4 feed.
Eventually you need to cover these steps (not necessarily directly, you would rather use third party libraries including those mentioned in other answers) from your application and build a pipeline which stitches together receiving from network and transcoding.
所以到目前为止,我看到 VLC 无法打开它,但如果我们创建 .sdp 文件并使用 ffplay 播放它,只会出现黑屏。
当然,这不是纯粹的解决方案,但希望不大。
但绝对的解决方案可以是这样的;
没有办法仅使用 C# 来实现我的意图。我可以使用的 C++ 库组件很少,但我可以将它与托管 C++ 一起使用来编写互操作服务并在我的 C# 代码中使用这些 dll。这是我需要的:
1-我需要一个 RTP 库, http:// Research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib 或 live555,但 live555 有一定的局限性。
2-RTP 库是我从编码器中提取的 MPEG4 流的传输。但我需要控制流的方法,这些方法是由生产者的 WSDL 提供的。
3-之后我需要一个解码器; Libavcodec,我可以使用 libavcodec 将 Iframe 转换为 .net 中的 jpeg 图像。
So until now, I saw VLC cant open it but if we create .sdp file and play it with ffplay only a black screen appears.
Of course this is not pure solution but there is little bit hope.
But obsolute solution can be like that;
There is no way to use just c# to achive what i intend. There are few c++ library components that i can use, but i can use it along with Managed c++ to write interop services and use those dlls in my c# code.Here is what i need:
1-I need an RTP Library, http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib or live555 but live555 has certain limitations.
2-RTP Library is the transport for the MPEG4 stream i pull from my encoder. But i need ways to control the stream, those are provided producer's WSDLs.
3-After that i need a decoder; Libavcodec, I can use libavcodec to convert an Iframe to a jpeg image in .net.