Skip to content

Commit

Permalink
add more example doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglei.w committed Nov 19, 2020
1 parent 5029339 commit 0782179
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ffmpeg-go is golang port of https://github.com/kkroening/ffmpeg-python
check ffmpeg_test.go for examples.


# example
# Examples

```go
split := Input(TestInputFile1).VFlip().Split()
Expand All @@ -21,7 +21,77 @@ err := Concat([]*Stream{
Run()
```

# view
## Task Frame From Video

```bash
func ExampleReadFrameAsJpeg(inFileName string, frameNum int) io.Reader {
buf := bytes.NewBuffer(nil)
err := ffmpeg.Input(inFileName).
Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
WithOutput(buf, os.Stdout).
Run()
if err != nil {
panic(err)
}
return buf
}

reader := ExampleReadFrameAsJpeg("./sample_data/in1.mp4", 5)
img, err := imaging.Decode(reader)
if err != nil {
t.Fatal(err)
}
err = imaging.Save(img, "./sample_data/out1.jpeg")
if err != nil {
t.Fatal(err)
}
```
result :
![image](./examples/sample_data/out1.jpeg)
## Show Ffmpeg Progress
see complete example at: [showProgress](./examples/showProgress.go)
```bash
func ExampleShowProgress(inFileName, outFileName string) {
a, err := ffmpeg.Probe(inFileName)
if err != nil {
panic(err)
}
totalDuration := gjson.Get(a, "format.duration").Float()

err = ffmpeg.Input(inFileName).
Output(outFileName, ffmpeg.KwArgs{"c:v": "libx264", "preset": "veryslow"}).
GlobalArgs("-progress", "unix://"+TempSock(totalDuration)).
OverWriteOutput().
Run()
if err != nil {
panic(err)
}
}
ExampleShowProgress("./sample_data/in1.mp4", "./sample_data/out2.mp4")
```
result
```bash
progress: .0
progress: 0.72
progress: 1.00
progress: done
```
## Use Ffmpeg-go With Open-cv (gocv) For Face-detect
see complete example at: [opencv](./examples/opencv.go)
result: ![image](./examples/sample_data/face-detect.jpg)
# View Graph
function 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/)
Expand Down
10 changes: 6 additions & 4 deletions examples/opencv.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ func openCvProcess(xmlFile string, reader io.ReadCloser, w, h int) {
if img.Empty() {
continue
}
img2 := gocv.NewMat()
gocv.CvtColor(img, &img2, gocv.ColorBGRToRGB)

// detect faces
rects := classifier.DetectMultiScale(img)
rects := classifier.DetectMultiScale(img2)
fmt.Printf("found %d faces\n", len(rects))

// draw a rectangle around each face on the original image,
// along with text identifing as "Human"
for _, r := range rects {
gocv.Rectangle(&img, r, blue, 3)
gocv.Rectangle(&img2, r, blue, 3)

size := gocv.GetTextSize("Human", gocv.FontHersheyPlain, 1.2, 2)
pt := image.Pt(r.Min.X+(r.Min.X/2)-(size.X/2), r.Min.Y-2)
gocv.PutText(&img, "Human", pt, gocv.FontHersheyPlain, 1.2, blue, 2)
gocv.PutText(&img2, "Human", pt, gocv.FontHersheyPlain, 1.2, blue, 2)
}

// show the image in the window, and wait 1 millisecond
window.IMShow(img)
window.IMShow(img2)
if window.WaitKey(10) >= 0 {
break
}
Expand Down
Binary file added examples/sample_data/face-detect.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0782179

Please sign in to comment.