Added functions for creating directories.
This commit is contained in:
parent
9ff99e2654
commit
6eea6cec1f
@ -1,31 +1,12 @@
|
|||||||
package config
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.insit.tech/sas/rtsp_proxy/protos"
|
"git.insit.tech/sas/rtsp_proxy/protos"
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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 "/".
|
// CutURI returns the last part of the URI after "/".
|
||||||
func CutURI(URI string) (CutterURI string) {
|
func CutURI(URI string) (CutterURI string) {
|
||||||
splitted := strings.Split(URI, "/")
|
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"),
|
TimeNow: time.Now().Format("15-04-05_02-01-2006"),
|
||||||
Name: "videoFragment",
|
Name: "videoFragment",
|
||||||
Number: -1,
|
Number: -1,
|
||||||
Duration: float64(period * 60),
|
Duration: float64(period),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fn
|
return &fn
|
||||||
}
|
}
|
||||||
|
|
||||||
// Waiter waits for the next period.
|
// WaitPeriod waits for the next period.
|
||||||
func Waiter(period int) {
|
func WaitPeriod(period int) {
|
||||||
periodTD := time.Duration(period) * time.Minute
|
periodTD := time.Duration(period) * time.Second
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
nextSegment := now.Truncate(periodTD).Add(periodTD)
|
nextSegment := now.Truncate(periodTD).Add(periodTD)
|
||||||
@ -55,3 +36,15 @@ func Waiter(period int) {
|
|||||||
log.Printf("waiting for start recording: %v\n", waitDuration)
|
log.Printf("waiting for start recording: %v\n", waitDuration)
|
||||||
time.Sleep(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