One . lal brief introduction
lal It is an open source live streaming media network transmission project , It mainly consists of three parts :
- lalserver: Streaming media forwarding server . Be similar to
nginx-rtmp-module
Etc , But support more agreements , Provide more functions . - demo: Some small applications , Like pushing 、 Pull stream client , Pressure measuring tool , Flow analysis tools , Scheduling example program, etc . Be similar to ffmpeg、ffprobe And so on .
- pkg: Streaming media protocol library . Be similar to ffmpeg Of libavformat Such as the library .
Here are lal Source code architecture diagram , You can get a general idea from it lal How to divide the functional hierarchy :
lal github Address : https://github.com/q191201771...
Two . lalserver Quick start
1 compile
The way 1, Compile from the source code
$git clone https://github.com/q191201771/lal.git
$cd lal
$export GO111MODULE=on && export GOPROXY=https://goproxy.cn,https://goproxy.io,direct
$make
Or use GoLand etc. IDE compile .
If not installed Go compiler , May refer to 《CentOS or macOS install GoLang》,windows The operating system can search the tutorial on the Internet by itself .
The way 2, Directly download the compiled binary executable file
Point me to open 《github lal newest release Version page 》, Downloadable linux/macos/windows Platform compiled lal Binary executable (zip Compression package form ).
The way 3, Use docker
docker There are two ways , One is directly from Docker Hub Download the compiled image and run :
$docker run -it -p 1935:1935 -p 8080:8080 -p 4433:4433 -p 5544:5544 -p 8083:8083 -p 8084:8084 -p 30000-30100:30000-30100/udp q191201771/lal /lal/bin/lalserver -c /lal/conf/lalserver.conf.json
The other is based on local code and Dockerfile Generate an image of the file and run :
$git clone https://github.com/q191201771/lal.git
$cd lal
$docker build -t lal .
$docker run -it -p 1935:1935 -p 8080:8080 -p 4433:4433 -p 5544:5544 -p 8083:8083 -p 8084:8084 -p 30000-30100:30000-30100/udp lal /lal/bin/lalserver -c /lal/conf/lalserver.conf.json
2 function
$./bin/lalserver -c conf/lalserver.conf.json
3 Experience function
lalserver After the service starts , You can push and pull the flow .
3、 ... and . lalserver brief introduction
lalserver Streaming media forwarding service . Be similar to nginx-rtmp-module
service , Simply speaking , The core function of this kind of service is to forward the audio and video data sent by the streaming client to the corresponding streaming client .
but lalserver Support more agreements , Provide more functions .
1 lalserver characteristic
[x] The whole platform
- [x] Support linux/macOS/windows Multi system development 、 debugging 、 function . Support more arch such as amd64/arm64/arm32/ppc64le/mipsle/s390x
- [x] Support cross compilation . Executable files of other platforms can be compiled on any platform
- [x] Without relying on . The generated executable has no environment 、 Library dependency , It can run independently with a single file
- [x] ( Open source at the same time ) Provide executable files of each platform , It can run directly without compilation
- [x] Support docker
- [x] High performance . Multi core multithreading extension
- [x] Multiple live stream encapsulation protocols . Support RTMP/RTSP/HTTP-FLV/HTTP-TS/HLS, Support the conversion between different encapsulation protocols
- [x] Multiple encoding formats . Video support H264/AVC,H265/HEVC, Audio support AAC
- [x] Record in multiple formats . Support FLV, Long MPEGTS,HLS Recording (HLS Live broadcast and recording can be started at the same time )
- [x] HTTPS. Support HTTPS-FLV,HTTPS-TS,HLS over HTTPS Pull flow
- [x] WebSocket/WebSockets. Support Websocket-FLV,WebSocket-TS Pull flow
- [x] HLS. Support live broadcast 、 Full list live broadcast . Slice files support multiple deletion methods . Support memory slicing
- [x] RTSP. Support over TCP(interleaved Pattern ). Support basic/digest auth verification . Support
GET_PARAMETER
. Compatible with various common interfaces H264/H265/AAC Realization - [x] RTMP. Full support RTMP agreement , Compatible with various common interfaces RTMP Realization . Support adding mute audio data to single video , Support merge sending
- [x] HTTP API Interface . Used to obtain service information , Send a command to the service .
- [x] HTTP Notify Event callback .
- [x] Multiple authentication methods are supported
- [x] Distributed cluster .
- [x] static state pull Back to the source . Configure the source address through the configuration file
- [x] static state push Turn to push . Support forwarding multiple addresses . Configure the forwarding address through the configuration file
- [x] CORS Cross domain . Support HTTP-FLV,HTTP-TS,HLS Cross domain pull flow
- [x] HTTP File server . such as HLS Slice files can be played directly , No additional HTTP File server
- [x] Listening port multiplexing .HTTP-FLV,HTTP-TS,HLS The same port can be used .over HTTPS similar
- [x] Seconds to play .GOP buffer
2 lalserver Supported protocols
Support for conversion between encapsulation protocols
Sub package type | sub rtmp | sub http[s]/websocket[s]-flv | sub http[s]/websocket[s]-ts | sub hls | sub rtsp | relay push rtmp |
---|---|---|---|---|---|---|
pub rtmp | ||||||
pub rtsp | ||||||
relay pull rtmp | X | . |
The support of each encapsulation protocol to the coding protocol
The encoding type | rtmp | rtsp | hls | flv | mpegts |
---|---|---|---|---|---|
aac | |||||
avc/h264 | |||||
hevc/h265 |
Type of recording file
Recording type | hls | flv | mpegts |
---|---|---|---|
pub rtmp | |||
pub rtsp |
The meaning of the table is shown in : Connection type session pub/sub/push/pull
Be careful , If it's just rtsp flow ( Exactly rtp package ) Forward to each other , It does not involve converting to other formats , Theoretically, other coding types also support .
3 lalserver Characteristic diagram
lal github Address : https://github.com/q191201771...
Four . lalserver Push and pull flow of each protocol url Address list
agreement | url Address | Protocol standard port |
---|---|---|
RTMP Push flow | rtmp://127.0.0.1:1935/live/test110 | 1935 |
RTSP Push flow | rtsp://localhost:5544/live/test110 | 554 |
. | . | . |
RTMP Pull flow | rtmp://127.0.0.1:1935/live/test110 | 1935 |
HTTP-FLV Pull flow | http://127.0.0.1:8080/live/test110.flv https://127.0.0.1:4433/live/test110.flv (https Address ) | 80 443 |
WebSocket-FLV Pull flow | ws://127.0.0.1:8080/live/test110.flv wss://127.0.0.1:4433/live/test110.flv (websockets Address ) | 80 443 |
HLS(m3u8+ts) Pull flow | http://127.0.0.1:8080/hls/test110.m3u8 ( Live address format 1) http://127.0.0.1:8080/hls/test110/playlist.m3u8 ( Live address format 2) http://127.0.0.1:8080/hls/test110/record.m3u8 ( Full volume recording and broadcasting address ) | 80 |
RTSP Pull flow | rtsp://localhost:5544/live/test110 | 554 |
HTTP-TS Pull flow | http://127.0.0.1:8080/live/test110.ts (http Address ) https://127.0.0.1:4433/live/test110.ts (https Address ) ws://127.0.0.1:8080/live/test110.ts (websocket Address ) wss://127.0.0.1:4433/live/test110.ts (websockets Address ) | 80 443 80 443 |
About ports
If the protocol standard port is used , The port in the address can be omitted , such as http The default port is 80, be http://127.0.0.1:80/live/test110.flv
become http://127.0.0.1/live/test110.flv
If you are not familiar with how push-pull streaming clients work together , May refer to Summary of common push-pull stream client information
lal github Address : https://github.com/q191201771...
5、 ... and . lalserver Profile description
{
"# doc of config": "https://pengrl.com/lal/#/ConfigBrief", //. The document description link corresponding to the configuration file , There is no practical use in the program
"conf_version": "0.2.8", //. Configuration file version number , The business party should not manually modify , This version will be checked in the program
// Whether the number is consistent with that declared in the code
"rtmp": {
"enable": true, //. Open or not rtmp Service monitoring
// Be careful , The configuration file controls the of each protocol type enable All switches should be turned on as needed , Avoid unnecessary protocol conversion overhead
"addr": ":1935", //. RTMP The port the service listens on , Client to lalserver Push and pull streams are all this address
"gop_num": 0, //. RTMP Pull flow GOP Number of caches , Acceleration flow on time , But it may increase the delay
//. If 0, Then the cache is not used to send
"merge_write_size": 0, //. Combine small packets of data and send them , Unit byte , Improve server performance , But it could cause Caton
// If 0, Send without merging
"add_dummy_audio_enable": false, //. Whether to enable dynamic detection and add mute AAC The function of data
// If open ,rtmp pub Plug flow , If exceeded `add_dummy_audio_wait_audio_ms` Time is still running out
// Received audio data , It will automatically stack this flow AAC The data of
"add_dummy_audio_wait_audio_ms": 150 //. Unit millisecond , Specific view `add_dummy_audio_enable`
},
"default_http": { //. http Default configuration for listening , If hls, httpflv, httpts The following configuration items are not separately configured in ,
// Then use default_http Configuration in
// Be careful ,hls, httpflv, httpts Whether the service is on , Not decided here
"http_listen_addr": ":8080", //. HTTP Monitor address
"https_listen_addr": ":4433", //. HTTPS Monitor address
"https_cert_file": "./conf/cert.pem", //. HTTPS The local cert File address
"https_key_file": "./conf/key.pem" //. HTTPS The local key File address
},
"httpflv": {
"enable": true, //. Open or not HTTP-FLV Service monitoring
"enable_https": true, //. Open or not HTTPS-FLV monitor
"url_pattern": "/", //. Pull flow url Routing path address . The default value is `/`, It means unrestricted , The routing address can be any path address .
// If set to `/live/`, Only from `/live/` Path drop-down flow , such as `/live/test110.flv`
"gop_num": 0 //. see rtmp.gop_num
},
"hls": {
"enable": true, //. Open or not HLS Service monitoring
"enable_https": true, //. Open or not HTTPS-HLS monitor
//
"url_pattern": "/hls/", //. Pull flow url Routing address , The default value is `/hls/`, Corresponding HLS(m3u8) Pull flow url Address :
// - `/hls/{streamName}.m3u8`
// - `/hls/{streamName}/playlist.m3u8`
// - `/hls/{streamName}/record.m3u8`
//
// playlist.m3u8 The file corresponds to the live broadcast hls, Only... Is saved in the list <fragment_num> individual ts File name , Will continue to increase
// Add newly generated ts file , And remove expired ts file
// record.m3u8 File corresponds to recording hls, The list will be saved from the first ts File to the latest generated ts file , Will hold
// Continue to add the newly generated ts file
//
// ts The address of the document is as follows :
// - `/hls/{streamName}/{streamName}-{timestamp}-{index}.ts` or
// `/hls/{streamName}-{timestamp}-{index}.ts`
//
// Be careful ,hls Of url_pattern Unable to join httpflv、httpts Of url_pattern identical
//
"out_path": "./lal_record/hls/", //. HLS Of m3u8 And the output root directory of the file
"fragment_duration_ms": 3000, //. Single TS File slicing time , Unit millisecond
"fragment_num": 6, //. playlist.m3u8 File list ts Number of documents
//
"delete_threshold": 6, //. ts When to delete a file
// Be careful , Only in configuration items `cleanup_mode` by 2 When using
// The meaning is to save only the most recent from playlist.m3u8 Removed from ts Number of files , Expired earlier ts The file will be deleted
// without , The default value is the configuration item `fragment_num` Value
// Be careful , This value should not be less than 1, Avoid deleting too fast and causing playback failure
//
"cleanup_mode": 1, //. HLS File cleanup mode :
//
// 0 Don't delete m3u8+ts file , It can be used for recording and other scenes
//
// 1 Delete... After the input stream ends m3u8+ts file
// Be careful , The exact deletion time point is after the end of streaming
// `fragment_duration_ms * (fragment_num + delete_threshold)`
// Postpone for a short time to delete , To avoid the input stream just ending ,HLS The pulling end of has not been pulled yet
//
// 2 In the process of streaming , Continue to delete expired ts file , Keep only the latest
// `delete_threshold + fragment_num + 1`
// About ts file
// also , At the end of the input stream , Clean up mode will also be executed 1 The logic of
//
// Be careful ,record.m3u8 Only in 0 and 1 Mode
//
"use_memory_as_disk_flag": false //. Whether to use memory instead of disk , preservation m3u8+ts file
// Be careful , When using this mode, pay attention to the memory capacity . Generally speaking, it should not match `cleanup_mode` by 0 or 1 Use
},
"httpts": {
"enable": true, //. Open or not HTTP-TS Service monitoring . Be careful , This is not HLS Medium TS, But in a HTTP Persistent transmission over long connections TS flow
"enable_https": true, //. Open or not HTTPS-TS monitor
"url_pattern": "/" //. Pull flow url Routing path address . The default value is `/`, It means unrestricted , The routing address can be any path address .
// If set to `/live/`, Only from `/live/` Path drop-down flow , such as `/live/test110.ts`
},
"rtsp": {
"enable": true, //. Open or not rtsp Service monitoring , Currently only supported rtsp Push flow
"addr": ":5544" //. rtsp Streaming address
},
"record": {
"enable_flv": true, //. Open or not flv Recording
"flv_out_path": "./lal_record/flv/", //. flv Recording Directory
"enable_mpegts": true, //. Open or not mpegts Recording . Be careful , Here is long ts File recording ,hls Recorded by the above hls Configuration control
"mpegts_out_path": "./lal_record/mpegts" //. mpegts Recording Directory
},
"relay_push": {
"enable": false, //. Whether to turn on the relay push function , After opening , All streams received by itself will be pushed out
"addr_list":[ //. The address of the opposite end of the relay forwarding , Support to fill in multiple addresses , do 1 Yes n Turn and push . Format example "127.0.0.1:19351"
]
},
"relay_pull": {
"enable": false, //. Whether to turn on the function of pulling flow back to the source , After opening , When it receives a streaming request , When the stream does not exist , This stream will be pulled from other servers to the local server
"addr": "" //. The address of the pull stream back to the source . Format example "127.0.0.1:19351"
},
"http_api": {
"enable": true, //. Open or not HTTP API Interface
"addr": ":8083" //. Monitor address
},
"server_id": "1", //. At present lalserver only ID. Multiple lalserver HTTP Notify At the same address , Through this ID distinguish
"http_notify": {
"enable": true, //. Open or not HTTP Notify Event callback
"update_interval_sec": 5, //. update Event callback interval , Unit millisecond
"on_server_start": "http://127.0.0.1:10101/on_server_start", //. Events HTTP Notify Event callback address
"on_update": "http://127.0.0.1:10101/on_update",
"on_pub_start": "http://127.0.0.1:10101/on_pub_start",
"on_pub_stop": "http://127.0.0.1:10101/on_pub_stop",
"on_sub_start": "http://127.0.0.1:10101/on_sub_start",
"on_sub_stop": "http://127.0.0.1:10101/on_sub_stop",
"on_rtmp_connect": "http://127.0.0.1:10101/on_rtmp_connect"
},
"simple_auth": { // For authentication documents, see : https://pengrl.com/lal/#/auth
"key": "q191201771", // private key, Calculation md5 Use... When authenticating parameters
"dangerous_lal_secret": "pengrl", // Back door authentication parameters , All streams can be authenticated by this parameter value
"pub_rtmp_enable": false, // rtmp Whether authentication is enabled for streaming ,true To enable authentication ,false To disable authentication
"sub_rtmp_enable": false, // rtmp Whether authentication is enabled for streaming
"sub_httpflv_enable": false, // httpflv Whether authentication is enabled for streaming
"sub_httpts_enable": false, // httpts Whether authentication is enabled for streaming
"pub_rtsp_enable": false, // rtsp Whether authentication is enabled for streaming
"sub_rtsp_enable": false, // rtsp Whether authentication is enabled for streaming
"hls_m3u8_enable": true // m3u8 Whether authentication is enabled for streaming
},
"pprof": {
"enable": true, //. Open or not Go pprof web Service monitoring
"addr": ":8084" //. Go pprof web Address
},
"log": {
"level": 1, //. The level of logging ,0 trace, 1 debug, 2 info, 3 warn, 4 error, 5 fatal
"filename": "./logs/lalserver.log", //. Log output file
"is_to_stdout": true, //. Whether to print to the sign console output
"is_rotate_daily": true, //. Logs roll by day
"short_file_flag": true, //. Whether the source file name and line number information are carried at the end of the log
"assert_behavior": 1 //. The behavior of log assertions ,1 Print error log only 2 Print and exit the program 3 Print and panic
},
"debug": {
"log_group_interval_sec": 30, // Print group The interval between debugging logs , Unit second . If 0, Do not print
"log_group_max_group_num": 10, // Maximum number of prints group
"log_group_max_sub_num_per_group": 10 // Every group Maximum number of prints sub session
}
}
6、 ... and . Demo brief introduction
lal In the project , except /app/lalserver In addition to this core service , stay /app/demo
The directory also provides some additional small applications , Function introduction :
| demo | explain |
| - | - |
| pushrtmp | RTMP Push streaming client ; Pressure test tools |
| pullrtmp | RTMP Pull stream client ; Pressure test tools |
| pullrtmp2pushrtmp | Pull... From the remote server RTMP flow , And use RTMP Turn and push out , Support 1 Yes n Turn to push |
| pullrtmp2pushrtsp | Pull... From the remote server RTMP flow , And use RTSP Turn and push out |
| pullrtmp2hls | Pull... From the remote server RTMP flow , Store as local m3u8+ts file |
| pullhttpflv | HTTP-FLV Pull stream client |
| pullrtsp | RTSP Pull stream client |
| pullrtsp2pushrtsp | Pull... From the remote server RTSP flow , And use RTSP Turn and push out |
pullrtsp2pushrtmp | Pull... From the remote server RTSP flow , And use RTMP Turn and push out |
---|---|
benchrtmpconnect | Yes rtmp Do concurrent build-up stress tests |
calcrtmpdelay | test rtmp The delay of sending and receiving data from the server |
analyseflv | Pull... From the remote server HTTP-FLV flow , And analyze |
dispatch | A simple demonstration of how to implement a simple scheduling service , Make more than one lalserver Nodes can form a cluster |
flvfile2es | Will local FLV Separate files into H264/AVC and AAC Of ES Streaming files |
modflvfile | modify flv Some information about the file ( Such as some tag The timestamp ) Save as file after |
( For more specific functions, please refer to the header description of each source file )
7、 ... and . Contact the author
- mailbox :[email protected]
- WeChat : q191201771
- QQ: 191201771
- Wechat group : After adding my wechat friend , Tell me to pull you into the group
- QQ Group : 1090510973
- lal github Address : https://github.com/q191201771...
- lal Official documents : https://pengrl.com/lal
Welcome any technical and non-technical exchanges .