rendering
ITools has a bit of a stick, but pushing to the server is fast.
preface
This blog post is a supplement to the iOS Live Video Preview: Meowcast App. Previous projects uploaded to Github didn’t have a push stream of integrated video. A lot of friends have asked me how to achieve this part of push stream. So, I reintegrated the RTMP push stream and incorporated it into the previous project.
Download link
Github (Full live video)
Blog details (I suggest you look together with this article)
The Nginx + RTMP server is installed on the Mac
I built the nginx+ RTMP server on my PC a long time ago, but when I built the server on my PC yesterday, I still had a bug when I manually entered the command (so, I suggest you directly copy the command, do not manually enter the command). So document a detailed set up procedure to prevent further potholes… Build nginx+ RTMP server on Mac
-
- Open the terminal and check whether it has been installed
Homebrew
Enter the command directly from the terminal
- Open the terminal and check whether it has been installed
man brewCopy the code
If the Mac is already installed, help information for some commands is displayed. Enter Q to exit and enter the second step directly. If no, run the command
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Copy the code
If after installing, you want to uninstall
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"Copy the code
Clone the nginx project locally
brew tap homebrew/nginxCopy the code
Perform installation:
brew install nginx-full --with-rtmp-moduleCopy the code
At this point, the nginx and RTMP modules are installed.
nginxCopy the code
Open http://localhost:8080 in your browser. If the following figure is displayed, the installation is successful
Successful installation
If the terminal prompts
Nginx: [emerg] Bind () to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] Bind () to 0.0.0.0:8080 failed (48: Address already in use) [emerg] Bind () to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)…..
If port 8080 is occupied, check the PORT PID
lsof -i tcp:8080Copy the code
According to the port PID, kill off (replace 9603 here with your own port 8080 PID)
kill 9603Copy the code
Then re-execute nginx and open http://localhost:8080
- 3. Configure nginx and ramp
First let’s look atnginx
Where is it installed
brew info nginx-fullCopy the code
As shown, locate the nginx.conf file
nginx.conf
By vim or clicking the Finder – > to – > input – > to folder/usr/local/etc/nginx/nginx. Conf – > use notepad tools (recommended Sublime does Text) open the nginx. Conf.
Roll straight to the last line and add after the last}(that is, the last blank, without any {})
RTMP {server {listen 1935; application rtmplive { live on; record off; }}}Copy the code
Then restart nginx(1.10.1 should be replaced with your own nginx version number, use nginx -v to check the version number).
/ usr/local/Cellar/nginx - full / 1.10.1 / bin/nginx -s reloadCopy the code
Yesterday, when executing this command, a pit appeared.(If you successfully execute the command, restart successfully, no exception, please go to the next step) When executing the command, an exception was reported
Nginx: [emerg] unknown directive "RTMP" in/usr/local/etc/nginx/nginx. Conf: 119Copy the code
RTMP becomes an unknown instruction. I quickly Google, will be one of the answers to try again, the bug still boomed. Finally, brew List looked at all installed modules and realized that it had changed nginx-full to nginx-full by typing the command manually.
Solution: Uninstall nginx
brew uninstall nginxCopy the code
Install nginx again
brew install nginx-full --with-rtmp-moduleCopy the code
Execute the command
brew install ffmpegCopy the code
Ffmpeg takes a little longer to install. If the speed is too slow, it is recommended to climb over the wall. But it’s only about 50 meters, just be patient. While waiting, install a video player VLC that supports the RTMP protocol
-
- Ffmpeg push flow
Take the one on my deskloginmovie.mp4
Prepare a video file, you can also use megithubIn the projectResource
For example, run the push stream command
- Ffmpeg push flow
ffmpeg -re -i /Users/sunlin/Desktop/loginmovie.mp4 -vcodec libx264 -acodec mac -strict -2 -f flv rtmp://localhost:1935/rtmplive/room
After streaming the video to the server, open VLC and then File-> Open Network -> Enter:
rtmp://localhost:1935/rtmplive/room
The effect is shown in figure
Fast inheritance live push stream
Prerequisites:
- Go to Github and download the latest cat project.
- Follow the instructions above to configure the nginx+ RTMP server
At first, I planned to implement the live streaming by myself, but today in the technical group chat, a friend recommended the iOS streaming framework LFLiveKit, which was opened by Youku Tudou. Written in OC, it is very suitable for learning (I also plan to study this framework in depth, there are any questions we can discuss together), integration is also very simple, a few lines of code OK.
Download good I write meow after sowing, direct search at the bottom-left Xcode ShowTimeViewController, enters ShowTimeViewController. M. Search – (IBAction)living (UIButton *)sender and replace the stream.url with your own RTMP address.
LFLiveKit already integrates CPUImage. If there is an integrated CPUImage in the project, remove the previous one. And integrating LFLiveKit requires turning off Bitcode.
Closing arguments
Now miaobo is a relatively complete live video project. Although many third parties are used, it also saves development time and improves development efficiency. I will continue to improve this project in the later stage. If you have any good idea or effect, please send me a private message on Weibo. If I can handle it, I will add it as soon as possible.
Github download address
Full version of video live: meow broadcast download address
To contact me
github