mirror of
https://github.com/u2takey/ffmpeg-go.git
synced 2025-10-06 00:16:55 +08:00
add more example doc
This commit is contained in:
74
README.md
74
README.md
@@ -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()
|
||||
@@ -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 :
|
||||
|
||||

|
||||
|
||||
|
||||
## 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: 
|
||||
|
||||
# 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/)
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
BIN
examples/sample_data/face-detect.jpg
Normal file
BIN
examples/sample_data/face-detect.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
Reference in New Issue
Block a user