app/src/main/java/com/safeluck/floatwindow/manager/UsbCameraRecordManager.java
@@ -17,6 +17,7 @@
import com.safeluck.floatwindow.MediaArgu;
import com.safeluck.floatwindow.ResponseVO;
import com.safeluck.floatwindow.util.GlobalData;
import com.safeluck.floatwindow.util.FileUtil;
import com.safeluck.floatwindow.util.VideoFileUtils;
import timber.log.Timber;
@@ -572,14 +573,17 @@
                        
                        // 释放当前资源
                        releaseResources();
                        // 重命名刚完成的文件
                        if (completedVideoFile != null) {
                            renameCompletedFile(completedVideoFile);
                            completedVideoFile = null;
                        }
                        // 初始化新的编码器和Muxer
                        // 每次写入新文件前,检查并清理存储空间(AnYun_VIDEO 下的 mp4)
                        ensureStorageSpaceForMp4();
                        // 初始化新的编码器和Muxer(创建下一分钟的新文件)
                        if (!initEncoderAndMuxer()) {
                            Timber.e("Failed to create new video file");
                            break;
@@ -647,13 +651,13 @@
                }
                
                releaseResources();
                // 重命名刚完成的文件(停止录像时)
                if (completedVideoFile != null) {
                    renameCompletedFile(completedVideoFile);
                    completedVideoFile = null;
                }
                Timber.d("RecordThread ended");
            }
        }
@@ -811,6 +815,41 @@
        // 如果获取失败,返回默认值60秒
        return 60;
    }
    /**
     * 确保存储空间足够(针对 AnYun_VIDEO 下的 mp4)
     * TF 卡:使用 FileUtil.cleanupH264Files(内部已改为清理 mp4)按日期目录删除最早的视频
     * 内部 Flash:使用 FileUtil.ensureInternalFlashSpaceForH264(内部已改为清理 mp4)
     */
    private void ensureStorageSpaceForMp4() {
        if (context == null || mediaArgu == null) {
            return;
        }
        try {
            int tfFlag = mediaArgu.getTfCardFlag(); // 0-内部存储,1-TF 卡
            // 先定位当前使用的日期目录,再取其父目录 AnYun_VIDEO 作为根目录
            File dateDir = VideoFileUtils.getVideoDirectory(context, tfFlag);
            if (dateDir == null) {
                return;
            }
            File rootDir = dateDir.getParentFile(); // .../AnYun_VIDEO
            if (rootDir == null) {
                return;
            }
            String rootPath = rootDir.getAbsolutePath();
            if (tfFlag == 1) {
                // TF 卡:限制总大小 + 剩余空间
                FileUtil.cleanupH264Files(context, rootPath);
            } else {
                // 内部 Flash:确保剩余空间 ≥ 800MB
                FileUtil.ensureInternalFlashSpaceForH264(context);
            }
        } catch (Exception e) {
            Timber.e(e, "ensureStorageSpaceForMp4 error");
        }
    }
    
    /**
     * 检查并启动Muxer