如何通过RTP数据包发送的byte []创建映像 [英] How to create image from byte[] send by RTP packets

查看:136
本文介绍了如何通过RTP数据包发送的byte []创建映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在通过调用RTSP服务来捕获图像。



为了调用RTSP服务,我创建了一个示例应用程序(作为客户端),并且我创建了socket对象并调用RTSP服务侦听方法。



我也可以使用UDP监听器接收byte [],但我无法使用此byte []值既不用于创建图像也不用于创建视频,并且它不会像无效的参数。那么,我如何使用这个字节[]来创建图像/视频?



这里的参考我有附加图像,你可以看到收到的字节[ ]

2017-07-11_1531 [ ^ ]



什么我试过了:



- 调用RTSP服务的代码-----

Hi,

I am working on capture images by calling RTSP service.

For calling RTSP service I have created one sample application (as a client) and in that I have created socket object and call RTSP service listen method.

I am also able to receive byte[] using UDP listener, but I am not able to use this byte[] value neither for create image nor for create video and it throwing error like "invalid parameter". So, How I can create image/video using this byte[] ?

For reference here I have attached image and in that you can see received byte[]
2017-07-11_1531[^]

What I have tried:

--Code for calling RTSP service -----

IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 322);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp);
server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
server.Connect(ip);
var msg ="PLAY rtsp://{cameraIP}/axis-media/media.amp?resolution=352x240&compression=80 RTSP/1.0\r\nRange: npt=0-\r\nCSeq: 5\r\nUser-Agent: Lavf57.62.100\r\nSession: 100\r\n\r\n")";
server.Send(msg);



- RTSP服务发送的接收UDP数据包的代码-----


--Code for receive UDP packets sent by RTSP service -----

var myEndPoint = (EndPoint)endPoint;
var udpListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
udpListener.Bind(myEndPoint);

var buffer = new byte[65536];
var size = udpListener.ReceiveFrom(buffer, ref myEndPoint);
Array.Resize(ref buffer, size);

//code for save image

MemoryStream ms = new MemoryStream(buffer);
var image = Image.FromStream(ms);
var path = string.Format(@"d:\MyImage\camImage-temp.jpeg");
image.Save(path);

推荐答案

为什么要发送TCP并接收UDP数据包?在接收方使用TCP alsp。



你应该使用 Image.Save(),带有一个强制执行jpeg的参数。

Why are you sending TCP and receiving UDP packets??? Use TCP alsp on the receiver side.

You should use the Image.Save() with a parameter to enforce jpeg.
image.Save(path, ImageFormat.Jpeg);



否则检查其他问题,例如传输的数据及其大小。


Else check for other problems, like the transmitted data and its size.


这篇关于如何通过RTP数据包发送的byte []创建映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