To realize the source code of app live mall, start with a simple live broadcast system

Software and hardware environment

  • ubuntu 16.04
  • Android Studio 2.1.3
  • OTT BOx with android 5.1.1
  • nginx 1.11.3
  • nginx-rtmp-module
  • vitamio

preface

At present, live broadcasting has become a hot word on the Internet. It not only refers to the real-time broadcasting of traditional radio and television, but also an extension of a wider range of audio and video real-time sharing. Previously, the source code data source of APP live mall could only come from TV stations and program production centers, but now, based on the rapid development of computer technology, anyone can complete the production of content alone, and then use the terminal equipment around to share. You can not only be the audience, but also become the protagonist. It can be said that the current popular "online Red" culture has made great contributions to the source code of APP live mall. This paper aims to build the simplest app live mall source code, including server and android client, using nginx, nginx RTMP, vitamio and ffmpeg.

rtmp protocol

RTMP is the abbreviation of Real Time Messaging Protocol. It is a network protocol designed for real-time data communication. It is a protocol family, including rtmpe, rtmpt, rtmps, etc. it is a common network protocol for the source code of app live mall

Server configuration

nginx adds rtmp support

Download version 1.11.3, and then download the rtmp patch of nginx. The downloaded files are placed in the directory / home/djstava (please modify them according to the actual situation), and then start compiling nginx

tar xvf nginx-1.11.3.tar.gz
cd nginx-1.11.3
mkdir build
./configure --prefix=/home/djstava/nginx-1.11.3/build --add-module=/home/djstava/nginx-rtmp-module
make -f objs/Makefile
make install

If a fallthrough error occurs

The objs/Makefile needs to be modified and added in CFLAGS

-Wno-implicit-fallthrough

Modify the configuration file nginx.conf

Edit / home/djstava/nginx-1.11.3/build/conf/nginx.conf and add the following at the end of the file

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application myapp {
            live on;

            # sample play/publish handlers
            #on_play http://localhost:8080/on_play;
            #on_publish http://localhost:8080/on_publish;

            # sample recorder
            #recorder rec1 {
            #    record all;
            #    record_interval 30s;
            #    record_path /tmp;
            #    record_unique on;
            #}

            # sample HLS
            #hls on;
            #hls_path /tmp/hls;
            #hls_sync 100ms;
        }

        # Video on demand
        #application vod {
        #    play /var/Videos;
        #}

        # Video on demand over HTTP
        #application vod_http {
        #    play http://localhost:8080/vod/;
        #}
    }
}

Start nginx service

Execute command

/home/djstava/nginx-1.11.3/build/sbin/nginx

ffmpeg push rtmp

Find a local video file and push it with ffmpeg. The command is

ffmpeg -re -i Moonlight treasure box of Dahua journey to the West.BD1280 Chaoqing Guoyue bilingual Chinese English double characters.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost/myapp/mystream

If the server of the app live mall source code is not local, replace localhost with the corresponding IP address

ffplay play test

After the service is started, the source code of the app live mall can be tested. If ffplay is not installed, vlc can also be used

ffplay rtmp://localhost/myapp/mystream

Postscript

The previous steps are carried out locally. However, in the practical application of the source code of app live mall, the situation will be much more complex. nginx may be one server and ffmpeg streaming may be another server. In this case, the localhost can be replaced with the corresponding IP address. If the data source is from the camera, you can also push it through ffmpeg. The command is as follows

ffmpeg -f dshow -i video="Integrated Camera" -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv rtmp://10.10.10.84/myapp/mystream1

Android client playback

We have written a video player based on vitamio before. We will modify it and find MainActivity.java

private String[] files = {"rtmp demo","apple demo"};

After the item of listview is clicked, send the intent containing the playback address

Intent intent = new Intent(MainActivity.this, VitamioVideoViewActivity.class);
intent.putExtra("movieUrl", "rtmp://10.10.10.84/myapp/mystream");
startActivity(intent);

In this way, a simple live broadcast system with the source code of an app live mall is realized.

Statement: This article is forwarded by cloudleopard technology from the Note blog of the lost little bookboy. If there is any infringement, please contact the author to delete it

Tags: Nginx

Posted on Tue, 19 Oct 2021 16:46:39 -0400 by davidz