Skip to content

Commit 898ebfd

Browse files
authored
Merge pull request #109 from stombeur/master
add example reading frame with ss
2 parents b4f7b21 + 62cabaf commit 898ebfd

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

examples/example_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ func TestExampleReadFrameAsJpeg(t *testing.T) {
3030
}
3131
}
3232

33+
func TestExampleReadTimePositionAsJpeg(t *testing.T) {
34+
reader := ExampleReadTimePositionAsJpeg("./sample_data/in1.mp4", 4)
35+
img, err := imaging.Decode(reader)
36+
if err != nil {
37+
t.Fatal(err)
38+
}
39+
err = imaging.Save(img, "./sample_data/out2.jpeg")
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
}
44+
3345
func TestExampleShowProgress(t *testing.T) {
3446
ExampleShowProgress("./sample_data/in1.mp4", "./sample_data/out2.mp4")
3547
}

examples/readTimePositionAsJpeg.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package examples
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"os"
7+
8+
ffmpeg "github.com/u2takey/ffmpeg-go"
9+
)
10+
11+
func ExampleReadTimePositionAsJpeg(inFileName string, seconds int) io.Reader {
12+
buf := bytes.NewBuffer(nil)
13+
err := ffmpeg.Input(inFileName, ffmpeg.KwArgs{"ss": seconds}).
14+
Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
15+
WithOutput(buf, os.Stdout).
16+
Run()
17+
if err != nil {
18+
panic(err)
19+
}
20+
return buf
21+
}

examples/sample_data/out1.jpeg

-24 Bytes
Loading

examples/sample_data/out2.jpeg

14.3 KB
Loading

0 commit comments

Comments
 (0)