From eb747decf2ddb1f8045a95c31146e1e3fae2640f Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 25 五月 2021 15:14:36 +0800
Subject: [PATCH] Merge branch 'master' of ssh://192.168.5.5:29418/valib/capture into master
---
capture.go | 35 +++++++++++++++++++----------------
1 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/capture.go b/capture.go
index a0bcf09..556c7a4 100644
--- a/capture.go
+++ b/capture.go
@@ -5,8 +5,9 @@
"fmt"
"time"
- "basic.com/valib/godraw.git"
"basic.com/valib/goffmpeg.git"
+
+ "basic.com/valib/godraw.git"
"github.com/disintegration/imaging"
)
@@ -38,8 +39,8 @@
InvalidFileExt PicExt = PicExt("")
)
-// Capture pic
-func CaptureGB28181(soFile string, url string, maxTry int) ([]byte, error) {
+// capture pic
+func captureGB28181(soFile string, url string, maxTry int) ([]byte, error) {
var ret []byte
var err error
@@ -49,14 +50,14 @@
return nil, err
}
- reterr := errors.New(fmt.Sprintf("try %d times to capture image, is url correct?", maxTry))
- for i := 0; i < maxTry; i++ {
- ret = goffmpeg.GetGBJpg(url)
- if len(ret) > 0 {
- reterr = nil
- break
- }
+ reterr := errors.New(fmt.Sprintf("gb28181 try %d times to capture image, is url correct?", maxTry))
+ // for i := 0; i < maxTry; i++ {
+ ret = goffmpeg.GetGBJpg(url, maxTry)
+ if len(ret) > 0 {
+ reterr = nil
+ // break
}
+ // }
goffmpeg.FreeFFmpeg()
@@ -67,6 +68,10 @@
func Capture(soFile string, m StreamMode, url string, ext PicExt, w, h, maxTry int) ([]byte, error) {
if m != GB28181 && m != Rtsp {
return nil, errors.New("there is no this mode, try capture.Rtsp/capture.GB28181")
+ }
+
+ if m == GB28181 {
+ return captureGB28181(soFile, url, maxTry)
}
if ext == InvalidFileExt {
@@ -101,11 +106,9 @@
gf.BuildDecoder()
tryTime := 0
+ interval := 40 // ms
// 淇濊瘉鏈変竴涓叧閿抚
- maxTry += 50
- if maxTry > 60 {
- maxTry = 60
- }
+ maxTry *= 1000
var bgrData, jpgData []byte
var err error
@@ -127,11 +130,11 @@
}
break
} else {
- tryTime++
+ tryTime += interval
if tryTime > maxTry {
break
}
- time.Sleep(800 * time.Millisecond)
+ time.Sleep(time.Duration(interval) * time.Millisecond)
}
}
--
Gitblit v1.8.0