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

Commit 1a993bf

Browse files
committed
add config timeout
1 parent 0fa8397 commit 1a993bf

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

ffmpeg/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package ffmpeg
22

3+
import "time"
4+
35
// Config ...
46
type Config struct {
57
FfmpegBinPath string
68
FfprobeBinPath string
79
ProgressEnabled bool
810
Verbose bool
11+
Timeout time.Duration
912
}

ffmpeg/ffmpeg.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"regexp"
1313
"strconv"
1414
"strings"
15+
"syscall"
16+
"time"
1517

16-
"github.com/floostack/transcoder"
17-
"github.com/floostack/transcoder/utils"
18+
"github.com/C0nstantin/transcoder"
19+
"github.com/C0nstantin/transcoder/utils"
1820
)
1921

2022
// Transcoder ...
@@ -101,16 +103,30 @@ func (t *Transcoder) Start(opts transcoder.Options) (<-chan transcoder.Progress,
101103
if err != nil {
102104
return nil, fmt.Errorf("Failed starting transcoding (%s) with args (%s) with error %s", t.config.FfmpegBinPath, args, err)
103105
}
106+
if int(t.config.Timeout) > 0 {
104107

105-
if t.config.ProgressEnabled && !t.config.Verbose {
106-
go func() {
107-
t.progress(stderrIn, out)
108-
}()
109-
108+
}
109+
if (t.config.ProgressEnabled && !t.config.Verbose) || (int(t.config.Timeout) > 0) {
110+
if t.config.ProgressEnabled {
111+
go func() {
112+
t.progress(stderrIn, out)
113+
}()
114+
}
115+
done := make(chan error, 1)
110116
go func() {
111117
defer close(out)
112-
err = cmd.Wait()
118+
done <- cmd.Wait()
119+
113120
}()
121+
select {
122+
case <-time.After(t.config.Timeout):
123+
cmd.Process.Signal(syscall.SIGTERM)
124+
case <-done:
125+
if err != nil {
126+
return nil, err
127+
}
128+
}
129+
114130
} else {
115131
err = cmd.Wait()
116132
}
@@ -192,7 +208,7 @@ func (t *Transcoder) validate() error {
192208
}
193209

194210
// GetMetadata Returns metadata for the specified input file
195-
func (t *Transcoder) GetMetadata() ( transcoder.Metadata, error) {
211+
func (t *Transcoder) GetMetadata() (transcoder.Metadata, error) {
196212

197213
if t.config.FfprobeBinPath != "" {
198214
var outb, errb bytes.Buffer

ffmpeg/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ffmpeg
22

3-
import "github.com/floostack/transcoder"
3+
import "github.com/C0nstantin/transcoder"
44

55
// Metadata ...
66
type Metadata struct {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/floostack/transcoder
1+
module github.com/C0nstantin/transcoder
22

33
go 1.13

0 commit comments

Comments
 (0)