创建从Android摄像头RTP数据包发送 [英] Creating RTP Packets from Android Camera to Send

查看:1411
本文介绍了创建从Android摄像头RTP数据包发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid和套接字编程。我想创建一个从设备摄像头实时传输视频到电脑Android应用程序。什么首先我要做的就是获得previewCallback参数的原始视频数据,并将其转换为RTP包。我只是用JLibRTP做到这一点。关于到包我想转让,也有一些相关的类:RtpPkt,RtpSession和RtpSocket。

I'm new to Android and socket programming. I want to create an android application that transfer video live from device camera to PC. What first i do is to get a raw video data from PreviewCallback arguments and convert it to an RTP Packet. I was just using JLibRTP to do this. Regarding to transfer the packet i think, there are some related class: RtpPkt, RtpSession, and RtpSocket.

下面是我一眼code:

Here is my glance code:

DatagramSocket rtpSocket = new DatagramSocket();
DatagramSocket rtcpSocket = new new DatagramSocket();
RtpSession rtpSession = new RtpSession(rtpSocket, rtcpSocket);

public void surfaceCreated(SurfaceHolder holder) {
    try {
            camera = Camera.open();
            camera.setPreviewCallback(new PreviewCallback() {
                public void onPreviewFrame(byte[] _data, Camera _camera) {
                int height = 240;
                    try {
                        rtps.sendData(_data);
                     } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), e.toString(),
                        Toast.LENGTH_SHORT).show();
                    }
                }
            });
            camera.setPreviewDisplay(holder);
            camera.startPreview();
    } catch (IOException e) {
            Log.d("CAMERA", e.getMessage());
    }
}

我还是想知道我必须把地址和端口信息。我知道code以上仍然需要纠正任何主。感谢提前..

I'm still wondering where i have to put address and port information. I know the code above still need correction from you any master. Thanks for advance..

推荐答案

我不知道这个库包含一些对数据包流式传输到PC, 但如果没有,你有问题,由于Android只支持RTP流,因为3.1版本(API等级12)。如果你的水平是较低的,你必须写自己的RTP服务器,这是能够从设备中的数据包传输到电脑上。

I don't know if this library includes something to stream the packets to the pc, but if not, you've a problem, because android only supports RTP streaming since version 3.1 (API level 12). if your level is lower, you have to write your own "rtp-server" which is able to stream the packets from your device to the pc.

有关详细信息,请查看sipdroid项目。他们创造了自己的RTP服务器:<一href="http://$c$c.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/VideoCamera.java" rel="nofollow">http://$c$c.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/VideoCamera.java

for more information check out the sipdroid project. they have created their own "rtp-server": http://code.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/VideoCamera.java

更新:

另一种可能性是使用从ffserver的FFmpeg的库,但因此,你必须编译库机器人。这里是一个小教程如何做到这一点,以及如何与图书馆合作:如何建立FFmpeg的Andr​​oid版

another possibility is to use the ffserver from the ffmpeg libraries, but therefore you have to compile the libraries for android. here is a small tutorial how to do this and how to work with the libraries: How to Build FFmpeg for Android

UPDATE2:

href="http://$c$c.google.com/p/spydroid-ipcamera/" rel="nofollow"> spydroid应用的

the spydroid application is a very good example to stream videos from an android device without any external libraries.

这篇关于创建从Android摄像头RTP数据包发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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