Skip to content

Commit c40f040

Browse files
Implement GenerateMasterPlaylist function for HLS video processing; update video handler to call the new function
1 parent 3167eed commit c40f040

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ go.work.sum
3333
temp/
3434

3535
bin/
36-
dist/
36+
dist/
37+
38+
index.html

internal/ffmpeg/master_playlist.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ffmpeg
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
func (s *Service) GenerateMasterPlaylist(outputDir string) error {
9+
10+
content := `#EXTM3U
11+
#EXT-X-VERSION:3
12+
13+
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
14+
1080p/index.m3u8
15+
16+
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
17+
720p/index.m3u8
18+
19+
#EXT-X-STREAM-INF:BANDWIDTH=1400000,RESOLUTION=854x480
20+
480p/index.m3u8
21+
`
22+
23+
path := filepath.Join(outputDir, "master.m3u8")
24+
25+
return os.WriteFile(path, []byte(content), 0644)
26+
}

internal/handlers/video.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ func (h *VideoHandler) ProcessVideo(
113113

114114
log.Println("HLS generated")
115115

116+
if err := h.ffmpeg.GenerateMasterPlaylist(outputDir); err != nil {
117+
return err
118+
}
119+
120+
log.Println("Master playlist generated")
121+
116122
thumbnailPath := filepath.Join(
117123
workspace,
118124
"thumbnail.jpg",

0 commit comments

Comments
 (0)