Rtmp streaming from android

Rtmp streaming from android

Sponsored with 💖 by

Enterprise Grade APIs for Feeds & Chat. Try the Android Chat tutorial 💬

Library for stream in RTMP and RTSP. All code in Java.

If you need a player see this project:

iOS version (under develop):

To use this library in your project with gradle add this to your build.gradle:

  • Android min API 16.
  • Support camera1 and camera2 API
  • Encoder type buffer to buffer.
  • Encoder type surface to buffer.
  • RTMP/RTSP auth.
  • Audio noise suppressor.
  • Audio echo cancellation.
  • Disable/Enable video and audio while streaming.
  • Switch camera while streaming.
  • Change video bitrate while streaming (API 19+).
  • Get upload bandwidth used.
  • Record MP4 file while streaming (API 18+).
  • H264, H265 and AAC hardware encoding.
  • Force H264 and AAC Codec hardware/software encoding (Not recommended).
  • RTSP TCP/UDP.
  • Stream from video and audio files like mp4, webm, mp3, etc (Limited by device decoders). More info
  • Stream device display (API 21+).
  • Set Image, Gif or Text to stream on real time.
  • OpenGL real time filters. More info
  • RTMPS and RTSPS.
  • RTSP H265 support (Waiting FLV official packetization to add RTMP support).

Other related projects:

Real time filters:

In library version 2.0.9, the filters was refactored. Check the wiki link to migrate your implementation.

This code is a basic example. I recommend you go to Activities in app module and see all examples.

Источник

Rtmp streaming from android

RTMP Java Muxer for Android

This project implements the RTMP protocol to broadcast video and audio TO (and only TO!) an RTMP server from Android using pure Java (no native extension).

It has been tested with Android MediaCodec encoder to send H264 (avc) video and with Android MediaRecorder to send AAC audio via RTMP to a server.

This implementation uses the RTMP 3 protocol version: RTMP 3

It also uses the AMF0 file format: AMF0

This muxer has been developed to be used on Android but it actually contains only 1 dependency to the Android platform: the support-v4 library.

It’s used for annotations and also ArrayMap but if you want to use this library outside of Android you can remove the dependency quite easily.

Another dependency are logs which are made with the Log util of Android, but it’s also easily replaceable.

This code is a small part of an internal project and is available «as is» without any guarantee. We are not providing implementation details on how to extract H264 video and AAC audio frames on purpose, this implementation is up to you.

If you want to contribute, feel free to ask question or make pull requests, we’ll be happy to review them 🙂

To use the Muxer, you must respect the following runtime:

1- Start streaming by calling the start and createStream method

Note that this sample uses an AsyncTask to demonstrate threading but you should use another most efficient threading method into your app.

2- Send data to the Muxer using postVideo and postAudio (see next part for more info)

3- Stop streaming by calling the deleteStream method

4- Disconnect by calling the stop method

Sample of video posting with MediaCodec API

Once the RtmpMuxer is ready to publish, you can provide it with video data. Those data can be extracted from the MediaCodec encoder (other ways asn’t been tested). Here’s how to create an H264VideoFrame object from the MediaCodec buffer (extracted from the Grafika sample):

Note that this sample is incomplete and you’ll have to manage encoder lifecycle. Also, avoid using AsyncTask for posting data since it will happen multiple times per seconds, it’s done here just as a sample.

Sample of audio posting with MediaRecorder API

Читайте также:  Android play store downloading

Once the RtmpMuxer is ready to publish, you can also provide it with audio data. Those data can be extracted from the MediaRecorder (other ways asn’t been tested). Here’s how to create configure MediaRecorder to generate the right stream:

Note that this sample is incomplete and you’ll have to manage thread completion, AAC parsing and data extracting. Also, avoid using AsyncTask for posting data since it will happen multiple times per seconds, it’s done here just as a sample.

  • Benoit Letondor: Android software engineer at Newzulu/Octiplex.

Code is available under the Revised BSD License, see LICENCE for more info.

Источник

How To Stream RTMP live in Android

