Nginx basic Knowledge ———— in the RTMP module in the HLS topic (translation document)

Source: Internet
Author: User
Tags nginx server

I. Configuring HLS in the Rtmp module of the Nginx configuration file

Hls_key_path/tmp/hlskeys;

Prompt for error message:

the same path name "/data/hlskeys" used in/usr/local/nginx/conf/nginx.conf:178 and in/usr/local/nginx/conf/ nginx.conf:178

Workaround:

View official RTMP Source code:nginx-rtmp-module / HLS /ngx_rtmp_hls_module.c

Ngx_conf_merge_str_value (conf-> key_path,prev-> Key_path, "");

Lines No. 2346 and No. 2421 in hls/ngx_rtmp_hls_module.c are called two times should be strikethrough or commented out 2346 on a "I am here temporarily commented out" To prevent Nginx throw configuration error Nginx:[emerg] Use the same path in the following languages.

Modified configuration file:

Recompile: Nginx-rtmp-module module,

This error message does not appear on the restart side:

[Email protected]:/usr/local/nginx/conf# service nginx Restart** starting Nginx Server ...

To view the generated files, theHLS key file has been generated as follows:

[Email protected]:/tmp# lsaegis-<guid (5a2c30a2-a87d-490a-9281-6765edad7cba) >  disk_io   HLS      netio_stat               qtsingleapp-aegisg-46d2-lockfilecpu_stat                                            dump.rdb  hlskeys  qtsingleapp-aegisg-46d2  vm.log[email protected]:/tmp# cd hlskeys/[email protected] :/tmp/hlskeys# lss0000_8-156.key  s0000_8-166.key  S0000_8-176.key 

Simultaneous HLS storage files:

Playlist file:

[Email protected]:/tmp/hls# Lss0000_8-224. TS s0000_8-227. TS s0000_8- the. TS s0000_8-233. TS s0000_8-236. TS s0000_8-239. TS s0000_8-242. TS Test.txts0000_8-225. TS s0000_8-228. TS s0000_8-231. TS s0000_8-234. TS s0000_8-237. TS s0000_8- -. TS s0000_8-243. Tss0000_8-226. TS s0000_8-229. TS s0000_8-232. TS s0000_8-235. TS s0000_8-238. TS s0000_8-241. TS s0000_8.m3u8

List of encrypted files:

#EXTM3U #ext-x-version:3#EXT-x-media-sequence:239#EXT-x-targetduration:5#EXT-x-key:method=aes- -, uri="Http://sewise.amai8.com/authcheck/accesskeyS0000_8-236.key", iv=0x000000000000000000000000000000ec#EXTINF:5.013, S0000_8-239. Ts#extinf:5.014, S0000_8- -. Ts#extinf:5.013, S0000_8-241. Ts#extinf:5.013, S0000_8-242. Ts#extinf:5.014, S0000_8-243. Ts#extinf:5.013, S0000_8-244. ts

Hls_path

Syntax:HLS path Path
Context: rtmp, Server, application
Description: Sets the HLS playlist and the fragment directory. If the directory does not exist, it will be created.

Hls_fragment

Syntax:hls_fragment fragment Time
Context: rtmp, Server, application
Description: Sets the length of the HLS fragment. The default is 5 seconds.

Hls_playlist_length

Syntax:hls_playlist_length time
Context: rtmp, Server, application
Description: Sets the length of the HLS playlist. The default is 30 seconds.

Hls_playlist_length 10m;

Hls_sync

Syntax:hls_sync time
Context: rtmp, Server, application

Description: Sets the HLS timestamp synchronization threshold value. The default value is 2ms. This feature prevents crack noise after conversion from low-resolution rtmp (1KHZ) to high-resolution mpeg-ts (90KHZ).

Hls_sync 100ms;

Hls_continuous

Syntax:hls_continuous on | off
Context: rtmp, Server, application

Description: Turns on HLS continuous mode. In this mode, the HLS serial number starts where it was last stopped. Old fragments are saved. The default is off.

Hls_continuous on;

hls_nested

Syntax:hls_continuous on | off
Context: rtmp, Server, application

