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

Commit 11076d1

Browse files
committed
Add custom usage
1 parent 013b5fc commit 11076d1

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

ffmpeg/ffmpeg.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,62 @@ func New(cfg *Config) transcoder.Transcoder {
3838
return &Transcoder{config: cfg, done: make(chan interface{})}
3939
}
4040

41+
func (t *Transcoder) StartCustom(opts transcoder.Options) (<-chan transcoder.Progress, error) {
42+
var stderrIn io.ReadCloser
43+
44+
out := make(chan transcoder.Progress)
45+
46+
defer t.closePipes()
47+
48+
// Append input file and standard options
49+
args := append([]string{}, opts.GetStrArguments()...)
50+
51+
// Initialize command
52+
// If a context object was supplied to this Transcoder before
53+
// starting, use this context when creating the command to allow
54+
// the command to be killed when the context expires
55+
var cmd *exec.Cmd
56+
if t.commandContext == nil {
57+
cmd = exec.Command(t.config.FfmpegBinPath, args...)
58+
} else {
59+
cmd = exec.CommandContext(*t.commandContext, t.config.FfmpegBinPath, args...)
60+
}
61+
cmd.Dir = t.config.OutputDir
62+
var err error
63+
// If progresss enabled, get stderr pipe and start progress process
64+
if t.config.ProgressEnabled && !t.config.Verbose {
65+
stderrIn, err = cmd.StderrPipe()
66+
if err != nil {
67+
return nil, fmt.Errorf("Failed getting transcoding progress (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
68+
}
69+
}
70+
71+
if t.config.Verbose {
72+
cmd.Stderr = os.Stdout
73+
}
74+
75+
// Start process
76+
err = cmd.Start()
77+
if err != nil {
78+
return nil, fmt.Errorf("Failed starting transcoding (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
79+
}
80+
if t.config.ProgressEnabled && !t.config.Verbose {
81+
go func() {
82+
t.progress(stderrIn, out)
83+
}()
84+
85+
go func() {
86+
err = cmd.Wait()
87+
t.done <- true
88+
close(out)
89+
}()
90+
} else {
91+
err = cmd.Wait()
92+
}
93+
94+
return out, nil
95+
}
96+
4197
// Start ...
4298
func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress, error) {
4399

@@ -55,7 +111,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
55111
// Get file metadata
56112
_, err := t.GetMetadata()
57113
if err != nil {
58-
return nil, err
114+
//return nil, err
59115
}
60116

61117
// Append input file and standard options

transcoder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
// Transcoder ...
99
type Transcoder interface {
1010
Start(opts Options) (<-chan Progress, error)
11+
StartCustom(opts Options) (<-chan Progress, error)
1112
Input(i string) Transcoder
1213
InputPipe(w *io.WriteCloser, r *io.ReadCloser) Transcoder
1314
Output(o string) Transcoder

0 commit comments

Comments
 (0)