From 9fec449bb6cf70c62d81b27f288975724f61fe09 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 25 五月 2021 15:16:01 +0800
Subject: [PATCH] log
---
capture.go | 44 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/capture.go b/capture.go
index 7d28756..bc5336a 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,10 +39,39 @@
InvalidFileExt PicExt = PicExt("")
)
+// capture pic
+func captureGB28181(soFile string, url string, maxTry int) ([]byte, error) {
+
+ var ret []byte
+ var err error
+
+ err = goffmpeg.InitFFmpeg(soFile)
+ if err != nil {
+ return nil, err
+ }
+
+ 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()
+
+ return ret, reterr
+}
+
// Capture pic
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 {
@@ -76,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
@@ -102,16 +130,16 @@
}
break
} else {
- tryTime++
+ tryTime += interval
if tryTime > maxTry {
break
}
- time.Sleep(800 * time.Millisecond)
+ time.Sleep(time.Duration(interval) * time.Millisecond)
}
}
if tryTime >= maxTry {
- err := fmt.Sprintf("try %d times to capture image, is url correct?\n", tryTime)
+ err := fmt.Sprintf("try %d ms to capture image, is url correct?\n", tryTime)
return nil, errors.New(err)
}
--
Gitblit v1.8.0