Streaming live video/audio in android is one of the very few interesting parts we have. Whenever we talk of streaming, the possibility of using RTMP(Real Time Messaging Protocol) cannot be ruled out. As RTMP is one of the most basic protocols available for streaming live video/audio feed. But unfortunately Android’s standard VideoView does not support the playback of RTMP streams. Therefore to natively play a live RTMP stream on Android, an external library is required which can provide us an Android RTMP player. As of now I have discovered two libraries which can serve this purpose.

First being the Android Vitamio library, and second being the LibVLC SDK for Android. In my opinion the later one is the better one. As this comes in a form of a plug-in solution from the open source organisation that built the worlds greatest video player ever, that right:- VLC. Therefore in this tutorial to build an example of Android RTMP player we will discuss how we can use the LibVLC SDK for Android. But before doing so lets, also have an overview of its counterpart, Vitamio library as well.

Android Vitamio Library

Vitamio is an open source project for Android and iOS built up on FFmpeg code. Vitamio provides us a clean and simple API with full and real hardware accelerated decoder and render-er. Vitamio is a very powerful library which supports a wide variety of video/audio formats like FLV, TS/TP, WMV, DivX, Xvid and many other standard formats. What makes it different is that it also supports the playback of embedded and external subtitles like .mkv and .srt. But Vitamio comes with a license, hence please go through this license page before using it in your project. In this Android RTMP example, we will not only discuss the live streaming of RTMP stream in Android, but will also discuss how we can stream m3u8 playlists(HLS), RTSP streams and MMS (Microsoft Media Stream). But through the usage of VLCs SDK for Android.

Android VLC SDK

VLC Media Player has been the most popular video file playback software available till date. The interesting part about it is that, it supports all major video/audio playback formats. Therefore when compared with other SDKs or libraries like Vitamio for RTMP streaming, it is considered to be far more superior by default. This gives us an obvious answer why we should use this LibVLC SDK for Android. Coincidentally, it is not very difficult to use this SDK in an Android app. Once done, you can play all the playback formats it supports, be it HLS, RTMP, RTSP, or even subtitles. Full SDK docs are available here. Therefore, without waiting lets integrate it in our app.

Читайте также:  Ammyy admin apk для андроид

How to embed VLC Media Player in your Android App?

To use Android VLC Media Player SDK in your app, you may need to include the compiled code for vlc media player in your app. To do so, two ways are available:

Option 1: Manually compile SDK and use it through NDK as .so file:

Option 2: Use a Gradle dependency, compiled as an opensource project vlc-android-sdk by mrmaffen (May not be the latest version always).

So for this Android RTMP Streaming Example, I will be using this option. To do so, all you need to do is in your build.gradle (app) file, add a dependency as shown:

Streaming RTMP Stream Live in Android

Before heading directly to the implementation part, first lets understand RTMP a little. Real Time Messaging Protocol (RTMP) is a protocol owned by Adobe Systems. This protocol was developed to stream audio and video content to company’s proprietary flash player. But later on as it evolved, a part of it was released for public use. More of it can be read here. Mostly this type of protocol is used for IPTV and live VoD streaming, but it can be used in many other areas as well.

To play an RTMP stream in Android, a normal VideoView cannot be used, as it does not support the RTMP playback. But a WebView can be used to play the RTMP stream without any external library. This solves the problem but in my personal opinion web apps don’t give a nice look and feel to an app. Hence in this Android RTMP example we will be using an external SDK – VLC Media Player for streaming a live RTMP stream. After including it in the project, please add a SurfaceView in your layout file:

Further to run this Android RTMP player, please code your activity something like this:

Although the above code is self explanatory, but please dont forget to change the RTMP path to play your stream. At times to stream an RTMP stream in Android, you may have to pass the headers along with the path. Luckily you may have seen above that LibVLC supports that too. Hence all types of RTMP streams can be used with Android VLC SDK. The above example would look something like this:

But before moving on to other parts, please don’t forget to add configChanges flag in your AndroidManifest for this Activity, as shown:

Full source code is also available here:

