mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
精确mp4录制时长:#1795
This commit is contained in:
parent
bbdcc44eb0
commit
80eef693c6
@ -61,6 +61,16 @@ bool MP4MuxerInterface::haveVideo() const {
|
||||
return _have_video;
|
||||
}
|
||||
|
||||
uint64_t MP4MuxerInterface::getDuration() const {
|
||||
uint64_t ret = 0;
|
||||
for (auto &pr : _codec_to_trackid) {
|
||||
if (pr.second.stamp.getRelativeStamp() > ret) {
|
||||
ret = pr.second.stamp.getRelativeStamp();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MP4MuxerInterface::resetTracks() {
|
||||
_started = false;
|
||||
_have_video = false;
|
||||
|
@ -58,6 +58,11 @@ public:
|
||||
*/
|
||||
void initSegment();
|
||||
|
||||
/**
|
||||
* 获取mp4时长,单位毫秒
|
||||
*/
|
||||
uint64_t getDuration() const;
|
||||
|
||||
protected:
|
||||
virtual MP4FileIO::Writer createWriter() = 0;
|
||||
|
||||
|
@ -70,11 +70,9 @@ void MP4Recorder::asyncClose() {
|
||||
auto full_path = _full_path;
|
||||
auto info = _info;
|
||||
WorkThreadPool::Instance().getExecutor()->async([muxer, full_path_tmp, full_path, info]() mutable {
|
||||
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
|
||||
info.time_len = (float) (::time(NULL) - info.start_time);
|
||||
//关闭mp4非常耗时,所以要放在后台线程执行
|
||||
info.time_len = muxer->getDuration() / 1000.0f;
|
||||
// 关闭mp4可能非常耗时,所以要放在后台线程执行
|
||||
muxer->closeMP4();
|
||||
|
||||
if (!full_path_tmp.empty()) {
|
||||
// 获取文件大小
|
||||
info.file_size = File::fileSize(full_path_tmp.data());
|
||||
@ -86,8 +84,7 @@ void MP4Recorder::asyncClose() {
|
||||
// 临时文件名改成正式文件名,防止mp4未完成时被访问
|
||||
rename(full_path_tmp.data(), full_path.data());
|
||||
}
|
||||
|
||||
/////record 业务逻辑//////
|
||||
//触发mp4录制切片生成事件
|
||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4, info);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user