Skip to content

Commit

Permalink
Merge pull request #52 from LopanovCo/master
Browse files Browse the repository at this point in the history
Introduce TOML configuration along with JSON
  • Loading branch information
LdDl authored Oct 25, 2024
2 parents c0e0239 + c15d963 commit 92fba16
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmd/video_server/linux-video_server.zip
cmd/video_server/windows-video_server.zip
cmd/video_server/conf_token.json
video-server-ui
video_server
./video_server
linux-amd64-video_server.tar.gz
video_server.exe
./video_server.exe
windows-video_server.zip
76 changes: 28 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ video_server -h
```
```shell
-conf string
Path to configuration JSON-file (default "conf.json")
Path to configuration either TOML-file or JSON-file (default "conf.toml")
-cpuprofile file
write cpu profile to file
-memprofile file
Expand All @@ -58,7 +58,7 @@ video_server -h
### Start server
Prepare configuration file (example [here](cmd/video_server/conf.json)). Then run binary:
```shell
video_server --conf=conf.json
video_server --conf=conf.toml
```
### Test Client-Server
For HLS-based player go to [hls-subdirectory](example_client/hls_example).
Expand All @@ -85,59 +85,39 @@ Paste link to the browser and check if video loaded successfully.
You can configure application to write MP4 chunks of custom duration (but not less than first keyframe duration) to the filesystem or [S3 MinIO](https://min.io/)

- For storing archive to the filesystem. Point default directory for storing MP4 files and duration:
```json
"archive": {
"enabled": true,
"directory": "./mp4",
"ms_per_file": 30000
}
```toml
[archive]
enabled = true
directory = "./mp4"
ms_per_file = 30000
```

For each stream configuration you can override default directory and duration. Field "type" should have value "filesystem":
```json
{
///
// Some other single stream props...
///
"archive": {
"enabled": true,
"ms_per_file": 20000,
"type": "filesystem",
"directory": "custom_folder"
}
}
```toml
[[rtsp_streams]]
# ...
# Some other single stream props
# ...
archive = { enabled = true, ms_per_file = 20000, type = "filesystem", directory = "custom_folder" }
```

- For storing archive to the S3 MinIO:
Modify configuration file to have both filesystem and minio configuration (filesystem will be picked for storing temporary files before moving it to the MinIO), e.g.:
```json
"archive": {
"directory": "./mp4",
"ms_per_file": 30000,
"minio_settings": {
"host": "localhost",
"port": 29199,
"user": "minio_secret_login",
"password": "minio_secret_password",
"default_bucket": "archive_bucket",
"default_path": "/var/archive_data"
}
}
```toml
[archive]
enabled = true
directory = "./mp4"
ms_per_file = 30000
minio_settings = { host = "localhost", port = 29199, user = "minio_secret_login", password = "minio_secret_password", default_bucket = "archive-bucket", default_path = "/var/archive_data" }
```

For each stream configuration you can override default directory for temporary files, MinIO bucket and path in it and chunk duration. Field "type" should have value "minio":
```json
{
///
// Some other single stream props...
///
"archive": {
"enabled": true,
"ms_per_file": 20000,
"type": "filesystem",
"directory": "custom_folder",
"type": "minio",
"minio_bucket": "vod-bucket",
"minio_path": "/var/archive_data_custom"
}
}
```toml
[[rtsp_streams]]
# ...
# Some other single stream props
# ...
archive = { enabled = true, ms_per_file = 20000, type = "minio", "directory": "custom_folder", minio_bucket = "vod-bucket", minio_path = "/var/archive_data_custom" }
```

- If you want disable archive for specified stream, just set value of the field `enabled` to `false` in streams array. For disabling archive at all you can do the same but in the main configuration (where default values are set)
Expand Down
55 changes: 55 additions & 0 deletions cmd/video_server/conf.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[api]
enabled = true
host = "localhost"
port = 8091
mode = "release"
verbose = "v"

[video]
host = "localhost"
port = 8090
mode = "release"
verbose = "v"

[hls]
ms_per_segment = 10000
directory = "./hls"
window_size = 5
window_capacity = 10

[archive]
enabled = true
directory = "./mp4"
ms_per_file = 30000
minio_settings = { host = "localhost", port = 29199, user = "minio_secret_login", password = "minio_secret_password", default_bucket = "archive-bucket", default_path = "/var/archive_data" }

[cors]
enabled = true
allow_origins = ["*"]
allow_methods = ["GET", "PUT", "POST", "DELETE"]
allow_headers = [
"Origin",
"Authorization",
"Content-Type",
"Content-Length",
"Accept",
"Accept-Encoding",
"X-HttpRequest",
]
expose_headers = ["Content-Length"]

[[rtsp_streams]]
guid = "0742091c-19cd-4658-9b4f-5320da160f45"
type = "rtsp"
url = "rtsp://localhost:45666/live"
output_types = ["mse"]
verbose = "v"
archive = { enabled = true, ms_per_file = 10000, type = "filesystem", directory = "custom_folder" }

[[rtsp_streams]]
guid = "566bfe72-1f85-4e7d-9c0a-424e6c3b29f3"
type = "rtsp"
url = "rtsp://localhost:45664/live"
output_types = ["mse"]
verbose = "v"
archive = { enabled = true, ms_per_file = 15000, type = "minio", minio_bucket = "vod-bucket", minio_path = "/var/archive_data_custom" }
3 changes: 2 additions & 1 deletion cmd/video_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var (
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
memprofile = flag.String("memprofile", "", "write memory profile to `file`")
conf = flag.String("conf", "conf.json", "Path to configuration JSON-file")
conf = flag.String("conf", "conf.toml", "Path to configuration either TOML-file or JSON-file")
EVENT_CPU = "cpu_profile"
EVENT_MEMORY = "memory_profile"
EVENT_APP_START = "app_start"
Expand Down Expand Up @@ -53,6 +53,7 @@ func main() {
log.Error().Err(err).Str("scope", videoserver.SCOPE_CONFIGURATION).Msg("Could not prepare application configuration")
return
}

app, err := videoserver.NewApplication(appCfg)
if err != nil {
log.Error().Err(err).Str("scope", videoserver.SCOPE_CONFIGURATION).Msg("Could not prepare application")
Expand Down
Loading

0 comments on commit 92fba16

Please sign in to comment.