从 Android 相机创建要发送的 RTP 数据包
我是 Android 和套接字编程的新手。我想创建一个 Android 应用程序,将视频从设备摄像头实时传输到 PC。我首先要做的是从 PreviewCallback 参数获取原始视频数据并将其转换为 RTP 数据包。我只是使用 JLibRTP 来做到这一点。关于传输数据包,我认为有一些相关的类:RtpPkt、RtpSession 和 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 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.
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());
}
}
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这个库是否包含将数据包流式传输到电脑的东西,
但如果没有,你就有问题了,因为 android 从 3.1 版本(API 级别 12)开始只支持 RTP 流。如果你的水平较低,你必须编写自己的“rtp服务器”,它能够将数据包从你的设备传输到电脑。
有关更多信息,请查看 sipdroid 项目。他们创建了自己的“rtp服务器”:http://code.google.com/p/sipdroid/source/browse/trunk/src/org/sipdroid/sipua/ui/VideoCamera.java
更新:
另一种可能性是使用 ffmpeg 库中的 ffserver,但因此您必须编译适用于 android 的库。这里有一个小教程,介绍如何执行此操作以及如何使用库:如何为 Android 构建 FFmpeg< /a>
更新2:
spydroid 应用程序是一个非常很好的例子从 Android 设备流式传输视频,无需任何外部库。
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.
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
UPDATE:
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:
the spydroid application is a very good example to stream videos from an android device without any external libraries.