Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to change whitelist protocols #56

Merged
merged 1 commit into from
Jun 24, 2020
Merged
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
14 changes: 14 additions & 0 deletions transcoder/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Transcoder struct {
process *exec.Cmd
mediafile *models.Mediafile
configuration ffmpeg.Configuration
whiteListProtocols []string
}

// SetProcessStderrPipe Set the STDERR pipe
Expand Down Expand Up @@ -51,6 +52,10 @@ func (t *Transcoder) SetConfiguration(v ffmpeg.Configuration) {
t.configuration = v
}

func (t *Transcoder) SetWhiteListProtocols(availableProtocols []string) {
t.whiteListProtocols = availableProtocols
}

// Process Get transcoding process
func (t Transcoder) Process() *exec.Cmd {
return t.process
Expand All @@ -75,6 +80,11 @@ func (t Transcoder) FFprobeExec() string {
func (t Transcoder) GetCommand() []string {
media := t.mediafile
rcommand := append([]string{"-y"}, media.ToStrCommand()...)

if t.whiteListProtocols != nil {
rcommand = append([]string{"-protocol_whitelist", strings.Join(t.whiteListProtocols, ",")}, rcommand...)
}

return rcommand
}

Expand Down Expand Up @@ -166,6 +176,10 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string) error {

command := []string{"-i", inputPath, "-print_format", "json", "-show_format", "-show_streams", "-show_error"}

if t.whiteListProtocols != nil {
command = append([]string{"-protocol_whitelist", strings.Join(t.whiteListProtocols, ",")}, command...)
}

cmd := exec.Command(cfg.FfprobeBin, command...)
cmd.Stdout = &outb
cmd.Stderr = &errb
Expand Down
28 changes: 28 additions & 0 deletions transcoder/transcored_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package transcoder

import (
"github.com/stretchr/testify/require"
"github.com/xfrr/goffmpeg/models"
"testing"
)

func TestTranscoder(t *testing.T) {
t.Run("#SetWhiteListProtocols", func(t *testing.T) {
t.Run("Should not set -protocol_whitelist option if it isn't present", func(t *testing.T) {
ts := Transcoder{}

ts.SetMediaFile(&models.Mediafile{})
require.NotEqual(t, ts.GetCommand()[0:2], []string{"-protocol_whitelist", "file,http,https,tcp,tls"})
require.NotContains(t, ts.GetCommand(), "protocol_whitelist")
})

t.Run("Should set -protocol_whitelist option if it's present", func(t *testing.T) {
ts := Transcoder{}

ts.SetMediaFile(&models.Mediafile{})
ts.SetWhiteListProtocols([]string{"file","http","https","tcp","tls"})

require.Equal(t, ts.GetCommand()[0:2], []string{"-protocol_whitelist", "file,http,https,tcp,tls"})
})
})
}