Home >Backend Development >Golang >Teach you to use golang to implement live broadcast and on-demand functions

Teach you to use golang to implement live broadcast and on-demand functions

藏色散人
藏色散人forward
2020-10-08 18:20:447148browse

The following column golang tutorial will introduce to you how golang implements live broadcast and on-demand functions. I hope it will be helpful to friends in need!

Teach you to use golang to implement live broadcast and on-demand functions

1. Overview

When I first started doing live broadcasts, I was still a little confused. What is push-pull streaming? , I don’t understand the format protocol at all, and there are also endless third-party interfaces. In fact, to put it simply, as shown in the picture (stolen from Tencent Live API)

In fact, the so-called push streaming is that the client of the anchor stores the broadcast content we want on the server according to a specific process. Of course, what is shown here is Tencent Cloud. After the completion, it is transcoded by the communication cloud and then allowed to be watched by the audience (pull Take), I suggest friends who are not very clear about the basics to learn about it, it is still very convenient to understand.Tencent Cloud Portal

And what we use today is not Tencent, but written in golang Open source project livego, livego portal

2.livego

To be honest, there are quite few documents. I guess the author is busy with work. I am also simple here. However, I have to mention a small bug. It is probably a problem with the go version. In go1.10, there is an error. Two values ​​are returned, but only one is written there (I can’t remember exactly where. "")

Let’s start with the rest. After setting up the environment,Start the service: execute the livego binary file to start the livego service That’s it

3.OBS

This is the standard configuration for live broadcast. I won’t go into the process. I will just say that I encountered it. The pit, as shown in the picture:

When I set up the push flow, I really didn’t know what the flow name was. I searched for a long time and experimented for a long time. Only then did I understand that if the address you have to connect to is rtmp://106.12.5.245:1935/live/push, and the live.cfg in livego is like this:

This is the same as the LIVE of AppName is the same as the LIVE in RTMP: //106.12.245: 1935/LIVE. The push address must be: rtmp://106.12.5.245:1935/livego, and the stream name can be filled in casually, as long as it is not empty. For example, if I fill in push here, then the page I will pull is :

rtmp://106.12.5.245:1935/live/push

http://106.12.5.245:7001/live/ push.flv

http://106.12.5.245:7002/live/push.m3u8

The above is the detailed content of Teach you to use golang to implement live broadcast and on-demand functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete
Previous article:About golang makeNext article:About golang make