| | |
| | | package service |
| | | |
| | | import ( |
| | | "flag" |
| | | "fmt" |
| | | "os" |
| | | "os/exec" |
| | | "time" |
| | | |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "gocv.io/x/gocv" |
| | | "io" |
| | | "log" |
| | | "mime/multipart" |
| | | "net/http" |
| | | "path/filepath" |
| | | |
| | | "basic.com/dbapi.git" |
| | | "basic.com/fileServer/WeedFSClient.git" |
| | | "basic.com/valib/capture.git" |
| | | "errors" |
| | | "strconv" |
| | | "webserver/extend/config" |
| | | ) |
| | | |
| | | /*以下属于旧版本地摄像机获取截图(国标摄像机底图无法刷新) |
| | | func PostFormBufferData(uri string, filepath string, fileName string) (maps map[string]interface{}, err0 error) { |
| | | // 要指定转byte的格式 |
| | | picMat := gocv.IMRead(filepath, gocv.IMReadColor) |
| | |
| | | return "", nil |
| | | } |
| | | //piclocal := fmt.Sprintf("%s%s.jpg", *storelocal, time.Now().String()) |
| | | piclocal := fmt.Sprintf("%s%s.jpg", *storelocal, time.Now().Format("2006-01-02_15_04_05.000000000")) |
| | | 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)'", |
| | |
| | | return piclocal, nil |
| | | } |
| | | |
| | | var storelocal = flag.String("storelcoal", "/home/user/workspace/gitblit/", "address of picture produce.") |
| | | var fileurl = flag.String("fileurl", "http://192.168.1.182:6333/submit", "url of file server.") |
| | | |
| | | func UpdateSnapshotUrl(cid string) (filename string, err error) { |
| | | var camApi dbapi.CameraApi |
| | | |
| | |
| | | if err != nil { |
| | | return "", err |
| | | } |
| | | |
| | | resp, err := PostFormBufferData(*fileurl, piclocal, piclocal) |
| | | 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 |
| | |
| | | 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("./runtime/libcffmpeg.so",m,camera.Rtsp,capture.JPEGFileExt,1280,720,10) |
| | | if err == nil{ |
| | | var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit" |
| | | 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 |
| | | } |
| | | } |