Skip to content

Commit f3a0847

Browse files
committed
update post
1 parent 49ead4c commit f3a0847

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

_posts/2022-05-27-hls_intro.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,76 @@ Easy to integrate with existing key server infrastructure
9292
流程
9393
![HLS_fair_play](/assets/img/post/post-2022-05-27/hls_fair_play.png){: width="972" height="589" .normal}_HLS Fair Play_
9494

95-
## 遇到的问题
95+
## 推流 Demo
96+
Conceptually, HTTP Live Streaming consists of three parts: the server component, the distribution component, and the client software.
97+
In a typical configuration, a hardware encoder takes audio-video input, encodes it as HEVC video and AC-3 audio, and outputs a fragmented MPEG-4 file or an MPEG-2 transport stream. A software stream segmenter then breaks the stream into a series of short media files, which are placed on a web server. The segmenter also creates and maintains an index file containing a list of the media files. The URL of the index file is published on the web server. Client software reads the index, then requests the listed media files in order and displays them without any pauses or gaps between segments.
98+
99+
### 下载工具
100+
下载地址: https://developer.apple.com/download/all/?q=HLS
101+
102+
安装完发现有个 `go``example`
103+
![HLS_go_server](/assets/img/post/post-2022-05-27/hls_go_server.png){: width="972" height="589" .normal}_HLS Go Server_
104+
`brew install go`,安装 `go`,然后启动该服务
105+
106+
```bash
107+
# tony @ tonyMBP in ~/Desktop/hls_server [14:48:18]
108+
$ go run ll-hls-origin-example.go
109+
ll-hls-origin-example.go:43:2: no required module provides package github.com/fsnotify/fsnotify: go.mod file not found in current directory or any parent directory; see 'go help modules'
110+
111+
112+
# tony @ tonyMBP in ~/Desktop/hls_server [14:48:25] C:1
113+
$ go mod init hls_server
114+
go: creating new go.mod: module hls_server
115+
go: to add module requirements and sums:
116+
go mod tidy
117+
118+
119+
# tony @ tonyMBP in ~/Desktop/hls_server [14:49:23]
120+
$ go build
121+
ll-hls-origin-example.go:43:2: no required module provides package github.com/fsnotify/fsnotify; to add it:
122+
go get github.com/fsnotify/fsnotify
123+
124+
125+
# tony @ tonyMBP in ~/Desktop/hls_server [14:49:28] C:1
126+
$ go get github.com/fsnotify/fsnotify
127+
go: downloading github.com/fsnotify/fsnotify v1.5.4
128+
go: downloading golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
129+
go: added github.com/fsnotify/fsnotify v1.5.4
130+
go: added golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
131+
132+
133+
# tony @ tonyMBP in ~/Desktop/hls_server [14:49:48]
134+
$ go run ll-hls-origin-example.go
135+
Listening on http://:8443/
136+
```
137+
### 启动 mediastreamsegmenter 服务
138+
```bash
139+
$ mediastreamsegmenter -w 499 -t 1 224.0.0.50:9121 -s 16 -D -T -f ~/Desktop/hls_server/hls
140+
```
141+
142+
### 使用 ffmpeg 推流
143+
1. 使用 mac 内置采集设备
144+
```bash
145+
$ ffmpeg -f avfoundation -list_devices true -i ""
146+
147+
[AVFoundation indev @ 0x7f924d904400] AVFoundation video devices:
148+
[AVFoundation indev @ 0x7f924d904400] [0] FaceTime高清摄像头(内建)
149+
[AVFoundation indev @ 0x7f924d904400] [1] Capture screen 0
150+
[AVFoundation indev @ 0x7f924d904400] AVFoundation audio devices:
151+
[AVFoundation indev @ 0x7f924d904400] [0] LarkAudioDevice
152+
[AVFoundation indev @ 0x7f924d904400] [1] 外置麦克风
153+
[AVFoundation indev @ 0x7f924d904400] [2] MacBook Pro麦克风
154+
155+
156+
$ ffmpeg -f avfoundation -framerate 30 -pixel_format uyvy422 -i "0:" -c:v h264 -fflags nobuffer -tune zerolatency -f mpegts udp://192.168.1.5:9121
157+
```
158+
159+
2. 使用指定文件
160+
```bash
161+
$ ffmpeg -re -i "/Users/tony/Downloads/sample.mp4" -c:v h264 -fflags nobuffer -tune zerolatency -f mpegts udp://192.168.1.5:9121
162+
```
163+
164+
## 疑难问题
96165
1. `seek` 不准确如何解决?
97166
`mp4` 可以 `seek` 到指定的时间戳, `ts``seek` 到文件的某个 `position`,而不能直接 `seek` 到指定的时间点。
98167
`ffplay.c` 中的 `event_loop` 函数中包含了 `seek` 的相关代码。
570 KB
Loading

0 commit comments

Comments
 (0)