@@ -38,6 +38,62 @@ func New(cfg *Config) transcoder.Transcoder {
38
38
return & Transcoder {config : cfg , done : make (chan interface {})}
39
39
}
40
40
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
+
41
97
// Start ...
42
98
func (t * Transcoder ) Start (opts transcoder.Options ) (<- chan transcoder.Progress , error ) {
43
99
@@ -55,7 +111,7 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
55
111
// Get file metadata
56
112
_ , err := t .GetMetadata ()
57
113
if err != nil {
58
- return nil , err
114
+ // return nil, err
59
115
}
60
116
61
117
// Append input file and standard options
0 commit comments