forked from External/mediamtx
playback: accept durations written in seconds (#2979)
This commit is contained in:
parent
e6bf095a05
commit
ff70f9022e
3 changed files with 15 additions and 4 deletions
|
|
@ -1231,13 +1231,13 @@ Where:
|
||||||
|
|
||||||
* [mypath] is the path name
|
* [mypath] is the path name
|
||||||
* [start_date] is the start date in RFC3339 format
|
* [start_date] is the start date in RFC3339 format
|
||||||
* [duration] is the maximum duration of the recording in Golang format (example: 20s, 20h)
|
* [duration] is the maximum duration of the recording in seconds
|
||||||
* [format] must be fmp4
|
* [format] must be fmp4
|
||||||
|
|
||||||
All parameters must be [url-encoded](https://www.urlencoder.org/). For instance:
|
All parameters must be [url-encoded](https://www.urlencoder.org/). For instance:
|
||||||
|
|
||||||
```
|
```
|
||||||
http://localhost:9996/get?path=stream2&start=2024-01-14T16%3A33%3A17%2B00%3A00&duration=200s&format=fmp4
|
http://localhost:9996/get?path=stream2&start=2024-01-14T16%3A33%3A17%2B00%3A00&duration=200.5&format=fmp4
|
||||||
```
|
```
|
||||||
|
|
||||||
The resulting stream is natively compatible with any browser, therefore its URL can be directly inserted into a \<video> tag:
|
The resulting stream is natively compatible with any browser, therefore its URL can be directly inserted into a \<video> tag:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -22,6 +23,16 @@ const (
|
||||||
|
|
||||||
var errNoSegmentsFound = errors.New("no recording segments found for the given timestamp")
|
var errNoSegmentsFound = errors.New("no recording segments found for the given timestamp")
|
||||||
|
|
||||||
|
func parseDuration(raw string) (time.Duration, error) {
|
||||||
|
// seconds
|
||||||
|
if secs, err := strconv.ParseFloat(raw, 64); err == nil {
|
||||||
|
return time.Duration(secs * float64(time.Second)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// deprecated, golang format
|
||||||
|
return time.ParseDuration(raw)
|
||||||
|
}
|
||||||
|
|
||||||
type listEntry struct {
|
type listEntry struct {
|
||||||
Start time.Time `json:"start"`
|
Start time.Time `json:"start"`
|
||||||
Duration float64 `json:"duration"`
|
Duration float64 `json:"duration"`
|
||||||
|
|
@ -172,7 +183,7 @@ func (p *Server) onGet(ctx *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
duration, err := time.ParseDuration(ctx.Query("duration"))
|
duration, err := parseDuration(ctx.Query("duration"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid duration: %w", err))
|
p.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid duration: %w", err))
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ func TestServerGet(t *testing.T) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("path", "mypath")
|
v.Set("path", "mypath")
|
||||||
v.Set("start", time.Date(2008, 11, 0o7, 11, 23, 1, 0, time.Local).Format(time.RFC3339))
|
v.Set("start", time.Date(2008, 11, 0o7, 11, 23, 1, 0, time.Local).Format(time.RFC3339))
|
||||||
v.Set("duration", "2s")
|
v.Set("duration", "2")
|
||||||
v.Set("format", "fmp4")
|
v.Set("format", "fmp4")
|
||||||
|
|
||||||
u := &url.URL{
|
u := &url.URL{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue