Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
80eef693
Commit
80eef693
authored
Oct 16, 2022
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精确mp4录制时长:#1795
parent
bbdcc44e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
11 行删除
+23
-11
src/Record/MP4Muxer.cpp
+10
-0
src/Record/MP4Muxer.h
+6
-1
src/Record/MP4Recorder.cpp
+7
-10
没有找到文件。
src/Record/MP4Muxer.cpp
查看文件 @
80eef693
...
...
@@ -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
;
...
...
src/Record/MP4Muxer.h
查看文件 @
80eef693
...
...
@@ -58,6 +58,11 @@ public:
*/
void
initSegment
();
/**
* 获取mp4时长,单位毫秒
*/
uint64_t
getDuration
()
const
;
protected
:
virtual
MP4FileIO
::
Writer
createWriter
()
=
0
;
...
...
@@ -73,7 +78,7 @@ private:
Stamp
stamp
;
};
std
::
unordered_map
<
int
,
track_info
>
_codec_to_trackid
;
FrameMerger
_frame_merger
{
FrameMerger
::
mp4_nal_size
};
FrameMerger
_frame_merger
{
FrameMerger
::
mp4_nal_size
};
};
class
MP4Muxer
:
public
MP4MuxerInterface
{
...
...
src/Record/MP4Recorder.cpp
查看文件 @
80eef693
...
...
@@ -70,24 +70,21 @@ 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.0
f
;
// 关闭mp4可能非常耗时,所以要放在后台线程执行
muxer
->
closeMP4
();
if
(
!
full_path_tmp
.
empty
())
{
//获取文件大小
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未完成时被访问
//
临时文件名改成正式文件名,防止mp4未完成时被访问
rename
(
full_path_tmp
.
data
(),
full_path
.
data
());
}
/////record 业务逻辑//////
//触发mp4录制切片生成事件
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastRecordMP4
,
info
);
});
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论