5

我正在从事一个爱好项目,其目标是开发一个 Android 应用程序,该应用程序能够使用 FFMpeg 作为底层引擎,在 LAN 设置中流式传输通过网络摄像头捕获的实时提要。到目前为止,我做了以下事情 -

A. 为以下版本编译和生成 FFMpeg 相关库 -

FFMpeg 版本:2.0
NDK 版本:r8e & r9
Android 平台版本:android-16 & android-18thisthisthisthis
工具链版本:4.6 & 4.8
构建平台:Fedora 18 (x86_64)

B. 在适当的路径中创建文件 Android.mk & Application.mk。

但是,在使用 Java 编写从应用程序层访问 FFMpeg 的适当功能的本机代码时,我遇到了以下问题 -

a) 我需要从本机层到应用程序层提供 FFMpeg 的哪些所有功能以用于流式传输实时源?
b)为了为 Android 编译 FFMpeg,我点击了这个链接。编译选项是否足以处理 *.sdp 流,还是我需要修改它?
c) 我需要使用live555吗?

我对 FFMpeg 和 Android 应用程序开发完全陌生,这将是我在 Android 平台上的第一个严肃项目。我一直在寻找使用 FFMpeg 处理 RTSP 流的相关教程一段时间,但没有取得多大成功。此外,我尝试了 VLC 播放器的最新开发版本,发现它非常适合实时流式传输。然而,它是一个复杂的野兽,我的项目的目标是非常有限的,主要是学习——在很短的时间内。

您能否就如何编写本机代码以利用 FFMpeg 库并随后使用应用层中的这些功能来流式传输实时提要提出一些建议(例如链接、文档或示例代码)?此外,如果您能让我从功能的角度(在与语言无关的意义上)了解该项目所需的背景知识,我将不胜感激。

4

1 回答 1

1

I was in a similar situation some time ago (I wanted to stream an mp3 from an RTMP server) and it was extremely frustrating. However, I managed to scrape together some code that actually did what it was supposed to. Some pointers:

  • You don't want to expose ffmpeg's API to your Java code. Instead, consider creating helper functions like openRTSPStream(String url) and keep the ffmpeg stuff in your C/C++ code. I say this because ffmpeg makes heavy use of pointers and dynamic memory allocation that would make it a pain to try and use it from Java.

  • The script you used to compile the library uses the flag --disable-everything which also means that it probably disables RTSP support. I'd recommend that you either remove that flag or run the configure script with --list-protocol, --list-demuxer, --list-muxer, --list-encoder, and --list-decoder (or something along those lines) to get an idea of what you need to enable. You need to keep in mind the format and encoding of the video and the audio and what you will be decoding it to.

  • While you are reading the packets from the stream, your native code could send buffers to your Java code through a callback function which would in turn display the buffers as video/audio.

Here is another SO post that might interest you: Record RTSP stream with FFmpeg libavformat

Let me know if you need some sample code or further clarification.

于 2013-08-10T20:50:37.557 回答