From 6eea6cec1f833b0ce0b7562ea7ecb57674d7fa9b Mon Sep 17 00:00:00 2001 From: Sergey Petrov Date: Tue, 18 Mar 2025 10:10:10 +0500 Subject: [PATCH] Added functions for creating directories. --- .../{config/config.go => storage/editor.go} | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) rename writer/internal/{config/config.go => storage/editor.go} (56%) diff --git a/writer/internal/config/config.go b/writer/internal/storage/editor.go similarity index 56% rename from writer/internal/config/config.go rename to writer/internal/storage/editor.go index 845fef2..b076304 100644 --- a/writer/internal/config/config.go +++ b/writer/internal/storage/editor.go @@ -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" +}