Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 1af837c

Browse files
author
xucai.hong
committed
compose gpu mode and cpu mode together
1 parent 73269cc commit 1af837c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ffmpeg/ffmpeg.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func New(cfg *Config) transcoder.Transcoder {
3838
}
3939

4040
// Start ...
41-
func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, *os.Process, error) {
41+
func (t *Transcoder) Start(opts transcoder.Options, mode string) (<-chan transcoder.Progress, *os.Process, error) {
4242

4343
var stderrIn io.ReadCloser
4444

@@ -58,7 +58,12 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
5858
}
5959

6060
// Append input file and standard options
61-
args := append([]string{"-i", t.input}, opts.GetStrArguments()...)
61+
var args []string
62+
if mode == "gpu" {
63+
args = append([]string{"-vsync", "0", "-hwaccel", "cuvid", "-hwaccel_output_format", "cuda", "-i", t.input}, opts.GetStrArguments()...)
64+
} else {
65+
args = append([]string{"-i", t.input}, opts.GetStrArguments()...)
66+
}
6267
outputLength := len(t.output)
6368
optionsLength := len(t.options)
6469

@@ -94,6 +99,10 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
9499
cmd = exec.CommandContext(*t.commandContext, t.config.FfmpegBinPath, args...)
95100
}
96101

102+
if mode != "" {
103+
fmt.Printf("ffmpeg command (%s) is: %s\n", mode, cmd.String())
104+
}
105+
97106
// If progresss enabled, get stderr pipe and start progress process
98107
if t.config.ProgressEnabled && !t.config.Verbose {
99108
stderrIn, err = cmd.StderrPipe()

transcoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// Transcoder ...
1010
type Transcoder interface {
11-
Start(opts Options) (<-chan Progress, *os.Process, error)
11+
Start(opts Options, mode string) (<-chan Progress, *os.Process, error)
1212
Input(i string) Transcoder
1313
InputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder
1414
Output(o string) Transcoder

0 commit comments

Comments
 (0)