Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ func (a *Args) HasFilters(filters ...string) bool {
func (a *Args) String() string {
b := bytes.NewBuffer(make([]byte, 0, 512))

b.WriteString(a.Bin)
// quote binary path with spaces (ex. C:\Program Files\ffmpeg.exe),
// so shell.QuoteSplit keeps it as a single argument
if strings.Contains(a.Bin, " ") {
b.WriteByte('"')
b.WriteString(a.Bin)
b.WriteByte('"')
} else {
b.WriteString(a.Bin)
}

if a.Global != "" {
b.WriteByte(' ')
Expand Down
25 changes: 25 additions & 0 deletions pkg/ffmpeg/ffmpeg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ffmpeg

import (
"testing"

"github.com/AlexxIT/go2rtc/pkg/shell"
"github.com/stretchr/testify/require"
)

func TestBinWithSpaces(t *testing.T) {
args := Args{
Bin: `C:\Program Files\Symcon\ffmpeg.exe`,
Global: "-hide_banner",
Input: "-i rtsp://example.com",
Output: "-f mjpeg -",
}

s := args.String()
require.Equal(t, `"C:\Program Files\Symcon\ffmpeg.exe" -hide_banner -i rtsp://example.com -f mjpeg -`, s)

// shell.QuoteSplit is how internal/exec parses this string back
split := shell.QuoteSplit(s)
require.Equal(t, `C:\Program Files\Symcon\ffmpeg.exe`, split[0])
require.Equal(t, "-hide_banner", split[1])
}