qixiaoning
2025-08-21 e38654fe9eff4562da4f18f8f018aed7879d493c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package service
 
import (
    "basic.com/fileServer/WeedFSClient.git"
    "basic.com/valib/logger.git"
    "encoding/base64"
    "strings"
    "time"
)
 
/*以下属于旧版本地摄像机获取截图(国标摄像机底图无法刷新)
func processphoto(cid string) (local string, err error) {
    var camApi dbapi.CameraApi
    caminfo, err := camApi.GetCameraById(cid)
    _ = caminfo
    if err != nil {
        return "", err
    }
 
    _, err = exec.LookPath("ffmpeg")
    if err != nil {
        return "", nil
    }
    //piclocal := fmt.Sprintf("%s%s.jpg", *storelocal, time.Now().String())
    piclocal := fmt.Sprintf("%s.jpg", time.Now().Format("2006-01-02_15_04_05.000000000"))
    cmd := exec.Command("ffmpeg", "-i", caminfo.Rtsp,
        //"-y", "-f", "image2", "-t", "0.001",
        //"-vf", "select='eq(pict_type\\,I)',setpts='N/(25*TB)'",
        "-s", "1920*1080", piclocal)
 
    err = cmd.Run()
    if err != nil {
        //return "", err //ignore error
    }
    return piclocal, nil
}
*/
 
// 调用统一接口,刷新底图(集成国标底图刷新)
func UpdateCapture(camType int, rtsp string, weedfsUri string, camName string) (string, string, error) {
 
    m := Rtsp
    if camType == 1 { //国标摄像机
        m = GB28181
    }
 
    realRtsp := rtsp
 
    // 暂时添加hik平台接口的rtsp转换功能.
    // 汇丰需求, 需要优化为通用功能. 暂时不影响正常rtsp地址
    if !strings.HasPrefix(rtsp, "rtsp://") && !strings.HasPrefix(rtsp, "/dev") {
        realRtsp = rtspTranslation(rtsp)
    }
 
    var imgByte []byte
    var err error
    if strings.Contains(realRtsp, "axis-media") {
        imgByte, err = FFmpegSnapshot(rtsp)
    } else {
        imgByte, err = Capture("libcffmpeg-capture.so", m, realRtsp, JPEGFileExt, 1280, 720, 10)
    }
    if err == nil {
        base64Str := base64.StdEncoding.EncodeToString(imgByte)
        weedFilePath, err := WeedFSClient.UploadFile(weedfsUri, camName+".jpg", imgByte, 5*time.Second)
        if err != nil {
            logger.Debug("UploadFile err:", err)
            return "", base64Str, err
        } else {
            return weedFilePath, base64Str, nil
        }
    } else {
        logger.Warn("capture.", err.Error())
        return "", "", err
    }
}