从 Android 相机创建 RTP 数据包以发送 [英] Creating RTP Packets from Android Camera to Send

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

问题描述

我是 Android 和套接字编程的新手.我想创建一个将视频从设备摄像头实时传输到 PC 的 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.

这是我的浏览代码:

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());
    }
}

我仍然想知道我必须将地址和端口信息放在哪里.我知道上面的代码仍然需要任何大师的更正.感谢您的提前..

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 从 3.1 版(API 级别 12)开始只支持 RTP 流.如果您的级别较低,则必须编写自己的rtp-server",它能够将数据包从您的设备流式传输到 pc.

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 服务器":http://code.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

更新:

另一种可能性是使用 ffmpeg 库中的 ffserver,但因此您必须为 android 编译库.这是一个小教程如何做到这一点以及如何使用这些库:如何为 Android 构建 FFmpeg

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

更新 2:

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天全站免登陆