hls

package module
v3.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 23 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

介绍

该插件依赖github.com/Monibuca/plugin-ts

功能

  1. 该插件可用来拉取网络上的m3u8文件并解析后转换成其他协议
  2. 该插件可以在服务器写HLS文件,并且可以播放
  3. 配合gateway插件可以直接访问http://localhost:8080/hls/live/user1.m3u8 进行播放,其中8080端口是gateway插件配置的,live/user1是streamPath,需要根据实际情况修改
  4. 支持回放功能,即每次发布流后均会产生一个m3u8文件,可以通过该文件进行回放 http://localhost:8080/hls/live/user1/xxxxxxxxxx.m3u8 其中xxxxxxxx代表发布的时间戳(Unix时间戳)

API

参数是可变的,下面的参数live/hls是作为例子,不是固定的

  • /api/hls/list 列出所有HLS流,是一个SSE,可以持续接受到列表数据
  • /api/hls/save?streamPath=live/hls 保存指定的流(例如live/hls)为HLS文件(m3u8和ts)当这个请求关闭时就结束保存(该API仅作用于远程拉流)
  • /api/hls/pull?streamPath=live/hls&target=http://localhost/abc.m3u8 将目标HLS流拉过来作为媒体源在monibuca内以live/hls流的形式存在

配置

[HLS]
EnableWrite = false
EnableMemory = false
Fragment = 5
Window = 2
Path = "hls"
Filter = "^live"
[[AutoPullList]]
"live/hls" = "http://localhost/abc.m3u8"

EnableWrite 用来控制是否启用HLS文件写入功能 EnableMemory 用来启用内存播放模式,开启后ts数据会保存在内存中 AutoPullList 自动拉流配置,可以指定多个流,每个流的key是streamPath,value是目标地址 Filter 用来过滤发布的流,只有匹配到的流才会写入

  • 如果同时开启写入和内存模式的话,从gateway读取的ts会优先使用内存。

使用方法

  1. 创建HLS结构体实例
  2. 设置该对象的Video.Req和Audio.Req属性(用于请求m3u8文件)没有audio单独的m3u8可不设置Audio.Req属性
  3. 调用对象的Publish方法,传入流名称和上级publisher,如果没有就传本对象
  4. 使用UI界面,点击拉流转发,可以将一个远程的hls流拉入服务器中,配置StreamPath用于从服务器中播放这个流。

如果拉取远程ts文件需要cookie或者http的验证,可以将验证头设置到HLS对象的TsHead属性中。

func demo(){
    p:=new(HLS)
    p.Video.Req = http.NewRequest("GET","http://xxxx.com/demo.m3u8", nil)
    p.Publish("live/hls")
}

Documentation

Index

Constants

View Source
const (
	HLS_KEY_METHOD_AES_128 = "AES-128"
)

Variables

This section is empty.

Functions

func AudioPacketToPES

func AudioPacketToPES(ts uint32, payload []byte, aac_asc codec.AudioSpecificConfig) (packet mpegts.MpegTsPESPacket, err error)

func AudioPacketToPESPreprocess

func AudioPacketToPESPreprocess(aacRaw []byte, aac_asc codec.AudioSpecificConfig) (data []byte, err error)

func VideoPacketToPES

func VideoPacketToPES(dts uint32, pack *VideoPack, extra [][]byte) (packet mpegts.MpegTsPESPacket, err error)

Types

type HLS

type HLS struct {
	TS
	Video       M3u8Info
	Audio       M3u8Info
	TsHead      http.Header     `json:"-"` //用于提供cookie等特殊身份的http头
	SaveContext context.Context `json:"-"` //用来保存ts文件到服务器
}

HLS 发布者

func (*HLS) Publish

func (p *HLS) Publish(streamName string) (result bool)

type M3u8Info

type M3u8Info struct {
	Req       *http.Request `json:"-"`
	M3U8Count int           //一共拉取的m3u8文件数量
	TSCount   int           //一共拉取的ts文件数量
	LastM3u8  string        //最后一个m3u8文件内容
	M3u8Info  []TSCost      //每一个ts文件的消耗
}

M3u8Info m3u8文件的信息,用于拉取m3u8文件,和提供查询

type Playlist

type Playlist struct {
	io.Writer
	ExtM3U         string      // indicates that the file is an Extended M3U [M3U] Playlist file. (4.3.3.1) -- 每个M3U文件第一行必须是这个tag.
	Version        int         // indicates the compatibility version of the Playlist file. (4.3.1.2) -- 协议版本号.
	Sequence       int         // indicates the Media Sequence Number of the first Media Segment that appears in a Playlist file. (4.3.3.2) -- 第一个媒体段的序列号.
	Targetduration int         // specifies the maximum Media Segment duration. (4.3.3.1) -- 每个视频分段最大的时长(单位秒).
	PlaylistType   int         // rovides mutability information about the Media Playlist file. (4.3.3.5) -- 提供关于PlayList的可变性的信息.
	Discontinuity  int         // indicates a discontinuity between theMedia Segment that follows it and the one that preceded it. (4.3.2.3) -- 该标签后边的媒体文件和之前的媒体文件之间的编码不连贯(即发生改变)(场景用于插播广告等等).
	Key            PlaylistKey // specifies how to decrypt them. (4.3.2.4) -- 解密媒体文件的必要信息(表示怎么对media segments进行解码).
	EndList        string      // indicates that no more Media Segments will be added to the Media Playlist file. (4.3.3.4) -- 标示没有更多媒体文件将会加入到播放列表中,它可能会出现在播放列表文件的任何地方,但是不能出现两次或以上.
	Inf            PlaylistInf // specifies the duration of a Media Segment. (4.3.2.1) -- 指定每个媒体段(ts)的持续时间.
}

以”#EXT“开头的表示一个”tag“,否则表示注释,直接忽略

func (*Playlist) GetInfCount

func (pl *Playlist) GetInfCount(filename string) (num int, err error)

func (*Playlist) Init

func (pl *Playlist) Init() (err error)

func (*Playlist) WriteInf

func (pl *Playlist) WriteInf(inf PlaylistInf) (err error)

type PlaylistInf

type PlaylistInf struct {
	Duration float64
	Title    string
	FilePath string
}

type PlaylistKey

type PlaylistKey struct {
	Method string // specifies the encryption method. (4.3.2.4)
	Uri    string // key url. (4.3.2.4)
	IV     string // key iv. (4.3.2.4)
}

type TSCost

type TSCost struct {
	DownloadCost int
	DecodeCost   int
	BufferLength int
}

TSCost ts文件拉取的消耗信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL