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
|
}
|
}
|