Android RTSP Streaming

Real Time Streaming Protocol (RTSP) is used for streaming content from media servers. Like YouTube uses RTSP streams to distribute content. The easy part about RTSP streaming is that, it can be done through the standard VideoView of Android. To read more about it please refer to my VideoView Example.

But if you are implementing a solution by using the embedded VLC Media Player Lib, you might prefer using the same for RTSP streaming as well. As a matter of fact Android VLC SDK supports all video/audio formats, hence it also supports the playback of RTSP stream. Therefore If you are building a media playback app, you may use the same code shown in the section above to playback an RTSP stream. All you need to do is replace the URL.

Android m3u8 Streaming

How to play m3u8 video in Android? is one of the most common questions among the Android developers. The easiest way to do HTTP Live Streaming (HLS) in Android is through the usage of standard VideoView. But as you might have guessed, there are some limitations to it. Through standard Android VideoView you can stream m3u8 streams but only on the devices having Android 3.0 and above. This is because the HTTP/HTTPS live streaming and HTTP/HTTPS progressive streaming protocols were introduced in Android 3.0 and full support with HTTPS was given in 3.1.

Читайте также:  Не включается точка доступа wifi андроид

If you wish to do HTTP Live Streaming (HLS) and support Android m3u8 streaming, for earlier versions of android. You should consider using the Android LibVLC, as this library adds the support for playback of m3u8 lists along with many other formats on android API 9 and above. To do so the process is same- as shown in the sections above, just replace the URL with m3u8, HTTP Live Streaming URL:

Playing m3u8 stream on Android with VLC SDK would look something like this:

Android MMS Stream

Another uncommon format for streaming in Android is MMS. Since the Android LibVLC is a powerful library which supports very complex video playback formats, it also supports the playback of Microsoft Media Server (MMS) stream. Hence one should use this SDK to stream MMS as well. MMS is a network streaming protocol, mostly used for webcasts and live radio. Using embedded VLC media player library for the playback of an MMS stream in Android is not that different from using other protocols. All you have to do just replace the path variable to point to an MMS url:

Conclusion

As we discussed above, I would like to conclude by saying that LibVLC SDK is a very powerful multi-platform library, for iOS and Android both. By using Vitamio library one can stream limited types of video formats and protocols like RTMP, RTSP, HTTP Live, and HTTP progressive streaming protocol. But by using the Android VLC SDK, you can stream all the major video/audio formats available till date. Another great playback feature that comes along with LibVLC is that it supports the playback of subtitles and multiple audio tracks as well. Hope this helped. Connect with us through our Facebook, Google+ and Twitter profiles for more updates.

About Mohit Gupt

An android enthusiast, and an iPhone user with a keen interest in development of innovative applications.

Источник

Rtmp streaming from android

Moving forward, Mux is consolidating examples in a single location: https://github.com/muxinc/examples. See that repo for a an updated Android Live streaming example (based on javacv) that should be simpler.

An example app for live streaming from an Android device using the Mux live streaming service, written in Java and C++

This repo includes two main components:

  • A sample application, located under /app , which includes a simple UI to configure and stream your live stream.
  • A lower-level moduled, under /libcamera , providing all of the live capture and live streaming functionality.

The libcamera module supports the following features:

  • Integration with Android’s Camera 2 API
  • Landscape and portrait video capture
  • Application pause and resume
  • Force screen to stay on while capture is active
  • Configuration of video and audio encoding settigns
  • Minimum Android API level 9

The libcamera module is built on, and encapsulates, the following third-party libraries:

Clone this repo locally, and then load the application from the root directory in Android Studio 3.0+.

Run the application. There will be buttons at the bottom of the screen to start/stop live capture.

app contains the demo application

libcamera is the functional module

  • Mux
  • Mux Live Streaming Documentation
  • Demuxed
  • Yasea FLC stream muxer
  • libyuv Color space converter
  • SimpleRTMP RTMP Streaming SDK

example-android-live-streaming and MuxLive are available under the MIT license, see the LICENSE file for more information.

Источник

Оцените статью