{"id":1257,"date":"2020-12-11T10:34:21","date_gmt":"2020-12-11T10:34:21","guid":{"rendered":"https:\/\/alternative-spaces.com\/blog\/?p=1257"},"modified":"2023-05-12T09:04:58","modified_gmt":"2023-05-12T09:04:58","slug":"rtmp-video-streaming-protocol-enable-instant-video-streaming-for-android-apps","status":"publish","type":"post","link":"https:\/\/alternative-spaces.com\/blog\/rtmp-video-streaming-protocol-enable-instant-video-streaming-for-android-apps\/","title":{"rendered":"RTMP Video Streaming Protocol: Enable Instant Video Streaming for Android Apps"},"content":{"rendered":"\n<p>Live video streaming is a really big thing. What can be easier than instantly running a live streaming app on your smartphone? It will directly broadcast you or an event taking place around you&#8230; And while you\u2019re streaming a video, your friends are watching it from their mobile devices. And all you need to make it happen is the camera and a built-in microphone on your smartphone&#8230; Isn\u2019t this fun?<\/p>\n\n\n\n<p>Live streaming has introduced a different manner for users to connect with their friends and for brands to engage and reach out to their customers.<\/p>\n\n\n\n<p>But how can your business or startup easily implement live streaming for Androidwithout dedicating lots of resources and hours of developers\u2019 work to do it? What technology stands behind live broadcast and makes it real?<\/p>\n\n\n\n<p>Let\u2019s dig into the topic to find comprehensive answers to these questions and also learn more about&nbsp;ready-to-use solutions&nbsp;that facilitate and speed up the process of adding a live video streaming feature into your app.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are characteristics of live streaming<\/strong><\/h2>\n\n\n\n<p>Unlike the format of video on demand which presumes that a user can select and watch videos at any time, live broadcast videos are tied to a specific moment in time and are displayed while being recorded.<\/p>\n\n\n\n<p>And here\u2019s how live streaming process looks like. Video and audio are both transferred through messages that the video player and the media server exchange. The video player connects to the media server first. The server transfers a portion of the video to the player. This video fragment corresponds to the current playing time. A buffer of several seconds ensures video playback without delays or interruptions. This process is constantly repeated the whole time the web broadcast lasts.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/how-video-streaming-works-1024x768.jpg\" alt=\"\" class=\"wp-image-1259\" srcset=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/how-video-streaming-works.jpg 1024w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/how-video-streaming-works-150x113.jpg 150w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/how-video-streaming-works-300x225.jpg 300w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/how-video-streaming-works-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>But live streaming never transfers media files as a whole (thus saving bandwidth). Instead, it\u2019s enabled through media servers responsible for transferring and streaming digital video, audio and data. Live streaming provides protection to source video files because they can\u2019t get copied to a viewer\u2019s computer. With the help of additional software, live streaming also supports live chatting and Q&amp;A.<\/p>\n\n\n\n<p>There is no just one single format that exists to transmit media data. Instead, you can choose the one that suits your technical needs best.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What video streaming technologies exist?<\/strong><\/h2>\n\n\n\n<p>There are multiple ways of enabling live broadcast in your app. We\u2019ll briefly overview the existing technologies below. This way you\u2019ll be able to differentiate their key features and type of content they\u2019re best made to deliver:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>RTMP Protocol<\/strong><\/li><\/ul>\n\n\n\n<p>Real-Time Messaging Protocol (or just RTMP) was developed for high-performance transfer of the video and audio streams and real-time data messages over the web. Real-time streaming is enabled by establishing a two-way connection between the Flash server and Flash player.<\/p>\n\n\n\n<p>Adobe Flash Player is the most common RTMP client that supports video and audio playback. It is currently available as an open-source specification for development of products and technology that delivers video streams in the formats of AMF, SWF, FLV and F4V (compatible with Adobe Flash Player formats) and audio in AAC and MP3.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>HTTP-based streaming protocols (HLS and HDS)<\/strong><\/li><\/ul>\n\n\n\n<p>HLS format is based on MPEG2-TS and pertains to streaming to iOS devices. It isn\u2019t part of HTML5. HLS combines multiple streams with the metadata information and easily switches between different media data.<\/p>\n\n\n\n<p>HDS uses Adobe\u2019s format for videos and delivers fragments of MPEG-4 files. MPEG format allows storing metadata and audio and video streams in different locations. HTTP Dynamic Streaming is a convenient technology for large media libraries. It helps reduce bandwidth, saves battery life and provides a better user experience compared to HLS.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Silverlight streaming protocol<\/strong><\/li><\/ul>\n\n\n\n<p>This video streaming format is used for rich Internet apps such as Adobe Flash and for running movies. Despite Microsoft Silverlight no longer works in Chrome browser, it is available in Internet Explorer and Mozilla Firefox.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>MPEG-DASH<\/strong><\/li><\/ul>\n\n\n\n<p>MPEG-DASH provides high-quality live and on-demand video streaming for media coming from HTTP servers. The format allows adding ads in between video segments for both types of streaming. Media content is encrypted once and delivered to a client computer with the help of different DRM (Digital Rights Management) schemes.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Progressive download streaming<\/strong><\/li><\/ul>\n\n\n\n<p>With progressive download, media content is transferred from a server to a client computer through &nbsp;HTTP protocol. It doesn\u2019t require any streaming server for file hosting or downloading a media file to watch it. Progressive download enables video playback before a complete video download.<\/p>\n\n\n\n<p>The rise of 4K video, high user expectations of quality standards and smooth experience, development of new effective platforms and faster Internet connection make demands to video streaming formats stricter. Irrespective of variety of technologies available, we\u2019ll focus on RTMP as one of the most widespread and favorite streaming protocols among developers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>So, what is RTMP protocol and why it\u2019s so good<\/strong><\/h2>\n\n\n\n<p>Created by Macromedia (currently Adobe), Real-Time Messaging Protocol ensures adaptive bitrate streaming (ABS). When the bandwidth changes, the video quality automatically tunes up to it. RTMP is based on Transmission Control Protocol (TCP) which prioritizes maintenance of stable connection and low latency. &nbsp;Regarding the type of content, RTMP allows transmitting both prerecorded and live media data and text information.<\/p>\n\n\n\n<p>Moreover, RTMP can be used not only for mobile streaming. RTMP server can send media data both to web applications as well as to mobile devices.<\/p>\n\n\n\n<p>It is most often praised for the following advantages it provides:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>It is specifically optimized for live streaming<\/strong><\/li><\/ul>\n\n\n\n<p>The greatest benefit that RTMP provides is optimization of video and audio data transmission. For streaming, it uses the exclusive 1935 port that is suitable for low-latency content transmission which is vital for live streaming and requires no buffering.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>It is a mature technology<\/strong><\/li><\/ul>\n\n\n\n<p>RTMP has been used for live streaming for more than 10 years. For a developer, setting up RTMP Server is an easy task. For a user, video streaming is enabled in different formats at the same time. Security features such as Player verification are applied too.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>You can watch any part of the video being broadcasted<\/strong><\/li><\/ul>\n\n\n\n<p>All RTMP servers allow recording incoming media streams and provide the ability to display videos from the beginning. A user can skip parts of the video till the current moment in the broadcast. This feature is particularly useful for long videos (more than 10 minutes), allowing to easily switch to any part of it.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>It is the most popular real-time streaming protocol<\/strong><\/li><\/ul>\n\n\n\n<p>RTMP is a platform-independent protocol that requires no hardware dependencies and is compatible with Windows, Mac, Linux, Android, iOS and Windows mobile. It is also widely utilized in gaming devices, such as PlayStation, Xbox One, and PS Vita.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How RTMP works<\/strong><\/h2>\n\n\n\n<p>In simple words, RTMP streaming consists of the following three entities:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A client that creates a media stream and broadcasts by RTMP protocol to a server. As client &#8220;publishers&#8221;, you can use a lot of apps on different platforms, such as FFMPEG based players, VLC Player, YouTube clients, and AVLib based solution.<\/li><li>A server that handles an incoming stream and performs processing and recording as necessary. The server also provides broadcasts to other clients. Among servers, the best options would be Wowza Media Server, Flussonic Media Server, and Simple RTMP Server.<\/li><li>Viewers represent any client that can watch published streams. For displaying such media streams, you could use any player that supports RTMP protocol. The good news is that almost all currently used players for all existing platforms support RTMP streams. You can select Flash Player, VLC, or Media Player Classic.<\/li><\/ul>\n\n\n\n<p>The most complex and resource-intensive are broadcaster apps. &#8216;Broadcasting flow&#8217; includes media processing, mixing, encoding and further streaming over RTMP protocol to a server. It depends significantly on a platform and hardware and requires a lot of supporting resources.<\/p>\n\n\n\n<p>To transmit as much data as possible with RTMP protocol, video and audio are split into fragments of different sizes. The default sizes are 64 bytes for audio and 128 bytes for video. Video chunk sizes are determined by the interaction format between a user and a server.<\/p>\n\n\n\n<p>Fragments of media are then interleaved and multiplexed over a single connection while correlating with a channel\u2019s bandwidth and latency. The stream coming from the broadcaster to the server consists of small data blocks that include different types of data (i.e., video, audio service, etc.). RTMP streaming can concurrently transfer several different data blocks, thus encapsulating both video and audio and enabling remote procedure calls.<\/p>\n\n\n\n<p>When the client opens the stream in RTMP player, a request is sent to RTMP Server. A session is initialized and service data exchange occurs. Once the client RTMP player receives the necessary portion of the service data packages about the ongoing stream, it starts decoding, buffering and displaying RTMP media stream.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/rtmp-process-1024x768.jpg\" alt=\"\" class=\"wp-image-1260\" srcset=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/rtmp-process.jpg 1024w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/rtmp-process-150x113.jpg 150w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/rtmp-process-300x225.jpg 300w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/rtmp-process-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>With RTMP, media is not required to be stored in any temporary storage. It continues to stream directly between clients and servers. If the bandwidth capacity allows, the same stream is directed to numerous clients that send requests. The streaming capacity improves if several media servers are put into a network. The streaming process continues until either the server or the player finishes the session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How can you use RTMP to stream video in your Android app?<\/strong><\/h2>\n\n\n\n<p>You can watch RTMP stream on any platform with the help of any player that supports RTMP protocol. For Android, the most popular third-party players are MX, VLC, and BS Players as well as any other player that supports FFMPEG. For watching RTMP from inside the application, a developer needs to integrate any player library that can read RTMP streams. These are ijkPlayer and VLC SDK.<\/p>\n\n\n\n<p>Alternative-spaces team have made their technological contribution to finding an easy and beautiful solution for video streaming and have created&nbsp;AVLib,  Alternative-spaces  own external library for Android RTMP streaming.<\/p>\n\n\n\n<p>Let\u2019s see how it works with the live broadcast for Android apps and how the idea originated.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How AVLib solves the basic problem for Android RTMP streaming<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/avlib-for-rtmp-streaming-1024x768.jpg\" alt=\"\" class=\"wp-image-1261\" srcset=\"https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/avlib-for-rtmp-streaming.jpg 1024w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/avlib-for-rtmp-streaming-150x113.jpg 150w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/avlib-for-rtmp-streaming-300x225.jpg 300w, https:\/\/alternative-spaces.com\/blog\/wp-content\/uploads\/2019\/04\/avlib-for-rtmp-streaming-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Our Android team of developers have come to the idea of AVLib almost accidentally, but with a great outcome and effect. While working on the task of adding a feature to broadcast video and audio for Android devices to RTMP servers, they encountered a serious problem. The customer\u2019s requirements stated that the app should be able to stream video and audio data at its maximum capacity through an Android camera. It was also necessary to enable support of Android 4.0 as the minimum version, for users with older mobile devices could use it, and possess a number of convenient usability settings for a user.<\/p>\n\n\n\n<p>Alternative-spaces  team have conducted a deep research and comparison of existing both commercial and open-source streaming libraries. But with no satisfying result. It turned out there was no similar solution in the market that could meet our technical needs in a complete manner. The team members quickly came to a decision of creating their own external library that could support RTMP streaming for Android. And because there is a vast number of Android devices and OS versions being currently in use, this library was built to support streaming needs of all current Android users.<\/p>\n\n\n\n<p>But it never makes sense to spend time on creating a one-time tool that solves one particular task strictly to the required extent. What if a similar situation is repeated? Why not use the best of what technology has to offer and build a well-tested software product?&nbsp;&nbsp;<\/p>\n\n\n\n<p>We intended to develop an elegant, flexible and simple solution, so any other third-party Android team or a developer who was looking for an RTMP library could easily integrate it into an app without having to reinvent the wheel. And we did it! AVLib combines all features we expected and comprehensively solves the basic task of the video broadcast.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How AVLib was developed and why it\u2019s a reliable RTMP library<\/strong><\/h2>\n\n\n\n<p>AVLib is an RTMP library that we\u2019re truly proud of. It is a software product that solves a customer&#8217;s requirements for live streaming of any complexity level. It is a ready-to-use tool for Android Studio that is integrated into a mobile app straight away.<\/p>\n\n\n\n<p>AVLib represents a convenient and stable solution that is based on the following principles:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>An easy integration with the app<\/strong><\/li><\/ul>\n\n\n\n<p>For an Android developer, it would take about an hour to complete the process of integration of AVLib and add a live streaming feature into an app.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Maximum capacity<\/strong><\/li><\/ul>\n\n\n\n<p>To implement the RTMP library and empower it with a high capacity potential, our team chose the C programming language. Every single function included into AVLib, starting from the conveyor logic, coding, work with RTMP and up to processing, were built using pure C.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>UI custom-built library<\/strong><\/li><\/ul>\n\n\n\n<p>AVLib is flexible and can be easily adjusted to customer needs in UI design (i.e., buttons, text) and video settings (i.e., frame resolution, audio, codec quality, bitrates).<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Support of all existing types of Android devices<\/strong><\/li><\/ul>\n\n\n\n<p>This RTMP library comes as one .aar file with no dependencies. AVLib was tested to make sure it is compatible with various Android devices and supports Android OS version 4.0 and higher.<\/p>\n\n\n\n<p>The development process of AVLib was really&nbsp;full of challenges and required thought and effort from our Android team.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Streaming from action cameras? Yes!<\/strong><\/li><\/ul>\n\n\n\n<p>One of the peculiar features of AVLib is its ability to stream video and audio from action cameras on the fly. To enable this feature, you need to work simultaneously with two network interfaces on the side of the module in C. The task was completed successfully but demanded thorough research of the source code of Android OS and continuous debugging.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Building the broadcast life cycle<\/strong><\/li><\/ul>\n\n\n\n<p>Another significant challenge that we encountered during the development phase was enabling smooth work with the camera and processing of the life cycle on different devices. That was rather time-consuming and required lots of scrutinizing work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How you can try AVLib to see if this solution works for you<\/strong><\/h2>\n\n\n\n<p>You can give AVLib a try by&nbsp;requesting a demo app&nbsp;that demonstrates the basic capacity of the RTMP library. With this demo app, you\u2019ll be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>stream live video from your smartphone to your YouTube account,<\/li><li>evaluate the basic functionality of AVLib and<\/li><li>see how easy and fast it is.<\/li><\/ul>\n\n\n\n<p>With the demo app, you\u2019ll also receive a detailed instruction and access to the app\u2019s source code on GitHub. The&nbsp;instruction contains examples of how AVLib works with action cameras.<\/p>\n\n\n\n<p>To get a free demo for AVLib, fill out the request form on this page or&nbsp;<a href=\"https:\/\/alternative-spaces.com\/\">contact our team directly<\/a>.<\/p>\n\n\n\n<p>Content created by our partner, Onix-systems. <br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Live video streaming is a really big thing. What can be easier than instantly running a live streaming app on your smartphone? It will directly broadcast you or an event taking place around you&#8230; And while you\u2019re streaming a video, your friends are watching it from their mobile devices. And all you need to make [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1258,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/posts\/1257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/comments?post=1257"}],"version-history":[{"count":5,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/posts\/1257\/revisions"}],"predecessor-version":[{"id":2526,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/posts\/1257\/revisions\/2526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/media\/1258"}],"wp:attachment":[{"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/media?parent=1257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/categories?post=1257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alternative-spaces.com\/blog\/wp-json\/wp\/v2\/tags?post=1257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}