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
7e92a0b7
Commit
7e92a0b7
authored
Jul 30, 2019
by
zqsong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MP4录制添加H265支持
parent
360eba2c
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
72 行增加
和
13 行删除
+72
-13
src/Extension/H265.cpp
+27
-0
src/Extension/H265.h
+37
-0
tests/test_server.cpp
+8
-13
没有找到文件。
src/Extension/H265.cpp
查看文件 @
7e92a0b7
...
...
@@ -25,9 +25,36 @@
*/
#include "H265.h"
#include "SPSParser.h"
#include "Util/logger.h"
namespace
mediakit
{
bool
getAVCH265Info
(
const
string
&
strSps
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
)
{
return
getAVC265Info
(
strSps
.
data
(),
strSps
.
size
(),
iVideoWidth
,
iVideoHeight
,
iVideoFps
);
}
bool
getAVC265Info
(
const
char
*
sps
,
int
sps_len
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
){
T_GetBitContext
tGetBitBuf
;
T_HEVCSPS
tH265SpsInfo
;
memset
(
&
tGetBitBuf
,
0
,
sizeof
(
tGetBitBuf
));
memset
(
&
tH265SpsInfo
,
0
,
sizeof
(
tH265SpsInfo
));
tGetBitBuf
.
pu8Buf
=
(
uint8_t
*
)
sps
;
tGetBitBuf
.
iBufSize
=
sps_len
;
if
(
0
!=
h265DecSeqParameterSet
((
void
*
)
&
tGetBitBuf
,
&
tH265SpsInfo
)){
return
false
;
}
h265GetWidthHeight
(
&
tH265SpsInfo
,
&
iVideoWidth
,
&
iVideoHeight
);
h265GeFramerate
(
&
tH265SpsInfo
,
&
iVideoFps
);
//ErrorL << iVideoWidth << " " << iVideoHeight << " " << iVideoFps;
return
true
;
}
Sdp
::
Ptr
H265Track
::
getSdp
()
{
if
(
!
ready
()){
WarnL
<<
"H265 Track未准备好"
;
...
...
src/Extension/H265.h
查看文件 @
7e92a0b7
...
...
@@ -36,6 +36,9 @@ using namespace toolkit;
namespace
mediakit
{
bool
getAVCH265Info
(
const
string
&
strSps
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
bool
getAVC265Info
(
const
char
*
sps
,
int
sps_len
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
/**
* 265帧类
*/
...
...
@@ -176,6 +179,7 @@ public:
_vps
=
vps
.
substr
(
vps_prefix_len
);
_sps
=
sps
.
substr
(
sps_prefix_len
);
_pps
=
pps
.
substr
(
pps_prefix_len
);
onReady
();
}
/**
...
...
@@ -206,6 +210,30 @@ public:
return
CodecH265
;
}
/**
* 返回视频高度
* @return
*/
int
getVideoHeight
()
const
override
{
return
_height
;
}
/**
* 返回视频宽度
* @return
*/
int
getVideoWidth
()
const
override
{
return
_width
;
}
/**
* 返回视频fps
* @return
*/
float
getVideoFps
()
const
override
{
return
_fps
;
}
bool
ready
()
override
{
return
!
_vps
.
empty
()
&&
!
_sps
.
empty
()
&&
!
_pps
.
empty
();
}
...
...
@@ -280,6 +308,12 @@ private:
}
}
/**
* 解析sps获取宽高fps
*/
void
onReady
(){
getAVCH265Info
(
_sps
,
_width
,
_height
,
_fps
);
}
Track
::
Ptr
clone
()
override
{
return
std
::
make_shared
<
std
::
remove_reference
<
decltype
(
*
this
)
>::
type
>
(
*
this
);
}
...
...
@@ -325,6 +359,9 @@ private:
string
_vps
;
string
_sps
;
string
_pps
;
int
_width
=
0
;
int
_height
=
0
;
float
_fps
=
0
;
bool
_last_frame_is_idr
=
false
;
};
...
...
tests/test_server.cpp
查看文件 @
7e92a0b7
...
...
@@ -180,7 +180,7 @@ void initEventListener() {
NoticeCenter
::
Instance
().
addListener
(
nullptr
,
Broadcast
::
kBroadcastMediaChanged
,
[](
BroadcastMediaChangedArgs
)
{
if
(
schema
==
RTMP_SCHEMA
&&
app
==
"live"
)
{
lock_guard
<
mutex
>
lck
(
s_mtxFlvRecorder
);
if
(
/*bRegist*/
0
)
{
if
(
bRegist
)
{
DebugL
<<
"开始录制RTMP:"
<<
schema
<<
" "
<<
vhost
<<
" "
<<
app
<<
" "
<<
stream
;
GET_CONFIG
(
string
,
http_root
,
Http
::
kRootPath
);
auto
path
=
...
...
@@ -239,9 +239,8 @@ int main(int argc,char *argv[]) {
//这里是拉流地址,支持rtmp/rtsp协议,负载必须是H264+AAC
//如果是其他不识别的音视频将会被忽略(譬如说h264+adpcm转发后会去除音频)
auto
urlList
=
{
// "rtsp://admin:admin123@192.168.5.82/",
"rtsp://192.168.5.24/live/chn0"
,
auto
urlList
=
{
"rtmp://live.hkstv.hk.lxdns.com/live/hks1"
,
"rtmp://live.hkstv.hk.lxdns.com/live/hks2"
//rtsp链接支持输入用户名密码
/*"rtsp://admin:jzan123456@192.168.0.122/"*/
};
map
<
string
,
PlayerProxy
::
Ptr
>
proxyMap
;
...
...
@@ -260,7 +259,7 @@ int main(int argc,char *argv[]) {
//rtsp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4
//rtmp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4
PlayerProxy
::
Ptr
player
(
new
PlayerProxy
(
DEFAULT_VHOST
,
"live"
,
to_string
(
i
).
data
()
,
true
,
true
,
true
,
true
));
PlayerProxy
::
Ptr
player
(
new
PlayerProxy
(
DEFAULT_VHOST
,
"live"
,
to_string
(
i
).
data
()));
//指定RTP over TCP(播放rtsp时有效)
(
*
player
)[
kRtpType
]
=
Rtsp
::
RTP_TCP
;
//开始播放,如果播放失败或者播放中止,将会自动重试若干次,重试次数在配置文件中配置,默认一直重试
...
...
@@ -277,7 +276,7 @@ int main(int argc,char *argv[]) {
" http-flv地址 : http://127.0.0.1/live/0.flv
\n
"
" rtsp地址 : rtsp://127.0.0.1/live/0
\n
"
" rtmp地址 : rtmp://127.0.0.1/live/0"
;
#if 1
//加载证书,证书包含公钥和私钥
SSL_Initor
::
Instance
().
loadCertificate
((
exeDir
()
+
"ssl.p12"
).
data
());
//信任某个自签名证书
...
...
@@ -294,12 +293,12 @@ int main(int argc,char *argv[]) {
//简单的telnet服务器,可用于服务器调试,但是不能使用23端口,否则telnet上了莫名其妙的现象
//测试方法:telnet 127.0.0.1 9000
//
TcpServer::Ptr shellSrv(new TcpServer());
TcpServer
::
Ptr
shellSrv
(
new
TcpServer
());
TcpServer
::
Ptr
rtspSrv
(
new
TcpServer
());
TcpServer
::
Ptr
rtmpSrv
(
new
TcpServer
());
TcpServer
::
Ptr
httpSrv
(
new
TcpServer
());
//
shellSrv->start<ShellSession>(shellPort);
shellSrv
->
start
<
ShellSession
>
(
shellPort
);
rtspSrv
->
start
<
RtspSession
>
(
rtspPort
);
//默认554
rtmpSrv
->
start
<
RtmpSession
>
(
rtmpPort
);
//默认1935
//http服务器,支持websocket
...
...
@@ -317,13 +316,11 @@ int main(int argc,char *argv[]) {
//服务器支持动态切换端口(不影响现有连接)
NoticeCenter
::
Instance
().
addListener
(
ReloadConfigTag
,
Broadcast
::
kBroadcastReloadConfig
,[
&
](
BroadcastReloadConfigArgs
){
//重新创建服务器
#if 0
if
(
shellPort
!=
mINI
::
Instance
()[
Shell
::
kPort
].
as
<
uint16_t
>
()){
shellPort
=
mINI
::
Instance
()[
Shell
::
kPort
];
shellSrv
->
start
<
ShellSession
>
(
shellPort
);
InfoL
<<
"重启shell服务器:"
<<
shellPort
;
}
#endif
if
(
rtspPort
!=
mINI
::
Instance
()[
Rtsp
::
kPort
].
as
<
uint16_t
>
()){
rtspPort
=
mINI
::
Instance
()[
Rtsp
::
kPort
];
rtspSrv
->
start
<
RtspSession
>
(
rtspPort
);
...
...
@@ -334,7 +331,6 @@ int main(int argc,char *argv[]) {
rtmpSrv
->
start
<
RtmpSession
>
(
rtmpPort
);
InfoL
<<
"重启rtmp服务器"
<<
rtmpPort
;
}
#if 1
if
(
httpPort
!=
mINI
::
Instance
()[
Http
::
kPort
].
as
<
uint16_t
>
()){
httpPort
=
mINI
::
Instance
()[
Http
::
kPort
];
httpSrv
->
start
<
EchoWebSocketSession
>
(
httpPort
);
...
...
@@ -345,7 +341,6 @@ int main(int argc,char *argv[]) {
httpsSrv
->
start
<
SSLEchoWebSocketSession
>
(
httpsPort
);
InfoL
<<
"重启https服务器"
<<
httpsPort
;
}
#endif
if
(
rtspsPort
!=
mINI
::
Instance
()[
Rtsp
::
kSSLPort
].
as
<
uint16_t
>
()){
rtspsPort
=
mINI
::
Instance
()[
Rtsp
::
kSSLPort
];
...
...
@@ -353,7 +348,7 @@ int main(int argc,char *argv[]) {
InfoL
<<
"重启rtsps服务器"
<<
rtspsPort
;
}
});
#endif
//设置退出信号处理函数
static
semaphore
sem
;
signal
(
SIGINT
,
[](
int
)
{
sem
.
post
();
});
// 设置退出信号
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论