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
120879df
Commit
120879df
authored
Dec 16, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HTTP-FMP4: 修复http-fmp4直播秒开问题
parent
4291c314
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
32 行增加
和
31 行删除
+32
-31
src/FMP4/FMP4MediaSource.h
+1
-3
src/FMP4/FMP4MediaSourceMuxer.h
+1
-1
src/Record/MP4Muxer.cpp
+29
-26
src/Record/MP4Muxer.h
+1
-1
没有找到文件。
src/FMP4/FMP4MediaSource.h
查看文件 @
120879df
...
...
@@ -64,9 +64,7 @@ public:
*/
void
setInitSegment
(
string
str
)
{
_init_segment
=
std
::
move
(
str
);
if
(
_ring
)
{
regist
();
}
createRing
();
}
/**
...
...
src/FMP4/FMP4MediaSourceMuxer.h
查看文件 @
120879df
...
...
@@ -72,7 +72,7 @@ public:
}
protected
:
void
onSegmentData
(
const
string
&
string
,
uint32_t
stamp
,
bool
key_frame
)
override
{
void
onSegmentData
(
string
string
,
uint32_t
stamp
,
bool
key_frame
)
override
{
if
(
string
.
empty
())
{
return
;
}
...
...
src/Record/MP4Muxer.cpp
查看文件 @
120879df
...
...
@@ -9,10 +9,12 @@
*/
#ifdef ENABLE_MP4
#include "MP4Muxer.h"
#include "Util/File.h"
#include "Extension/H264.h"
namespace
mediakit
{
namespace
mediakit
{
MP4Muxer
::
MP4Muxer
()
{}
...
...
@@ -20,19 +22,19 @@ MP4Muxer::~MP4Muxer() {
closeMP4
();
}
void
MP4Muxer
::
openMP4
(
const
string
&
file
){
void
MP4Muxer
::
openMP4
(
const
string
&
file
)
{
closeMP4
();
_file_name
=
file
;
_mp4_file
=
std
::
make_shared
<
MP4FileDisk
>
();
_mp4_file
->
openFile
(
_file_name
.
data
(),
"wb+"
);
}
MP4FileIO
::
Writer
MP4Muxer
::
createWriter
(){
MP4FileIO
::
Writer
MP4Muxer
::
createWriter
()
{
GET_CONFIG
(
bool
,
mp4FastStart
,
Record
::
kFastStart
);
return
_mp4_file
->
createWriter
(
mp4FastStart
?
MOV_FLAG_FASTSTART
:
0
,
false
);
}
void
MP4Muxer
::
closeMP4
(){
void
MP4Muxer
::
closeMP4
()
{
MP4MuxerInterface
::
resetTracks
();
_mp4_file
=
nullptr
;
}
...
...
@@ -44,15 +46,15 @@ void MP4Muxer::resetTracks() {
/////////////////////////////////////////// MP4MuxerInterface /////////////////////////////////////////////
void
MP4MuxerInterface
::
saveSegment
(){
void
MP4MuxerInterface
::
saveSegment
()
{
mp4_writer_save_segment
(
_mov_writter
.
get
());
}
void
MP4MuxerInterface
::
initSegment
(){
void
MP4MuxerInterface
::
initSegment
()
{
mp4_writer_init_segment
(
_mov_writter
.
get
());
}
bool
MP4MuxerInterface
::
haveVideo
()
const
{
bool
MP4MuxerInterface
::
haveVideo
()
const
{
return
_have_video
;
}
...
...
@@ -66,7 +68,7 @@ void MP4MuxerInterface::resetTracks() {
bool
MP4MuxerInterface
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
auto
it
=
_codec_to_trackid
.
find
(
frame
->
getCodecId
());
if
(
it
==
_codec_to_trackid
.
end
())
{
if
(
it
==
_codec_to_trackid
.
end
())
{
//该Track不存在或初始化失败
return
false
;
}
...
...
@@ -84,7 +86,6 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) {
//mp4文件时间戳需要从0开始
auto
&
track_info
=
it
->
second
;
int64_t
dts_out
,
pts_out
;
switch
(
frame
->
getCodecId
())
{
case
CodecH264
:
case
CodecH265
:
{
...
...
@@ -117,7 +118,7 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) {
return
true
;
}
static
uint8_t
getObject
(
CodecId
codecId
){
static
uint8_t
getObject
(
CodecId
codecId
)
{
switch
(
codecId
){
case
CodecG711A
:
return
MOV_OBJECT_G711a
;
case
CodecG711U
:
return
MOV_OBJECT_G711u
;
...
...
@@ -129,8 +130,8 @@ static uint8_t getObject(CodecId codecId){
}
}
void
MP4MuxerInterface
::
stampSync
(){
if
(
_codec_to_trackid
.
size
()
<
2
)
{
void
MP4MuxerInterface
::
stampSync
()
{
if
(
_codec_to_trackid
.
size
()
<
2
)
{
return
;
}
...
...
@@ -143,7 +144,7 @@ void MP4MuxerInterface::stampSync(){
}
}
if
(
audio
&&
video
)
{
if
(
audio
&&
video
)
{
//音频时间戳同步于视频,因为音频时间戳被修改后不影响播放
audio
->
syncTo
(
*
video
);
}
...
...
@@ -202,7 +203,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
audio_track
->
getAudioSampleRate
(),
audio_track
->
getAacCfg
().
data
(),
audio_track
->
getAacCfg
().
size
());
if
(
track_id
<
0
)
{
if
(
track_id
<
0
)
{
WarnL
<<
"添加AAC Track失败:"
<<
track_id
;
return
false
;
}
...
...
@@ -220,7 +221,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
struct
mpeg4_avc_t
avc
=
{
0
};
string
sps_pps
=
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h264_track
->
getSps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h264_track
->
getPps
();
h264_annexbtomp4
(
&
avc
,
sps_pps
.
data
(),
(
int
)
sps_pps
.
size
(),
NULL
,
0
,
NULL
,
NULL
);
h264_annexbtomp4
(
&
avc
,
sps_pps
.
data
(),
(
int
)
sps_pps
.
size
(),
NULL
,
0
,
NULL
,
NULL
);
uint8_t
extra_data
[
1024
];
int
extra_data_size
=
mpeg4_avc_decoder_configuration_record_save
(
&
avc
,
extra_data
,
sizeof
(
extra_data
));
...
...
@@ -236,7 +237,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
extra_data
,
extra_data_size
);
if
(
track_id
<
0
)
{
if
(
track_id
<
0
)
{
WarnL
<<
"添加H264 Track失败:"
<<
track_id
;
return
false
;
}
...
...
@@ -256,7 +257,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
string
vps_sps_pps
=
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getVps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getSps
()
+
string
(
"
\x00\x00\x00\x01
"
,
4
)
+
h265_track
->
getPps
();
h265_annexbtomp4
(
&
hevc
,
vps_sps_pps
.
data
(),
(
int
)
vps_sps_pps
.
size
(),
NULL
,
0
,
NULL
,
NULL
);
h265_annexbtomp4
(
&
hevc
,
vps_sps_pps
.
data
(),
(
int
)
vps_sps_pps
.
size
(),
NULL
,
0
,
NULL
,
NULL
);
uint8_t
extra_data
[
1024
];
int
extra_data_size
=
mpeg4_hevc_decoder_configuration_record_save
(
&
hevc
,
extra_data
,
sizeof
(
extra_data
));
...
...
@@ -271,7 +272,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
h265_track
->
getVideoHeight
(),
extra_data
,
extra_data_size
);
if
(
track_id
<
0
)
{
if
(
track_id
<
0
)
{
WarnL
<<
"添加H265 Track失败:"
<<
track_id
;
return
false
;
}
...
...
@@ -298,7 +299,7 @@ MP4FileIO::Writer MP4MuxerMemory::createWriter() {
return
_memory_file
->
createWriter
(
MOV_FLAG_SEGMENT
,
true
);
}
const
string
&
MP4MuxerMemory
::
getInitSegment
(){
const
string
&
MP4MuxerMemory
::
getInitSegment
()
{
if
(
_init_segment
.
empty
())
{
initSegment
();
saveSegment
();
...
...
@@ -307,34 +308,36 @@ const string &MP4MuxerMemory::getInitSegment(){
return
_init_segment
;
}
void
MP4MuxerMemory
::
resetTracks
(){
void
MP4MuxerMemory
::
resetTracks
()
{
MP4MuxerInterface
::
resetTracks
();
_memory_file
=
std
::
make_shared
<
MP4FileMemory
>
();
_init_segment
.
clear
();
}
bool
MP4MuxerMemory
::
inputFrame
(
const
Frame
::
Ptr
&
frame
){
bool
MP4MuxerMemory
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
if
(
_init_segment
.
empty
())
{
//尚未生成init segment
return
false
;
}
auto
key_frame
=
frame
->
keyFrame
();
auto
data
=
_memory_file
->
getAndClearMemory
();
if
(
!
data
.
empty
())
{
bool
key_frame
=
frame
->
keyFrame
();
//flush切片
saveSegment
();
auto
data
=
_memory_file
->
getAndClearMemory
();
if
(
!
data
.
empty
())
{
//输出切片数据
onSegmentData
(
data
,
frame
->
dts
(),
_key_frame
);
onSegmentData
(
std
::
move
(
data
)
,
frame
->
dts
(),
_key_frame
);
_key_frame
=
false
;
}
if
(
key_frame
)
{
_key_frame
=
true
;
}
return
MP4MuxerInterface
::
inputFrame
(
frame
);
}
}
//namespace mediakit
#endif//#ifdef ENABLE_MP4
src/Record/MP4Muxer.h
查看文件 @
120879df
...
...
@@ -134,7 +134,7 @@ protected:
* @param stamp 切片末尾时间戳
* @param key_frame 是否有关键帧
*/
virtual
void
onSegmentData
(
const
string
&
string
,
uint32_t
stamp
,
bool
key_frame
)
=
0
;
virtual
void
onSegmentData
(
string
string
,
uint32_t
stamp
,
bool
key_frame
)
=
0
;
protected
:
MP4FileIO
::
Writer
createWriter
()
override
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论