Android 相机 RTSP/RTP 流?

发布于 2024-11-07 02:53:05 字数 1896 浏览 0 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间☆小暴躁 2024-11-14 02:53:05

我认为您可能需要通过decodeYUV420SP 解码流,因为byte[] 数据是YUV 格式。

I think you might need to decode the stream via decodeYUV420SP since the byte[] data is in YUV format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文