From 92c67df7b49162a3a2d598b6f0e6197ec4fc507e Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sun, 21 Aug 2022 06:56:24 +0300 Subject: [PATCH] Rewrite ffmpeg query format --- README.md | 6 +++--- cmd/ffmpeg/ffmpeg.go | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d3243c1..5c9d0ff6 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ streams: You can get any stream or file or device via FFmpeg and push it to go2rtc. The app will automatically start FFmpeg with the proper arguments when someone starts watching the stream. -Format: `ffmpeg:{input}#{params}`. Examples: +Format: `ffmpeg:{input}#{param1}#{param2}#{param3}`. Examples: ```yaml streams: @@ -141,7 +141,7 @@ streams: file2: ffmpeg:~/media/BigBuckBunny.mp4#video=h264 # [FILE] video will be copied, audio will be transcoded to pcmu - file3: ffmpeg:~/media/BigBuckBunny.mp4#video=copy&audio=pcmu + file3: ffmpeg:~/media/BigBuckBunny.mp4#video=copy#audio=pcmu # [HLS] video will be copied, audio will be skipped hls: ffmpeg:https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8#video=copy @@ -150,7 +150,7 @@ streams: mjpeg: ffmpeg:http://185.97.122.128/cgi-bin/faststream.jpg?stream=half&fps=15#video=h264 # [RTSP] video and audio will be copied - rtsp: ffmpeg:rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0#video=copy&audio=copy + rtsp: ffmpeg:rtsp://rtsp:12345678@192.168.1.123/av_stream/ch0#video=copy#audio=copy ``` All trascoding formats has built-in templates. But you can override them via YAML config. You can also add your own formats to config and use them with source params. diff --git a/cmd/ffmpeg/ffmpeg.go b/cmd/ffmpeg/ffmpeg.go index 62b87e6e..8ff29378 100644 --- a/cmd/ffmpeg/ffmpeg.go +++ b/cmd/ffmpeg/ffmpeg.go @@ -54,7 +54,7 @@ func Init() { var query url.Values if i := strings.IndexByte(s, '#'); i > 0 { - query, _ = url.ParseQuery(s[i+1:]) + query = parseQuery(s[i+1:]) s = s[:i] } @@ -110,3 +110,16 @@ func Init() { return exec.Handle(s) }) } + +func parseQuery(s string) map[string][]string { + query := map[string][]string{} + for _, key := range strings.Split(s, "#") { + var value string + i := strings.IndexByte(key, '=') + if i > 0 { + key, value = key[:i], key[i+1:] + } + query[key] = append(query[key], value) + } + return query +}