Added functions for creating directories.
This commit is contained in:
parent
9ff99e2654
commit
6eea6cec1f
@ -1,31 +1,12 @@
|
||||
package config
|
||||
package storage
|
||||
|
||||
import (
|
||||
"git.insit.tech/sas/rtsp_proxy/protos"
|
||||
"gopkg.in/yaml.v3"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ParseCamerasYAML parses camera links from YAML file into struct Cameras.
|
||||
func ParseCamerasYAML(dir string) (map[string]string, error) {
|
||||
var CamerasYAML map[string]string
|
||||
|
||||
data, err := os.ReadFile(dir + "/rtsp_reader-writer/writer/internal/config/source.yaml")
|
||||
if err != nil {
|
||||
return CamerasYAML, err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(data, &CamerasYAML)
|
||||
if err != nil {
|
||||
return CamerasYAML, err
|
||||
}
|
||||
|
||||
return CamerasYAML, nil
|
||||
}
|
||||
|
||||
// CutURI returns the last part of the URI after "/".
|
||||
func CutURI(URI string) (CutterURI string) {
|
||||
splitted := strings.Split(URI, "/")
|
||||
@ -39,15 +20,15 @@ func CreateFileName(dir string, resolutions []string, URI string, period int) *p
|
||||
TimeNow: time.Now().Format("15-04-05_02-01-2006"),
|
||||
Name: "videoFragment",
|
||||
Number: -1,
|
||||
Duration: float64(period * 60),
|
||||
Duration: float64(period),
|
||||
}
|
||||
|
||||
return &fn
|
||||
}
|
||||
|
||||
// Waiter waits for the next period.
|
||||
func Waiter(period int) {
|
||||
periodTD := time.Duration(period) * time.Minute
|
||||
// WaitPeriod waits for the next period.
|
||||
func WaitPeriod(period int) {
|
||||
periodTD := time.Duration(period) * time.Second
|
||||
|
||||
now := time.Now()
|
||||
nextSegment := now.Truncate(periodTD).Add(periodTD)
|
||||
@ -55,3 +36,15 @@ func Waiter(period int) {
|
||||
log.Printf("waiting for start recording: %v\n", waitDuration)
|
||||
time.Sleep(waitDuration)
|
||||
}
|
||||
|
||||
func FindResolution(Body []byte) string {
|
||||
split := strings.Split(string(Body), "\n")
|
||||
for _, line := range split {
|
||||
if strings.Contains(line, "a=x-dimensions:") {
|
||||
s, _ := strings.CutPrefix(line, "a=x-dimensions:")
|
||||
resolution := strings.Join(strings.Split(s, ","), "-")
|
||||
return resolution
|
||||
}
|
||||
}
|
||||
return "resolution"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user