Skip to content

Instantly share code, notes, and snippets.

@Frago9876543210
Created November 17, 2017 20:11
Show Gist options
  • Save Frago9876543210/ea7c945b1e07fa3b9d9942ece40ae965 to your computer and use it in GitHub Desktop.
Save Frago9876543210/ea7c945b1e07fa3b9d9942ece40ae965 to your computer and use it in GitHub Desktop.
package main
/*
#include <stdlib.h>
#include "HCNetSDK.h"
*/
import "C"
import(
"os"
"fmt"
"unsafe"
"strconv"
)
func main() {
C.NET_DVR_Init()
defer C.NET_DVR_Cleanup()
var info C.NET_DVR_DEVICEINFO
host := C.CString(os.Args[1])
defer C.free(unsafe.Pointer(host))
login := C.CString(os.Args[3])
defer C.free(unsafe.Pointer(login))
password := C.CString(os.Args[4])
defer C.free(unsafe.Pointer(password))
port, err := strconv.Atoi(os.Args[2])
if err != nil {
return
}
channel, err := strconv.Atoi(os.Args[5])
if err != nil {
return
}
uid := (int64)(C.NET_DVR_Login(host, C.WORD(port), login, password, (*C.NET_DVR_DEVICEINFO)(unsafe.Pointer(&info))))
if uid >= 0 {
fmt.Println("Success login!")
fmt.Println("channels:", info.byChanNum)
var netDvrJpegpara C.NET_DVR_JPEGPARA
netDvrJpegpara.wPicQuality = 2
netDvrJpegpara.wPicSize = 0
filename := "screenshot.jpg"
c_filename := C.CString(filename)
defer C.free(unsafe.Pointer(c_filename))
if C.NET_DVR_CaptureJPEGPicture((C.LONG)(uid), (C.LONG)(channel), (*C.NET_DVR_JPEGPARA)(unsafe.Pointer(&netDvrJpegpara)), c_filename) != 0 {
fmt.Println("Downloaded image from channel", channel)
} else {
fmt.Println("Could not download picture")
}
C.NET_DVR_Logout((C.LONG)(uid))
} else {
fmt.Println("Wrong login or password")
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment