File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ err := fluentffmpeg.NewCommand("").
2828 Run ()
2929```
3030
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+
3143If you want to view the errors/logs returned from FFmpeg, provide an io.Writer to receive the data.
3244``` go
3345buf := &bytes.Buffer {}
@@ -37,7 +49,7 @@ err := fluentffmpeg.NewCommand("").
3749 OutputPath (" ./video.mp4" ).
3850 Overwrite (true ).
3951 OutputLogs (buf). // provide a io.Writer
40- Run ()
52+ Run ()
4153
4254out , _ := ioutil.ReadAll (buf) // read logs
4355fmt.Println (string (out))
@@ -48,11 +60,11 @@ You can also get the command in the form of an [exec.Cmd](https://golang.org/pkg
4860``` go
4961done := make (chan error , 1 )
5062cmd := 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 ()
5668cmd.Start ()
5769
5870go func () {
Original file line number Diff line number Diff line change 11package fluentffmpeg
22
33import (
4+ "context"
45 "io"
56 "os/exec"
67 "reflect"
@@ -35,9 +36,19 @@ func (c *Command) Run() error {
3536 return c .Build ().Run ()
3637}
3738
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+
3844// Build returns an exec.Cmd struct ready to run the FFmpeg command with its arguments
3945func (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 ()... )
4152
4253 if c .input != nil {
4354 cmd .Stdin = c .input
You can’t perform that action at this time.
0 commit comments