From d3f1c2fab1ba68d8a1a661058f2e8c18d9562e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 10 Jun 2023 14:56:23 +0800 Subject: [PATCH] =?UTF-8?q?mp4=E5=BD=95=E5=88=B6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E6=B7=BB=E5=8A=A0=E7=B4=A2=E5=BC=95=E5=8F=B7=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E4=B8=80=E7=A7=92=E5=86=85=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E5=90=8C=E5=90=8D=E6=96=87=E4=BB=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=A6=86=E7=9B=96=20(#2542)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测发现 如果在点播推流时 如果切片大小设置比较小 一秒钟可能产生多个mp4切片 以前切片名称粒度最小为一秒 所以会存在文件覆盖问题 --- src/Record/MP4Recorder.cpp | 10 +++++----- src/Record/MP4Recorder.h | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index fd7c8955..4784fcda 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -41,16 +41,16 @@ MP4Recorder::~MP4Recorder() { void MP4Recorder::createFile() { closeFile(); auto date = getTimeStr("%Y-%m-%d"); - auto time = getTimeStr("%H-%M-%S"); - auto full_path_tmp = _folder_path + date + "/." + time + ".mp4"; - auto full_path = _folder_path + date + "/" + time + ".mp4"; + auto file_name = getTimeStr("%H-%M-%S") + "-" + std::to_string(_file_index++) + ".mp4"; + auto full_path = _folder_path + date + "/" + file_name; + auto full_path_tmp = _folder_path + date + "/." + file_name; /////record 业务逻辑////// _info.start_time = ::time(NULL); - _info.file_name = time + ".mp4"; + _info.file_name = file_name; _info.file_path = full_path; GET_CONFIG(string, appName, Record::kAppName); - _info.url = appName + "/" + _info.app + "/" + _info.stream + "/" + date + "/" + time + ".mp4"; + _info.url = appName + "/" + _info.app + "/" + _info.stream + "/" + date + "/" + file_name; try { _muxer = std::make_shared(); diff --git a/src/Record/MP4Recorder.h b/src/Record/MP4Recorder.h index 69175238..3e0c8013 100644 --- a/src/Record/MP4Recorder.h +++ b/src/Record/MP4Recorder.h @@ -57,13 +57,14 @@ private: private: bool _have_video = false; size_t _max_second; + uint64_t _last_dts = 0; + uint64_t _file_index = 0; std::string _folder_path; std::string _full_path; std::string _full_path_tmp; RecordInfo _info; MP4Muxer::Ptr _muxer; std::list _tracks; - uint64_t _last_dts = 0; }; #endif ///ENABLE_MP4