Android - Stream camera as RTMP stream

Gooey picture Gooey · Mar 12, 2015 · Viewed 31.9k times · Source

I want to capture the camera stream from an Android device and stream it to a server with RTMP (the server is out of my control). I have not figured out yet how to create a stream of data from the camera itself, but that is for a later concern.

At the moment there are two problems: I wish to support API 9+ and RTMP is not native supported by Android.

I've taken a look around and found this SO post Convert video Input Stream to RTMP and https://github.com/yixia/VitamioBundle. The former suggested a library that has little to no documentation. The latter probably supports it (?), but it requires API 14+.

Are there decent examples or libraries out there, that that supports RTMP streaming from an Android device? I've also read something about converting RTSP or FFMPEG, if that is a viable way then I guess it will suffice too.

Edit 1:

I've found this library (It has a lot of resemblance to the one mentioned above) and tried to work with. I imported it in Android Studio and wrote some code, but it appears to crash internally with a java.lang.NoClassDefFoundError RTSP Codec Factory error. So apparently that doesn't work too well on Android.

Also, I've encountered several times Adobe air. I do not want to code in Action Script 3 (AS3) as this library will just be a (small) part of a native app. If Adobe Air has a library which I am unaware of, then I would happily integrate it if that is possible.

Answer

aergistal picture aergistal · Mar 15, 2015

In the accepted answer of the question you linked someone suggests using JavaCV.

It requires API 8 or newer and features a FFmpegFrameRecorder class.

Link to github:

https://github.com/bytedeco/javacv

They even have a full sample of capturing flv (it's rather large so I won't paste it here): https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java

In your case you probably need to replace:

private String ffmpeg_link = "/mnt/sdcard/stream.flv";

with

private String ffmpeg_link = "rtmp://<server>:<port>/stream";