From 57c2d5aecb5ef78c4f3ff1e93842cf60a92498e8 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Tue, 23 Jan 2024 20:52:05 +0100 Subject: [PATCH] add playback server (#2452) (#2906) * add playback server * add playback switch * update readme --- README.md | 40 +++ apidocs/openapi.yaml | 20 +- go.mod | 3 +- go.sum | 6 +- internal/api/api.go | 14 +- internal/conf/conf.go | 35 +- internal/conf/conf_test.go | 1 + internal/conf/credential.go | 40 ++- internal/conf/credential_test.go | 4 +- internal/conf/path.go | 50 ++- internal/core/core.go | 65 +++- internal/core/path.go | 77 ++--- internal/core/path_manager.go | 183 ++++------ internal/defs/path.go | 10 +- internal/defs/path_manager.go | 2 +- internal/playback/fmp4.go | 410 +++++++++++++++++++++++ internal/playback/fmp4_test.go | 79 +++++ internal/playback/server.go | 299 +++++++++++++++++ internal/playback/server_test.go | 228 +++++++++++++ internal/record/agent_instance.go | 13 +- internal/record/cleaner.go | 50 +-- internal/record/cleaner_test.go | 2 +- internal/record/format_fmp4_part.go | 10 +- internal/record/format_fmp4_segment.go | 8 +- internal/record/format_mpegts_segment.go | 2 +- internal/record/path.go | 54 ++- internal/record/path_test.go | 12 +- internal/servers/hls/http_server.go | 2 +- internal/servers/webrtc/http_server.go | 2 +- mediamtx.yml | 35 +- 30 files changed, 1411 insertions(+), 345 deletions(-) create mode 100644 internal/playback/fmp4.go create mode 100644 internal/playback/fmp4_test.go create mode 100644 internal/playback/server.go create mode 100644 internal/playback/server_test.go diff --git a/README.md b/README.md index c1e9ecab..0896b5c4 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ And can be recorded with: * Streams are automatically converted from a protocol to another * Serve multiple streams at once in separate paths * Record streams to disk +* Playback recordings * Authenticate users; use internal or external authentication * Redirect readers to other RTSP servers (load balancing) * Query and control the server through the API @@ -115,6 +116,7 @@ _rtsp-simple-server_ has been rebranded as _MediaMTX_. The reason is pretty obvi * [Encrypt the configuration](#encrypt-the-configuration) * [Remuxing, re-encoding, compression](#remuxing-re-encoding-compression) * [Record streams to disk](#record-streams-to-disk) + * [Playback recordings](#playback-recordings) * [Forward streams to other servers](#forward-streams-to-other-servers) * [Proxy requests to other servers](#proxy-requests-to-other-servers) * [On-demand publishing](#on-demand-publishing) @@ -1183,6 +1185,44 @@ To upload recordings to a remote location, you can use _MediaMTX_ together with If you want to delete local segments after they are uploaded, replace `rclone sync` with `rclone move`. +### Playback recordings + +Recordings can be served to users through a dedicated HTTP server, that can be enabled inside the configuration: + +```yml +playback: yes +playbackAddress: :9996 +``` + +The server can be queried for recordings by using the URL: + +``` +http://localhost:9996/get?path=[mypath]&start=[start_date]&duration=[duration]&format=[format] +``` + +Where: + +* [mypath] is the path name +* [start_date] is the start date in RFC3339 format +* [duration] is the maximum duration of the recording in Golang format (example: 20s, 20h) +* [format] must be fmp4 + +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 +``` + +The resulting stream is natively compatible with any browser, therefore its URL can be directly inserted into a \