Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bimlu/hls-duration-go
Calculates the total duration of an HLS (HTTP Live Streaming) VOD (Video on Demand)
https://github.com/bimlu/hls-duration-go
golang hls hls-duration library m3u8 manifest
Last synced: 23 days ago
JSON representation
Calculates the total duration of an HLS (HTTP Live Streaming) VOD (Video on Demand)
- Host: GitHub
- URL: https://github.com/bimlu/hls-duration-go
- Owner: bimlu
- Created: 2024-10-19T04:50:23.000Z (about 1 month ago)
- Default Branch: master
- Last Pushed: 2024-10-22T03:33:19.000Z (27 days ago)
- Last Synced: 2024-10-23T05:28:35.093Z (26 days ago)
- Topics: golang, hls, hls-duration, library, m3u8, manifest
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hls-duration-go
`hls-duration-go` is a Go library that fetches and calculates the total duration of an HLS (HTTP Live Streaming) VOD (Video on Demand). It loads the master and media playlists, processes the segments, and calculates the cumulative duration.## Features
- Fetches the HLS master and media playlists.
- Calculates the total duration of a VOD based on the media segments in the playlists.
- Supports multiple media variants from the master playlist.## Todos
- Optimize it. no need to fetch all the media manifest. only one is sufficient to calculate the duration.## Installation
Install the package using go get:```
go get github.com/bimlu/hls-duration-go
```## Usage
To use the hls-duration library in your Go project, follow the example below.### Example
```
package mainimport (
"fmt"
"github.com/bimlu/hls-duration-go"
)func main() {
// Replace the URL with your master manifest URI
duration := hlsduration.Calculate("https://d1hsxynlvbyrp1.cloudfront.net/videos/big_bunny/hls/index.m3u8")
fmt.Printf("Total duration of the VOD: %.2f seconds\n", duration)
}
```### Output
```
Total duration of the VOD: 62.28 seconds
```## API
`Calculate(masterManifestURI string) float64`
Calculates the total duration of an HLS VOD.
* Parameters:
* masterManifestURI: The URL of the master manifest .m3u8 file.
* Returns:
* The total duration of the VOD in seconds.## Testing
You can run tests using Go’s built-in testing framework. The project includes a basic test case to validate the duration calculation.
```
go test ./...
```### Example test case
```
package hlsdurationimport (
"fmt"
"testing"
)func TestCalculateSimple(t *testing.T) {
t.Run("simple test", func(t *testing.T) {
duration := Calculate("https://d1hsxynlvbyrp1.cloudfront.net/videos/big_bunny/hls/index.m3u8")
fmt.Printf("duration: %v\n", duration)
if duration != 62.280000 {
t.Errorf("Calculate() = %v, want %v", duration, 62.280000)
}
})
}
```## License
This project is licensed under the MIT License