One, foreword
I do not know why, today I suddenly want to share with you the recent hot video live technology implementation ideas. Hopefully this quick and easy way to live video will help you put on a little act in front of your gay friends.
Of course, as a poor person, I am not stupid enough to buy expensive hardware and software to meet my small needs. There are so many forces to install in life, but we must bear in mind that the force must be installed at a reasonable price, in order to lose beauty.
Two, the implementation principle
Anyway, if you’re new to this, I think it’s worth sharing a little bit about how live video works before we start talking about it. If you already know, please skip this section, because I’m really only going to share the implementation principles that are easiest to understand.
The simplest implementation principle of live broadcast
As can be seen from the above figure, the so-called live video is actually the video data collected by the recording equipment is pushed to the server in the form of streaming, and then when we watch the live video, we pull the video data from the server in the form of streaming. Of course, this process also involves a series of complex coding, packet loss, jitter, delay…… A series of technical difficulties, but these are not the scope of our discussion today. We just want to do a simple live broadcasting quietly, so about the principle of live broadcasting, you can roughly understand as a big barrel has two pipes, one water, one water, so simple.
As for the technical implementation scheme of this time, I choose to implement the water pipe (Video collection and flow pushing) through Android phone (to further prove that I am poor), and the water pipe (Video pulling and playing) through THE Video label of H5 (because I am lazy). In other words, the idea of live broadcast is to collect video data in real time through the camera of your mobile phone and push it to the H5 page opened on your friend’s mobile phone to realize live video.
We will not go into all the technical difficulties mentioned just now, because from the point of view of cost, I decide to use the third-party video cloud service as our underlying technical support. After a simple selection, today we choose to achieve through Baidu’s LSS live video service (because I am poor).
Third, concrete implementation
First, a diagram will help you understand the steps of using LSS.
LSS usage procedure
1. Create live sessions
According to the above figure, the first step after we register and open the LSS service is to create a live session. Let’s start by creating a live session with the specified Settings, as shown below:
Live session creation option
Here you can see that I have highlighted the important parts in a red box. You are advised to select an appropriate transcoding template, because the default template Settings will result in the final live video, the server only forwards, keep the input resolution and bit rate unchanged. This has two drawbacks: first, it consumes more traffic and the latency may be more pronounced when the user is actually watching; Second, on iPhone, you will find that the default Video in HTML5 cannot be broadcast. This is mainly due to the iPhone’s default support for video formats. Here are the main video formats supported by the iPhone:
1. H.264 video: up to 1080p, 60 FPS, High Profile level 4.2 encoding, its audio format for aac-lc, up to 160 Kbps, 48kHz, stereo, file package format for.m4v,.mp4 and.mov;
2: MPEG-4 video: Supports 2.5Mbps, 640 x 480 pixels, 30fps, Simple Profile encoding, its audio is AAC-LC format, supports up to 160 Kbps per sound channel, 48kHz, stereo, file package formats for.m4V,.mp4 and.mov;
In a word, if you want to watch the following live broadcast directly through the Video TAB, it is recommended to choose a suitable transcoding template. For example, I just use it to install a force, so I don’t have to worry about money, so I choose a lower 640*360 resolution, and in fact, this resolution can get a good effect on mobile phones.
2, to achieve the Android terminal push stream
Firstly, download the SDK of LSS service Adnroid and do the corresponding configuration. There is one special point to mention here. The SDK package includes the following files:
SDK includes files
The introduction of jar files is not a problem. But about the introduction of so file, because the official help document is still based on Eclipse+ANT introduction method (disdain for a……) , so if you’re using Android Studio as a development tool, follow my instructions:
1. Create a jniLibs directory in the SRC /main directory.
2. Copy and paste the so file to the jniLibs directory.
Note: if there is no reference so file, may in the execution of a program when loading libraries fail, there are similar to the following the DEBUG message — Java. Lang. UnsatisfiedLinkError: Couldn’t load library xxxx from loader dalvik.system.PathClassLoader
With the SDK introduced, the next step is to consider the actual coding implementation. Here I don’t say any more nonsense, direct example of the source code, for your reference. Please click the following address to download:
Live video on Android push terminal
When you download the code, you need to replace the stream address in the application with your own actual address. For details about the address of push stream and pull stream, you can click on us to start a newly created live session, enter the session details page, and then get it here.
Get video push stream and pull address
The final APP effect is shown in the picture below:
Android video capture and push effect picture
3. Play the pull stream on the Web end
There are a number of ways to do this on the Web side, and you are free to use any third-party PLAYER that supports HLS. Of course, if you want to do some deeper attempts in the live broadcast, such as subtitles, playlists, advertising, interaction, live authorization and so on, you can also choose to use Baidu’s OWN T5 broadcast kernel.
For me, the mere need to pretend to be a pussy is obviously not enough to motivate me to continue spending time, and WHAT I need is for others to easily and directly enter the live broadcast without any restrictions, otherwise how can I pretend to be a pussy? Therefore, I chose the simplest and crude way, which is to directly make an H5 page adapted to the mobile terminal, and then use the video label in it and share it with my friends directly through wechat and other ways. The key codes are as follows:
For the sake of personal privacy, I use XXXXXXXXX instead of the key part of the above drawstream address. Please don’t pay attention to these small details. Use your own address instead.
4, pretend to force the moment
Ok, next is the last step, you just need to upload the mobile H5 page you just made to your own virtual space or cloud host, then use wechat to scan the link address and share it with your girlfriend (if you really have one…). “Or your best gay friend, you can go into fake-ass mode! Remember, don’t install force too much, easy to be thunder P……
Four, a little sigh
With the development and opening of information technology and the steady improvement of public cloud technology, some technical difficulties in the past are no longer the bottleneck that bothers us. Personally, taking video broadcast as an example, although I understand its principle, operation mechanism and key technical points, if I am not in the era of “cloud”, I have to build a video broadcast framework from scratch and apply it to actual production, display will not be a matter of a short time. Now, in half a day, WITH the help of cloud services, I can quickly complete an awesome live video function. Be grateful for this era! This is an era that belongs to our technicians!
This time to share the first here, please allow me to make an advertisement. If you find this article helpful, I’d like to ask you to do me a favor. Click the link of Suke.com, and then enter the platform to register an account (mobile phone, email or a third party login is ok, we will not disturb you). Please try our products if you have time. Fast course network is a platform focusing on the construction of mobile teaching courseware. At present, it has reached the seed round. We sincerely invite you to join us.