Android 相机 RTSP/RTP 流?
如何使用 RTP/RTSP 发送 Android 摄像头视频并在 PC 中播放(使用 vlc 或任何其他播放器)。
我用谷歌搜索并找到了两个答案:
1)使用mediarecorder(http://sipdroid.org/使用VideoCamera.java)
如何使用它我尝试了但没有结果:(
2) 使用 PreviewCallback() - onPreviewFrame(data, camera) 方法。
通过使用 sipdroid 的(Rtppacket、Rtpsocket、sipdroidsocket),我能够发送包含每个帧作为数据的 Rtp 数据包,并且我能够通过 Wireshark 捕获它。
但我无法在 VLC 中播放我的数据包:(
这是我的代码:
mCamera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
int width= 320;
int height=240;
eth=getInterfaces();
Log.v("Connected to ","Ethernet"+eth);
if(eth!=null){
try{
InetAddress serverAddr = InetAddress.getByName("IP Address of My PC");
Log.v("trying to ","connect with"+serverAddr);
SipdroidSocket soc = new SipdroidSocket(9954);
Log.v("trying to ","connect with Sipdroid Socket");
soc.connect(serverAddr, 9954);
Log.v("Socket ","Connected");
RtpPacket rtpp=new RtpPacket(data,height);
//rtpp.setPayloadType(125);
Log.v("RTPPacket","Created");
RtpSocket rtps= new RtpSocket(soc,serverAddr,9954);
Log.v("RTPSocket","Created");
rtps.send(rtpp);
Log.v("Packet","Sent");
}
catch(Exception e){e.printStackTrace();Log.v(TAG, "Socket");}
}
}
});
我怎样才能播放数据包?请给出一些建议!!!
我完全困惑:(我是 Android 开发新手!!需要专家的帮助!!!
How can I send Android camera video using RTP/RTSP and play it in PC(using vlc or any other player).
I googled this and found two answers:
1) using mediarecorder (http://sipdroid.org/ using VideoCamera.java)
How to work with it i tried it but no result :(
2) using PreviewCallback() - onPreviewFrame(data, camera) method.
by using sipdroid's (Rtppacket,Rtpsocket,sipdroidsocket) I am able to send Rtp Packets containing each frame as data and I am able to catch it via Wireshark.
But I am not able to play my packets in VLC :(
This is my code:
mCamera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
int width= 320;
int height=240;
eth=getInterfaces();
Log.v("Connected to ","Ethernet"+eth);
if(eth!=null){
try{
InetAddress serverAddr = InetAddress.getByName("IP Address of My PC");
Log.v("trying to ","connect with"+serverAddr);
SipdroidSocket soc = new SipdroidSocket(9954);
Log.v("trying to ","connect with Sipdroid Socket");
soc.connect(serverAddr, 9954);
Log.v("Socket ","Connected");
RtpPacket rtpp=new RtpPacket(data,height);
//rtpp.setPayloadType(125);
Log.v("RTPPacket","Created");
RtpSocket rtps= new RtpSocket(soc,serverAddr,9954);
Log.v("RTPSocket","Created");
rtps.send(rtpp);
Log.v("Packet","Sent");
}
catch(Exception e){e.printStackTrace();Log.v(TAG, "Socket");}
}
}
});
How can I play the packets? Please give some suggestions!!!
I am totally confused:( I am new to android development!! need help from experts!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能需要通过decodeYUV420SP 解码流,因为byte[] 数据是YUV 格式。
I think you might need to decode the stream via decodeYUV420SP since the byte[] data is in YUV format.