sunty
2020-08-20 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package service
 
import (
    "basic.com/dbapi.git"
    "basic.com/fileServer/WeedFSClient.git"
    "basic.com/valib/capture.git"
    "basic.com/valib/logger.git"
    "errors"
    "strconv"
    "webserver/cache"
)
/*以下属于旧版本地摄像机获取截图(国标摄像机底图无法刷新)
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 UpdateSnapshotUrl(cid string) (filename string, err error) {
    var camApi dbapi.CameraApi
 
    flag.Parse()
    piclocal, err := processphoto(cid)
    defer os.Remove(piclocal)
    if err != nil {
        return "", err
    }
    var weedfsUrl = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit"
    resp, err := PostFormBufferData(weedfsUrl, piclocal, piclocal)
    if err != nil {
        fmt.Println(err)
        return "", err
    }
 
    fileurl := resp["fileUrl"].(string)
    filename = filepath.Base(fileurl)
    ok := camApi.UpdateSnapshotUrl(cid, filename)
    if !ok {
        return "", errors.New("update filelocal to camera fail")
    }
    return filename, nil
}*/
 
//调用统一接口,刷新底图(集成国标底图刷新)
func UpdateCapture(cid string) (fileName string,err error){
    var cameraApi dbapi.CameraApi
    camera, err := cameraApi.GetCameraById(cid)
    if err !=nil{
        return "",errors.New("camera not exist")
    }
 
    m := capture.Rtsp
    if camera.Type == 1{//国标摄像机
        m = capture.GB28181
    }
    b,err := capture.Capture("libcffmpeg-capture.so",m,camera.Rtsp,capture.JPEGFileExt,1280,720,10)
    if err == nil{
        localConf, err2 := cache.GetServerInfo()
        if err2 !=nil || localConf.WebPicIp == "" {
            logger.Debug("localConfig is wrong!!!")
            return "",err2
        }
        var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent"
        weedFilePath, err := WeedFSClient.UploadFile(weedfsUri, camera.Name+".jpg", b)
        if err != nil {
            return "",err
        } else {
            ok := cameraApi.UpdateSnapshotUrl(cid, weedFilePath)
            if !ok {
                return "", errors.New("update camera's snapshot fail")
            }
            return weedFilePath, nil
        }
    }else{
        return "",err
    }
}