mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-05 08:16:55 +08:00
Add virtual source to ffmpeg (for testing)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/AlexxIT/go2rtc/internal/app"
|
||||
"github.com/AlexxIT/go2rtc/internal/ffmpeg/device"
|
||||
"github.com/AlexxIT/go2rtc/internal/ffmpeg/hardware"
|
||||
"github.com/AlexxIT/go2rtc/internal/ffmpeg/virtual"
|
||||
"github.com/AlexxIT/go2rtc/internal/rtsp"
|
||||
"github.com/AlexxIT/go2rtc/internal/streams"
|
||||
"github.com/AlexxIT/go2rtc/pkg/ffmpeg"
|
||||
@@ -193,6 +194,11 @@ func parseArgs(s string) *ffmpeg.Args {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
} else if strings.HasPrefix(s, "virtual?") {
|
||||
var err error
|
||||
if args.Input, err = virtual.GetInput(s[8:]); err != nil {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
args.Input = inputTemplate("file", s, query)
|
||||
}
|
||||
|
59
internal/ffmpeg/virtual/virtual.go
Normal file
59
internal/ffmpeg/virtual/virtual.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package virtual
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func GetInput(src string) (string, error) {
|
||||
query, err := url.ParseQuery(src)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// set defaults (using Add instead of Set)
|
||||
query.Add("source", "testsrc")
|
||||
query.Add("size", "1920x1080")
|
||||
query.Add("decimals", "2")
|
||||
|
||||
// https://ffmpeg.org/ffmpeg-filters.html
|
||||
source := query.Get("source")
|
||||
input := "-re -f lavfi -i " + source
|
||||
|
||||
sep := "=" // first separator
|
||||
for key, values := range query {
|
||||
value := values[0]
|
||||
|
||||
// https://ffmpeg.org/ffmpeg-utils.html#video-size-syntax
|
||||
switch key {
|
||||
case "color", "rate", "duration", "sar":
|
||||
case "size":
|
||||
switch value {
|
||||
case "720":
|
||||
value = "1280x720"
|
||||
case "1080":
|
||||
value = "1920x1080"
|
||||
case "2K":
|
||||
value = "2560x1440"
|
||||
case "4K":
|
||||
value = "3840x2160"
|
||||
case "8K":
|
||||
value = "7680x4230" // https://reolink.com/blog/8k-resolution/
|
||||
}
|
||||
case "decimals":
|
||||
if source != "testsrc" {
|
||||
continue
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
input += sep + key + "=" + value
|
||||
sep = ":" // next separator
|
||||
}
|
||||
|
||||
if s := query.Get("format"); s != "" {
|
||||
input += ",format=" + s
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
Reference in New Issue
Block a user