first commit

This commit is contained in:
gqc
2025-12-10 14:34:57 +08:00
parent 9b02bd9779
commit c554fd3d3d
13 changed files with 182 additions and 277 deletions
+5 -8
View File
@@ -212,14 +212,13 @@ func alignTo10Seconds(timestamp int64) int64 {
return alignedTime.Unix()
}
// parseSimpleTimestamp 解析简单的时间戳文件名 (如: 20251029181740.mp4)
// parseSimpleTimestamp 解析简单的时间戳文件名
func parseSimpleTimestamp(filename string) (int64, error) {
// 移除文件扩展名
nameWithoutExt := strings.TrimSuffix(filename, filepath.Ext(filename))
// 文件名应该就是14位时间戳
if len(nameWithoutExt) != 14 {
//return 0, fmt.Errorf("无效的时间戳格式: %s (期望14位数字)", nameWithoutExt)
}
// 解析时间戳
@@ -297,7 +296,7 @@ func CleanupOldVideos(deviceUUID string) {
func CleanupOldRawVideos(deviceUUID string) {
rawDir := filepath.Join("/usr/data/camera", deviceUUID)
if _, err := os.Stat(rawDir); os.IsNotExist(err) {
return // 目录不存在,直接返回
return
}
files, err := os.ReadDir(rawDir)
@@ -308,7 +307,7 @@ func CleanupOldRawVideos(deviceUUID string) {
var videoFiles []string
for _, file := range files {
if !file.IsDir() && filepath.Ext(file.Name()) == ".mp4" { // 假设是mp4,也可以加更多判断
if !file.IsDir() && filepath.Ext(file.Name()) == ".mp4" {
videoFiles = append(videoFiles, filepath.Join(rawDir, file.Name()))
}
}
@@ -317,14 +316,12 @@ func CleanupOldRawVideos(deviceUUID string) {
return // 不超过60条,不清理
}
// 按修改时间排序(旧 → 新)
sort.Slice(videoFiles, func(i, j int) bool {
fi, _ := os.Stat(videoFiles[i])
fj, _ := os.Stat(videoFiles[j])
return fi.ModTime().Before(fj.ModTime())
})
// 删除最早的(超过60条的部分)
for i := 0; i < len(videoFiles)-60; i++ {
if err := os.Remove(videoFiles[i]); err != nil {
logger.Logger.Printf("Failed to delete the old original video %s: %v", videoFiles[i], err)