13

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.

Community
  • 1
  • 1
Gooey
  • 4,740
  • 10
  • 42
  • 76

3 Answers3

19

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";
Community
  • 1
  • 1
aergistal
  • 29,947
  • 5
  • 70
  • 92
  • This looks promising. I tried the example but getting a ``java.lang.ExceptionInInitializerError`` caused by ``Couldn't load jniopencv_core: findLibrary returned null`` error. – Gooey Mar 15 '15 at 22:32
  • Did you deploy all libs? Look around SO and Google Code (rip) because there are some related issues – aergistal Mar 15 '15 at 23:34
  • 1
    It works for me with nginx rtmp server but it only streams a black video. I think it has codec issue. I'm using recorder.setVideoCodec() to set codec ... – farhang67 Sep 07 '15 at 08:17
  • 2
    finally I solved black video issue by setting RECORD_LENGTH = 0 in RecordActivity class. – farhang67 Sep 23 '15 at 13:31
  • I tried to sent RTMP stream to RED5 server and its work. The live stream is not getting stored in the RED5 server as flv file. Do u have any idea about the changes to be done to store the stream in Red5 server. Thanks in advance. – DAC84 May 11 '17 at 09:33
3

If you can publish from your android device using a protocol supported by ffmpeg (see the list of protocols supported) you could use the following command to transmit the video to your server :

ffmpeg -re -i <input link> -vcodec h264 -ar 44100 -f flv "rtmp://<host>/<publication>"
thomas
  • 526
  • 3
  • 10
  • 3
    Could you elaborate more on this? How would you run that command from inside an android app? This app should send a stream using RTMP to a server that is out of his control. – Gooey Mar 13 '15 at 21:10
  • Sorry, I thought you were the owner of the server. You could try this repository https://github.com/cine-io/android-ffmpeg-with-rtmp but I don't know if it works well. Otherwise you could also develop an AIR application, it works! – thomas Mar 14 '15 at 16:56
  • I do not want to code in AS3, so I guess AIR will not do. Unless they have a library you can add? – Gooey Mar 14 '15 at 17:54
2

You should take a look at spydroid; it does exactly what you are looking for. Their website may be found here: https://code.google.com/p/spydroid-ipcamera/

They provide a library that you can use, along with an explanation of the various streaming options and some code examples. Said information may be found here: https://github.com/fyhertz/libstreaming

Willis
  • 5,308
  • 3
  • 32
  • 61
  • I will definitely take a look. – Gooey Mar 12 '15 at 20:29
  • Are you sure this supports RTMP? I only find RT(S)P in the list (wiki). Or can you use these? I am new to streaming stuff, so I don't really know for sure. – Gooey Mar 12 '15 at 20:47