File tree 2 files changed +30
-7
lines changed
2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ err := fluentffmpeg.NewCommand("").
28
28
Run ()
29
29
```
30
30
31
+ You could use ` context ` to set the timeout:
32
+
33
+ ``` go
34
+ ctx , cancel := context.WithTimeout (context.Background (), time.Second * 5 )
35
+ defer cancel ()
36
+ err := fluentffmpeg.NewCommand (" " ).
37
+ InputPath (" /path/to/video.avi" ).
38
+ OutputFormat (" mp4" ).
39
+ OutputPath (" /path/to/video.mp4" ).
40
+ RunWithContext (ctx)
41
+ ```
42
+
31
43
If you want to view the errors/logs returned from FFmpeg, provide an io.Writer to receive the data.
32
44
``` go
33
45
buf := &bytes.Buffer {}
@@ -37,7 +49,7 @@ err := fluentffmpeg.NewCommand("").
37
49
OutputPath (" ./video.mp4" ).
38
50
Overwrite (true ).
39
51
OutputLogs (buf). // provide a io.Writer
40
- Run ()
52
+ Run ()
41
53
42
54
out , _ := ioutil.ReadAll (buf) // read logs
43
55
fmt.Println (string (out))
@@ -48,11 +60,11 @@ You can also get the command in the form of an [exec.Cmd](https://golang.org/pkg
48
60
``` go
49
61
done := make (chan error , 1 )
50
62
cmd := fluentffmpeg.NewCommand (" " ).
51
- InputPath (" ./video.avi" ).
52
- OutputFormat (" mp4" ).
53
- OutputPath (" ./video.mp4" ).
54
- Overwrite (true ).
55
- Build ()
63
+ InputPath (" ./video.avi" ).
64
+ OutputFormat (" mp4" ).
65
+ OutputPath (" ./video.mp4" ).
66
+ Overwrite (true ).
67
+ Build ()
56
68
cmd.Start ()
57
69
58
70
go func () {
Original file line number Diff line number Diff line change 1
1
package fluentffmpeg
2
2
3
3
import (
4
+ "context"
4
5
"io"
5
6
"os/exec"
6
7
"reflect"
@@ -35,9 +36,19 @@ func (c *Command) Run() error {
35
36
return c .Build ().Run ()
36
37
}
37
38
39
+ // RunWithContext is like Run but includes a context which is used to kill the process
40
+ func (c * Command ) RunWithContext (ctx context.Context ) error {
41
+ return c .BuildWithContext (ctx ).Run ()
42
+ }
43
+
38
44
// Build returns an exec.Cmd struct ready to run the FFmpeg command with its arguments
39
45
func (c * Command ) Build () * exec.Cmd {
40
- cmd := exec .Command (c .FFmpegPath , c .GetArgs ()... )
46
+ return c .BuildWithContext (context .Background ())
47
+ }
48
+
49
+ // BuildWithContext is like Build but includes a context which is used to kill the process
50
+ func (c * Command ) BuildWithContext (ctx context.Context ) * exec.Cmd {
51
+ cmd := exec .CommandContext (ctx , c .FFmpegPath , c .GetArgs ()... )
41
52
42
53
if c .input != nil {
43
54
cmd .Stdin = c .input
You can’t perform that action at this time.
0 commit comments