Refactoring.

This commit is contained in:
Сергей Петров 2025-04-03 15:16:47 +05:00
parent 5c401bd781
commit d311776302
6 changed files with 27 additions and 10 deletions

View File

@ -3,8 +3,8 @@ module git.insit.tech/psa/rtsp_reader-writer/writer
go 1.24.1
require (
git.insit.tech/sas/rtsp_proxy v0.0.0-20250328095933-2642c2a10d0c
github.com/Eyevinn/mp4ff v0.47.0
git.insit.tech/sas/rtsp_proxy v0.0.0-20250403064958-d4446b880371
github.com/Eyevinn/mp4ff v0.48.0
github.com/bluenviron/gortsplib/v4 v4.12.3
github.com/bluenviron/mediacommon v1.14.0
github.com/bluenviron/mediacommon/v2 v2.0.0
@ -17,7 +17,7 @@ require (
)
require (
github.com/asticode/go-astikit v0.52.0 // indirect
github.com/asticode/go-astikit v0.54.0 // indirect
github.com/asticode/go-astits v1.13.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect

View File

@ -1,10 +1,16 @@
git.insit.tech/sas/rtsp_proxy v0.0.0-20250328095933-2642c2a10d0c h1:eABK52LAFilOYqVViB7XRA+maacYIGe14NzKdWW+HV0=
git.insit.tech/sas/rtsp_proxy v0.0.0-20250328095933-2642c2a10d0c/go.mod h1:/AHWd1Otr+ikOLWzpXtoozzifEx9ZKou+R6DgwaEzr0=
git.insit.tech/sas/rtsp_proxy v0.0.0-20250403064958-d4446b880371 h1:rfv9H0aF9piFSfdh1ZPPMU+vb2ws/nZyanRJfZmteGI=
git.insit.tech/sas/rtsp_proxy v0.0.0-20250403064958-d4446b880371/go.mod h1:C8AfoW1Go9xoZz2VdGYKjK8h3ormC3zYb40h7OGL+rs=
github.com/Eyevinn/mp4ff v0.47.0 h1:XSSHYt5+I0fyOnHWoNwM72DtivlmHFR0V9azgIi+ZVU=
github.com/Eyevinn/mp4ff v0.47.0/go.mod h1:hJNUUqOBryLAzUW9wpCJyw2HaI+TCd2rUPhafoS5lgg=
github.com/Eyevinn/mp4ff v0.48.0 h1:PwCeFOHGi07LffijQtFmIeIIY7BRURN2c5I2tnQbwds=
github.com/Eyevinn/mp4ff v0.48.0/go.mod h1:hJNUUqOBryLAzUW9wpCJyw2HaI+TCd2rUPhafoS5lgg=
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astikit v0.52.0 h1:kTl2XjgiVQhUl1H7kim7NhmTtCMwVBbPrXKqhQhbk8Y=
github.com/asticode/go-astikit v0.52.0/go.mod h1:fV43j20UZYfXzP9oBn33udkvCvDvCDhzjVqoLFuuYZE=
github.com/asticode/go-astikit v0.54.0 h1:uq9eurgisdkYwJU9vSWIQaPH4MH0cac82sQH00kmSNQ=
github.com/asticode/go-astikit v0.54.0/go.mod h1:fV43j20UZYfXzP9oBn33udkvCvDvCDhzjVqoLFuuYZE=
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=

View File

@ -3,5 +3,5 @@ package config
var (
Local = "storage"
LogsDirectory string
Cameras = "/home/developer/rtsp_reader-writer/writer/internal/config/cameras.yaml"
Cameras = "/home/psa/GoProjects/writer/internal/config/cameras.yaml"
)

View File

@ -58,7 +58,7 @@ func rtsp(dir string, period int, link string, number int) error {
// Create cam logger.
cutURI := LastPartURI(link)
cam := log2.CamLogging(fmt.Sprintf("%s/%s/writer-cam_%s.log", dirData, cutURI, time.Now().Format("15-04-05_02-01-2006")))
cam := log2.CamLogging(fmt.Sprintf("%s/%s/writer-cam_%s.log", dirData, cutURI, strconv.FormatInt(time.Now().Unix(), 10)))
// Connect to the server.
c := gortsplib.Client{
@ -90,6 +90,15 @@ func rtsp(dir string, period int, link string, number int) error {
resolution := findResolution(res.Body)
resolutions := []string{resolution}
for i, itemRes := range resolutions {
switch itemRes {
case "1920-1080":
resolutions[i] = "tracks_v1"
case "1280-720":
resolutions[i] = "tracks_v2"
}
}
fn := storage.CreateFileName(dirData, resolutions, cutURI, period, number)
err = os.MkdirAll(fmt.Sprintf("%s", fn.Path), 0755)
@ -558,7 +567,7 @@ func rtsp(dir string, period int, link string, number int) error {
defer file.Close()
seg := storage.Segment{
Date: time.Now().Format("15-04-05_02-01-2006"),
Date: strconv.FormatInt(time.Now().Unix(), 10),
Duration: strconv.Itoa(period),
Packet: storage.InterleavedPacket{},
}
@ -700,7 +709,7 @@ func rtsp(dir string, period int, link string, number int) error {
}
seg = storage.Segment{
Date: time.Now().Format("15-04-05_02-01-2006"),
Date: strconv.FormatInt(time.Now().Unix(), 10),
Duration: strconv.Itoa(period),
Packet: storage.InterleavedPacket{},
}

View File

@ -2,6 +2,7 @@ package log
import (
"fmt"
"strconv"
"time"
"git.insit.tech/psa/rtsp_reader-writer/writer/internal/config"
@ -20,5 +21,5 @@ func StartMainLogger(local, program string) {
fmt.Sprintf("%s/%s-main_%s.log",
config.LogsDirectory,
program,
time.Now().Format("15-04-05_02-01-2006")))
strconv.FormatInt(time.Now().Unix(), 10)))
}

View File

@ -3,6 +3,7 @@ package storage
import (
"git.insit.tech/sas/rtsp_proxy/proto/common"
"os"
"strconv"
"time"
)
@ -10,8 +11,8 @@ import (
func CreateFileName(dirData string, resolutions []string, cutURI string, period int, number int) *common.FileName {
fn := common.FileName{
Path: dirData + "/" + cutURI + "/" + resolutions[0],
TimeNow: time.Now().Format("15-04-05_02-01-2006"),
Name: "videoFragment",
TimeNow: strconv.FormatInt(time.Now().Unix(), 10),
Name: "seg",
Number: number,
Duration: float64(period),
}