Description: Turns on HLS continuous mode. In this mode, the HLS serial number starts where it was last stopped. Old fragments are saved. The default is off. ...

Hls_nested on;

Hls_base_url

Syntax:hls_base_url URL
Context: rtmp, Server, application

Description: Sets the base URL for the HLS playlist item. When empty, these items do not have a prefix and are assumed to be in the same location as the parent playlist, or to lower one level when using hls_nested. This feature applies to master (variable) and from HLS playlists. It allows you to download playlists and play them locally because it contains a full reference to the sub playlist or fragment. The default is empty.

Hls_base_url http://myserver.com/hls/;

Hls_cleanup

Syntax: Hls_cleanup on | Off
Context: rtmp, Server, application

Description: Toggle HLs cleanup. By default, this feature is turned on. In this mode, the Nginx cache manager process removes old HLS fragments and playlists from the HLS directory.

Hls_cleanup off;

Hls_fragment_naming

Syntax:hls_fragment_naming Sequential | timestamp | system
Context: rtmp, Server, application

Description: Sets the fragment naming pattern.

Order-Use an incremented integer
Timestamp-Using stream timestamps
System-Use System time
The default is sequential.

Hls_fragment_naming system;

Hls_fragment_naming_granularity

Syntax:hls_fragment_naming_granularity number
Context: rtmp, Server, application

Description: Sets the granularity of the HLS fragment ID. If it is greater than 0, change the IDs to divide the supplied values. The default value is zero.

# Use system time to round to 500ms as fragment name
Hls_fragment_naming system;
Hls_fragment_naming_granularity 500;

Hls_type

Syntax:hls_type Live | event
Context: rtmp, Server, application

Description: Sets the type of HLS playlist specified in the X-playlist-type playlist directive. Live HLS flow is often played from the current active position, which is a few fragments to the end of the playlist. The event HLS stream is always played from the beginning of the playlist. In event mode, make sure that the playlist is long enough for the entire event. The default is live;

Hls_type event;

Hls_keys

Syntax:hls_keys on | off
Context: rtmp, Server, application
Description: Enables HLS encryption. The AES-128 method is used to encrypt the entire HLS fragment. Closed by default.
Hls_keys on;
Description: The following is an example configuration using HLS encryption. This configuration requires Nginx to be built using--with-http_ssl_module for HTTPS support.
..... http {    ...    server {        listen 443 SSL;        server_name example.com;        Ssl_certificate/var/ssl/example.com.cert;        Ssl_certificate_key/var/ssl/example.com.key;        Location/keys {            root/tmp;        }    }    server {        listen;        server_name example.com;        Location/hls {            root/tmp;}}}    rtmp {    server {        listen 1935;        Application MyApp {            live on;            HLS on;            Hls_path/tmp/hls;            Hls_keys on;            Hls_key_path/tmp/keys;            Hls_key_url https://example.com/keys/;            Hls_fragments_per_key;}}}    

Hls_key_path

Syntax:hls_key_path path
Context: rtmp, Server, application

Description: Sets the directory where auto-generated HLS keys are saved. The key file has a. key extension and pseudo-random 16-byte content created using the OpenSSL rand_bytes () routines. If the directory does not exist, it will be created at run time. By default, the Hls_path directory is used for key files. But remember, you should usually restrict access to key files, which are easier to store separately from playlists and fragments.

Hls_key_path/tmp/keys;

Hls_key_url

Syntax:hls_key_url URL
Context: rtmp, Server, application

Description: Sets the URL of the HLS key file entry. When empty, those items do not have a prefix and assume that the key is in the same position as the playlist. The default is empty.

Hls_key_url https://myserver.com/keys/;
Example of a playlist entry with the above settings

#EXT-x-key:method=aes-128,uri= "Https://myserver.com/keys/337.key", iv=0x00000000000000000000000000000151

Hls_fragments_per_key

Syntax:hls_fragments_per_key value
Context: rtmp, Server, application

Description: Sets the number of HLS shards encrypted with the same key. 0 means that only one key is created at the beginning of the publication and this key is used to encrypt all fragments in the session. The default value is zero.

Hls_fragments_per_key 10;

Nginx basic Knowledge ———— in the RTMP module in the HLS topic (translation document)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.