This article introduces the basic fields of HLS, but it is not enough to know the basic fields. This article takes you to know the advanced fields of HLS, so that you can have a deeper understanding of HLS.

EXT-X-BYTERANGE

We know that M3U8 needs to be sliced, but sometimes we don’t want to slice (why? I’m lazy), I just want to use a TS to build a sharded index like M3U8, where ext-X-Byterange comes in handy. The format of the expression is as follows:

#EXT-X-BYTERANGE:<length>[@<offset>]
Copy the code

Where length indicates the length of range, offset indicates the position from which range is read in the fragment. Here’s an example:

#EXTM3U # ext-x-targetDuration :11 # ext-x-media-sequence :0 # ext-x-version :4 #EXTINF:9.009, # ext-x-byterange :12345@0 media.ts #EXTINF:9.009, # ext-X-byterange :82112@12345 media.ts #EXTINF:3.003, #EXT-X-BYTERANGE:69864 media.ts #EXT-X-ENDLISTCopy the code

In the M3U8 index file, there is only one shard file, media.ts, which can be very large. The first shard to be specified reads 12345 bytes from position 0 of media.ts. The second specified shard reads 82112 bytes from position 12345 of media.ts; The third one does not specify offset, so it defaults to read from the end of the previous one. Of course, this property can only be applied if VERSION is at least 4

EXT-X-KEY

The # ext-X-key field in the M3U8 index file indicates that the current M3U8 video clip may be encrypted. This line tells you how to decrypt these video fragments. The format of the expression is as follows:

#EXT-X-KEY:<attribute-list>
Copy the code

The property list has the following fields:

  • METHOD

This is an enumeration value. It can be NONE, AES-128, or sample-AES NONE. The sharding is not encrypted

  • URI

The location where the key is stored is also a URL

  • IV

The value is a hexadecimal sequence that specifies the 128-bit unsigned integer initialization vector to be used with the key

  • KEYFORMAT

The format of this key, optional field, is “identity” by default, and is used to enforce digital certificate verification security.

M3U8 encryption and decryption is very important, is one of the advantages of M3U8, after all, modern society is paying more and more attention to security, copyright awareness is also very important. The decryption process needs to be described in a special article.

EXT-X-MAP

This field is the initialization fragment of the video. In short, with this field, it means that every subsequent fragment file must pass this initialization fragment to be fully interpreted. Without this initialization fragment, M3U8 video cannot be played at all. The format of the expression is as follows:

#EXT-X-MAP:<attribute-list>
Copy the code

This property set has the following fields:

  • URI

Initialize the address of the fragment. This information is required.

  • BYTERANGE

See the # ext-X-Byterange field for this

To everyone according to an example: europe.olemovienews.com/hlstimeofff… There was one line:

#EXT-X-MAP:URI="init-v1-a1.mp4"
Copy the code

Illustrate the follow-up every shard needs the init – v1 – a1. Mp4 can truly decoding broadcast: take out the first subdivision: europe.olemovienews.com/hlstimeofff…

Copyright (c) 2007-2020 The FFmpeg developers built with GCC 9 (Ubuntu 9.3.0-10Ubuntu2)  configuration: -- prefix = / usr - extra - version = 1 ubuntu0. 1 - toolchain = hardened - libdir = / usr/lib/x86_64 - Linux - gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi  --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56.31.100/56.31.100 libavCodec 58.54.100/58.54.100 libavformat 58.29.100/58.29.100 Libavdevice 58.8.100/58.8.100 libavFilter 7.57.100/7.57.100 libavresample 4.0/4.0 libswScale 5.5.100 Libpostproc 55.5.100/55.5.100 [mov,mp4,m4a,3gp,3g2, mj2@ 0x55fd8bd5ff00] could not find corresponding trex (id 1) [mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fd8bd5ff00] could not find corresponding track id 0 [mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fd8bd5ff00] trun track id unknown, no tfhd was found [mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fd8bd5ff00] error reading header https://europe.olemovienews.com/hlstimeofffmp4/20210226/fICqcpqr/mp4/fICqcpqr.mp4/seg-1-v1-a1.m4s: Invalid data found when processing inputCopy the code

