@@ -5,7 +5,7 @@ ffmpeg-go is golang port of https://github.com/kkroening/ffmpeg-python
55check ffmpeg_test.go for examples.
66
77
8- # example
8+ # Examples
99
1010``` go
1111split := Input (TestInputFile1).VFlip ().Split ()
@@ -21,7 +21,77 @@ err := Concat([]*Stream{
2121 Run ()
2222```
2323
24- # view
24+ ## Task Frame From Video
25+
26+ ``` bash
27+ func ExampleReadFrameAsJpeg(inFileName string, frameNum int) io.Reader {
28+ buf := bytes.NewBuffer(nil)
29+ err := ffmpeg.Input(inFileName).
30+ Filter(" select" , ffmpeg.Args{fmt.Sprintf(" gte(n,%d)" , frameNum)}).
31+ Output(" pipe:" , ffmpeg.KwArgs{" vframes" : 1, " format" : " image2" , " vcodec" : " mjpeg" }).
32+ WithOutput(buf, os.Stdout).
33+ Run ()
34+ if err ! = nil {
35+ panic(err)
36+ }
37+ return buf
38+ }
39+
40+ reader := ExampleReadFrameAsJpeg(" ./sample_data/in1.mp4" , 5)
41+ img, err := imaging.Decode(reader)
42+ if err ! = nil {
43+ t.Fatal(err)
44+ }
45+ err = imaging.Save(img, " ./sample_data/out1.jpeg" )
46+ if err ! = nil {
47+ t.Fatal(err)
48+ }
49+ ` ` `
50+ result :
51+
52+ ! [image](./examples/sample_data/out1.jpeg)
53+
54+
55+ # # Show Ffmpeg Progress
56+
57+ see complete example at: [showProgress](./examples/showProgress.go)
58+
59+ ` ` ` bash
60+ func ExampleShowProgress(inFileName, outFileName string) {
61+ a, err := ffmpeg.Probe(inFileName)
62+ if err ! = nil {
63+ panic(err)
64+ }
65+ totalDuration := gjson.Get(a, " format.duration" ).Float()
66+
67+ err = ffmpeg.Input(inFileName).
68+ Output(outFileName, ffmpeg.KwArgs{" c:v" : " libx264" , " preset" : " veryslow" }).
69+ GlobalArgs(" -progress" , " unix://" +TempSock(totalDuration)).
70+ OverWriteOutput ().
71+ Run ()
72+ if err ! = nil {
73+ panic(err)
74+ }
75+ }
76+ ExampleShowProgress(" ./sample_data/in1.mp4" , " ./sample_data/out2.mp4" )
77+ ` ` `
78+
79+ result
80+
81+ ` ` ` bash
82+ progress: .0
83+ progress: 0.72
84+ progress: 1.00
85+ progress: done
86+ ` ` `
87+
88+ # # Use Ffmpeg-go With Open-cv (gocv) For Face-detect
89+
90+ see complete example at: [opencv](./examples/opencv.go)
91+
92+ result: ! [image](./examples/sample_data/face-detect.jpg)
93+
94+ # View Graph
2595
2696function view generate [mermaid](https://mermaid-js.github.io/mermaid/# /) chart, which can be use in markdown or view [online](https://mermaid-js.github.io/mermaid-live-editor/)
2797
0 commit comments