Skip to content

Commit

Permalink
dev: update rtsp support
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Aug 10, 2023
1 parent 9e9fb05 commit 2972a67
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions device/generic_camera_stream_windows_amd64.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package device

import (
"image"
"image/jpeg"
"fmt"
"os/exec"
"strings"

"os"
"time"

"context"
"fmt"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -62,21 +61,48 @@ func NewVideoCamera(e typex.RuleX) typex.XDevice {
videoCamera.status = typex.DEV_DOWN
videoCamera.mainConfig = _MainConfig{
MaxThread: 10,
InputMode: "LOCAL",
Device: "video0",
RtspUrl: "rtsp://127.0.0.1",
InputMode: "LOCAL",
OutputMode: "JPEG_STREAM",
OutputAddr: "127.0.0.1:2599",
}
return videoCamera
}

/*
* 教程:
* https://ffmpeg.xianwaizhiyin.net/base-ffmpeg/ffmpeg-install.html
*
*/
func CheckFFMPEG() error {
// Command to check if 'ffmpeg' exists
cmd := exec.Command("ffmpeg", "-version")
output, err := cmd.CombinedOutput()

if err != nil {
return err
}
if len(output) < 100 {
return fmt.Errorf("ffmpeg not exists")
}
return nil
}

// 初始化 通常用来获取设备的配置
func (vc *videoCamera) Init(devId string, configMap map[string]interface{}) error {
vc.PointId = devId
if err := utils.BindSourceConfig(configMap, &vc.mainConfig); err != nil {
return err
}
if err := CheckFFMPEG(); err != nil {
return err
}
/*
*
* 检查一下URL
*
*/
if vc.mainConfig.InputMode == "RTSP" {
rtspClient := gortsplib.Client{}
u, err := url.Parse(vc.mainConfig.RtspUrl)
Expand All @@ -89,7 +115,11 @@ func (vc *videoCamera) Init(devId string, configMap map[string]interface{}) erro
}
defer rtspClient.Close()
}
// 从本地摄像头获取
/*
*
* Local指的是本地的USB摄像头
*
*/
if vc.mainConfig.InputMode == "LOCAL" {
if _, ok := videoDevMap[vc.mainConfig.Device]; !ok {
errMsg := fmt.Errorf("video device: %v not exists", vc.mainConfig.Device)
Expand Down

0 comments on commit 2972a67

Please sign in to comment.