From 1c5380eeadb5b835c73e2ddd42b87d51bdc34d6b Mon Sep 17 00:00:00 2001 From: Dw9 Date: Sun, 19 Jun 2022 17:27:03 +0800 Subject: [PATCH] Update MP4Recorder.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #1679 _muxer->openMP4 创建非法的文件夹会失败抛出异常 所以_full_path_tmp等都是空字符串 delete_file的时候 就会从此盘符的""(full_path_tmp)目录挨个删除了。 复现建议新建个盘符... --- src/Record/MP4Recorder.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index ede0d32d..35dbeaa0 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -73,15 +73,18 @@ void MP4Recorder::asyncClose() { info.time_len = (float) (::time(NULL) - info.start_time); //关闭mp4非常耗时,所以要放在后台线程执行 muxer->closeMP4(); - //获取文件大小 - info.file_size = File::fileSize(full_path_tmp.data()); - if (info.file_size < 1024) { - //录像文件太小,删除之 - File::delete_file(full_path_tmp.data()); - return; + + if(!full_path_tmp.empty()) { + //获取文件大小 + info.file_size = File::fileSize(full_path_tmp.data()); + if (info.file_size < 1024) { + //录像文件太小,删除之 + File::delete_file(full_path_tmp.data()); + return; + } + //临时文件名改成正式文件名,防止mp4未完成时被访问 + rename(full_path_tmp.data(), full_path.data()); } - //临时文件名改成正式文件名,防止mp4未完成时被访问 - rename(full_path_tmp.data(), full_path.data()); /////record 业务逻辑////// NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4, info); @@ -138,4 +141,4 @@ void MP4Recorder::resetTracks() { } /* namespace mediakit */ -#endif //ENABLE_MP4 \ No newline at end of file +#endif //ENABLE_MP4