This is because optical resolution of the first shard is not possible, because the real video header information is in init-v1-A1.mp4.

EXT-X-I-FRAMES-ONLY

This field means that each clip has only one I frame, and I frame should be pretty clear to you, sound, sound and video guys, why is this field there? Those of you who have done video effects know that it’s very convenient to do effects/reverse/fast forward/fast rewind if you’re doing all I frames.

Of course, # ext-x-i-frames -ONLY is not used much on M3U8.

EXT-X-MEDIA

This field represents different interpretations of the same content, such as a single video with video/audio/subtitles, or even more than one audio track, subtitles in many languages, and so much information on a single video. # ext-X-Media does this. The format of the expression is as follows:

#EXT-X-MEDIA:<attribute-list>
Copy the code

The property set has the following fields:

  • TYPE

This is an enumeration value, which could be AUDIO, VIDEO, SUBTITLES, closed-captions, this field is required.

  • URI

The URL of the data source, if TYPE is closed-captions, the URI is gone

  • GROUP-ID

Represents the group ID to which the source belongs, which is just an identifier

  • DEFAULT

YES 或者 NO

  • AUTOSELECT

YES or NO for example:

#EXTM3U #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="test_audio",LANGUAGE="eng",NAME="Test Audio",AUTOSELECT=NO,DEFAULT=NO,URI="test_audio_aac/index.m3u8" #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",CHARACTERI STICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="subtitles/eng/index.m3u8" # EXT - X - STREAM - INF: BANDWIDTH = 263851, CODECS = "mp4a. 40.2, Avc1.4 d400d, "RESOLUTION = 416 x234, AUDIO =" test_audio ", SUBTITLES = "subs high_test/index. M3u8. # EXT - X - STREAM - INF: BANDWIDTH = 41457, CODECS = "mp4a. 40.2", AUDIO = "test_audio", SUBTITLES = "subs" middle_test/index. M3u8Copy the code

HLS example

1.HLS Basic examples:

# # EXTM3U EXT - X - TARGETDURATION: 10 # EXT - X - VERSION: 3 # EXTINF: 9.009, http://media.example.com/first.ts # EXTINF: 9.009, http://media.example.com/second.ts # EXTINF: 3.003, http://media.example.com/third.ts # EXT - X-ray ENDLISTCopy the code

2. Examples of live streaming:

#EXTM3U # ext-x-version :3 # ext-x-targetDuration :8 # ext-x-media-sequence :2680 #EXTINF:7.975, https://priv.example.com/fileSequence2680.ts # EXTINF: 7.941, https://priv.example.com/fileSequence2681.ts # EXTINF: 7.975, https://priv.example.com/fileSequence2682.tsCopy the code

3. Master HLS:

#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=1280000,AVERAGE-BANDWIDTH=1000000 http://example.com/low.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=2560000,AVERAGE-BANDWIDTH=2000000 http://example.com/mid.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=7680000,AVERAGE-BANDWIDTH=6000000 http://example.com/hi.m3u8 # EXT - X - STREAM - INF: BANDWIDTH = 65000, CODECS = "mp4a. 40.5" http://example.com/audio-only.m3u8Copy the code

4. EXT – X – MEDIA examples:

#EXTM3U #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="English", \ DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="en", \ URI="main/english-audio.m3u8" #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Deutsch", \ DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="de", \ URI="main/german-audio.m3u8" #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="Commentary", \ DEFAULT=NO,AUTOSELECT=NO,LANGUAGE="en", \ URI="commentary/audio-only.m3u8" #EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS="..." ,AUDIO="aac" low/video-only.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS="..." ,AUDIO="aac" mid/video-only.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=7680000,CODECS="..." / video, AUDIO = "aac" hi - only. M3u8 # EXT - X - STREAM - INF: BANDWIDTH = 65000, CODECS = "mp4a. 40.5", AUDIO = "aac" main/English - AUDIO. M3u8Copy the code