How to quickly develop a complete iOS live app] (push flow)

Preface

Before reading this, if you do not understand the principle of live, please check this article how to quickly develop a complete iOS live app (principle)

Development of a live app, you certainly need a streaming media server, this article mainly to explain the live streaming media server to build, and explain how to use FFMPEG encoding and push flow, and describes the FFMPEG common commands.

If you love my article, I can focus on micro-blog: Yuan Zheng Seemygo, can also be small brother iOS training course, we understand. The follow-up will be more updates, have any questions, welcome Jane Zheng Yuan Book message Seemygo…

Effect

How to quickly develop a complete iOS live app] (push flow)
Snip20161018_20.png

First, install Homebrew

Homebrew referred to as brew, is the Mac OSX package management tools, can be easily installed in the Mac software or uninstall software.

1, open the terminal to see if the Homebrew has been installed, direct terminal input command

* man command: Manual (manual) abbreviation, you can view a command of help information, such as git, brew, by the way you can see if there is a command
Man brew
How to quickly develop a complete iOS live app] (push flow)
man brew.png

2, the implementation of orders, install Homebrew

  • After executing the command, press enter, and enter the password.
Ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
How to quickly develop a complete iOS live app] (push flow)
Homebrew.png

Two, the use of installation nginx

Nginx:Nginx is a very good HTTP server, which is characterized by less memory, high concurrency, in fact, the concurrent ability of nginx in the same type of web server performance.

  1. Download Nginx from the GitHub to the local, increase the home-brew extension to nginx
Brew tap homebrew/nginx
How to quickly develop a complete iOS live app] (push flow)
brew tap.png

2 install Nginx server and RTMP module

Brew install nginx-full --with-rtmp-module
How to quickly develop a complete iOS live app] (push flow)
Snip20161017_6.png

3 check to see if the installation is successful
open the nginx server at the terminal

Nginx
  • Nginx: open nginx server

In the browser address bar input: http://localhost:8080 (direct click)
if the following figure, the installation is successful

How to quickly develop a complete iOS live app] (push flow)
Snip20161017_7.png

Three, configure RTMP

1 see nginx configuration file installed in which

Brew info nginx-full
How to quickly develop a complete iOS live app] (push flow)
Snip20161022_3.png
How to quickly develop a complete iOS live app] (push flow)
Snip20161022_4.png

2 Xcode open the configuration file, scroll to the back (the last one behind can not in {}}, inside), add code to configure, remember to save the last

How to quickly develop a complete iOS live app] (push flow)
Snip20161022_5.png
RTMP {server {listen 1990; application liveApp {live on; record off;}}}
How to quickly develop a complete iOS live app] (push flow)
Snip20161017_11.png
  • Application: streaming media application name, you can fill
  • Record off: picture is wrong, do not record data

3 reload nginx configuration file

Nginx -s reload

Four, the installation of ffmepg push

Brew install ffmpeg
How to quickly develop a complete iOS live app] (push flow)
Snip20161017_10.png

Five, the use of ffmepg push test

Ffmpeg -re -i (video full path) -vcodec copy -f (RTMP path ffmpeg -i /Users/yuanzheng/Desktop/02- how to learn the project.Mp4 -vcodec -f flv copy rtmp://localhost:1990/liveApp/room) flv
  • Need to configure the one-to-one correspondence, the port, the application name, room can write
  • Delay: the time required to send streaming media data. Otherwise, FFmpeg processing data is very fast, the moment will be able to send out all the data, streaming media server is unacceptable. Therefore, it is necessary to send the data according to the actual frame rate of the video
  • -re: must be added, according to the representative frame rate sent, otherwise ffmpeg will fall to send data to the highest efficiency
  • -i: input file
  • -vcodec copy: mandatory use of codec codec, to add, otherwise ffmpeg will re encode the input H.264 nude
  • -f format, format, format
  • Detailed explanation of ffmpeg parameters in Chinese

Six, the use of VLC play RTMP push

1 download VLC

2 open VLC, enter the live address, CMD + N

How to quickly develop a complete iOS live app] (push flow)
Snip20161018_15.png
How to quickly develop a complete iOS live app] (push flow)
Snip20161018_16.png
How to quickly develop a complete iOS live app] (push flow)

! [Uploading Snip20161018_20_411856.png. “

Seven, using ffmpeg to grab the desktop and push the camera to live

1 first check whether the ffmpeg supports the corresponding device, OSX, Video and Audio devices using the avfoundation, so you can use avfoundation to view

Ffmpeg -f -list_devices true avfoundation -i""
How to quickly develop a complete iOS live app] (push flow)
Snip20161018_13.png

2 grab desktop and camera to push the flow

Ffmpeg -f avfoundation -framerate 30 -i "1:0" -f avfoundation -framerate 30 -video_size 640x480 -i "0" -c:v libx264 -preset slow -filter_complex'overlay=main_w-overlay_w-10:main_h-overlay_h-10'-acodec libmp3lame -ar -f flv rtmp:// localhost:1990/liveApp/room 44100 -ac 1
  • -f avfoundation conversion to avfoundation
  • -framerate 30: set frame rate 30
  • -i “1:0”: set output, video: Capture screen audio: Built-in Microphone
  • -f avfoundation -framerate 30 640×480 -video_size: setting frame rate and video size
  • -c:v libx264 set video coding, H.264 coding is the same as the advantages of clarity, the smaller the shortcomings of the video file is slow conversion
  • The benefits of the -c:v flv standard FLV coding are fast and high definition video files will be relatively large
  • -preset slow slow mode delay with high resolution
  • Ffmpeg transcoding delay testing and setting optimization
  • -filter_complex’overlay=main_w-overlay_w-10:main_h-overlay_h-10′: video watermark
  • -acodec libmp3lame specifies the audio processing mode
  • -ac 1 channel selection
  • -ar 44100 audio Hz