Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
d4952ba1
提交
d4952ba1
authored
8月 08, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
f6a306e0
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
268 行增加
和
213 行删除
+268
-213
c_cpp_properties.json
.vscode/c_cpp_properties.json
+28
-0
settings.json
.vscode/settings.json
+5
-0
tasks.json
.vscode/tasks.json
+20
-0
rtsp-relay.cpp
opencv-motion-detect/rtsp-relay.cpp
+215
-213
没有找到文件。
.vscode/c_cpp_properties.json
0 → 100644
浏览文件 @
d4952ba1
{
"configurations"
:
[
{
"name"
:
"Mac"
,
"includePath"
:
[
"${workspaceFolder}/**"
,
"/usr/local/Cellar/opencv/4.1.0_2/include/opencv4"
,
"/usr/local/Cellar/ffmpeg/4.1.4_1/include"
],
"defines"
:
[],
"macFrameworkPath"
:
[
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"compilerPath"
:
"/usr/bin/clang"
,
"cStandard"
:
"c11"
,
"cppStandard"
:
"c++17"
,
"intelliSenseMode"
:
"clang-x64"
,
"browse"
:
{
"path"
:
[
"/usr/local/Cellar/"
],
"limitSymbolsToIncludedHeaders"
:
true
}
}
],
"version"
:
4
}
\ No newline at end of file
.vscode/settings.json
0 → 100644
浏览文件 @
d4952ba1
{
"C_Cpp.intelliSenseEngineFallback"
:
"Enabled"
,
"python.pythonPath"
:
"/opt/apps/conda/anaconda3/bin/python"
}
\ No newline at end of file
.vscode/tasks.json
0 → 100644
浏览文件 @
d4952ba1
{
"tasks"
:
[
{
"type"
:
"shell"
,
"label"
:
"clang++ build active file"
,
"command"
:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
,
"args"
:
[
"-g"
,
"${file}"
,
"-o"
,
"${fileDirname}/${fileBasenameNoExtension}"
],
"options"
:
{
"cwd"
:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
}
}
],
"version"
:
"2.0.0"
}
\ No newline at end of file
opencv-motion-detect/rtsp-relay.cpp
浏览文件 @
d4952ba1
#pragma GCC diagnostic ignored "-Wunused-private-field"
#pragma GCC diagnostic ignored "-Wunused-variable"
extern
"C"
{
#include <libavformat/avformat.h>
}
#include <libavutil/timestamp.h>
#include <stdlib.h>
#include <string>
#include <thread>
...
...
@@ -17,102 +14,143 @@ extern "C" {
namespace
fs
=
std
::
filesystem
;
#endif
#include "vendor/include/zmq.h"
#include "inc/json.hpp"
#include "inc/blockingconcurrentqueue.hpp"
#include "vendor/include/zmq.h"
#include "inc/tinythread.hpp"
#include "inc/common.hpp"
using
namespace
std
;
using
json
=
nlohmann
::
json
;
using
namespace
moodycamel
;
class
PacketPusher
:
public
TinyThread
{
private
:
void
*
pPubContext
=
NULL
;
// for packets publishing
void
*
pPublisher
=
NULL
;
AVFormatContext
*
pAVFormatInput
=
NULL
,
*
pAVFormatRemux
=
NULL
;
string
urlIn
;
int
*
streamList
=
NULL
,
numStreams
=
0
;
class
Stoppable
{
std
::
promise
<
void
>
exitSignal
;
std
::
future
<
void
>
futureObj
;
int
state
=
0
;
thread
th
;
protected
:
// Task need to provide defination for this function
// It will be called by thread function
virtual
void
run
()
=
0
;
public
:
Stoppable
()
:
futureObj
(
exitSignal
.
get_future
())
{
PacketPusher
(
string
urlIn
)
:
urlIn
(
urlIn
){
setupMq
();
}
Stoppable
(
Stoppable
&&
obj
)
:
exitSignal
(
std
::
move
(
obj
.
exitSignal
)),
futureObj
(
std
::
move
(
obj
.
futureObj
))
{
std
::
cout
<<
"Move Constructor is called"
<<
std
::
endl
;
}
Stoppable
&
operator
=
(
Stoppable
&&
obj
)
{
std
::
cout
<<
"Move Assignment is called"
<<
std
::
endl
;
exitSignal
=
std
::
move
(
obj
.
exitSignal
);
futureObj
=
std
::
move
(
obj
.
futureObj
);
return
*
this
;
~
PacketPusher
(){
}
// Thread function to be executed by thread
private
:
void
_
run
()
protected
:
// Function to be executed by thread function
void
run
()
{
if
(
state
==
0
)
{
th
=
thread
([
&
](){
this
->
run
();
});
state
=
1
;
int
ret
=
0
;
if
((
ret
=
avformat_open_input
(
&
pAVFormatInput
,
urlIn
.
c_str
(),
NULL
,
NULL
))
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Could not open input file '%s'"
,
urlIn
.
c_str
());
}
if
((
ret
=
avformat_find_stream_info
(
pAVFormatInput
,
NULL
))
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed to retrieve input stream information"
);
}
public
:
//Checks if thread is requested to stop
bool
checkStop
()
{
// checks if value in future object is available
if
(
futureObj
.
wait_for
(
std
::
chrono
::
milliseconds
(
0
))
==
std
::
future_status
::
timeout
)
return
false
;
return
true
;
pAVFormatInput
->
flags
=
AVFMT_FLAG_NOBUFFER
|
AVFMT_FLAG_FLUSH_PACKETS
;
numStreams
=
pAVFormatInput
->
nb_streams
;
int
*
streamList
=
(
int
*
)
av_mallocz_array
(
numStreams
,
sizeof
(
*
streamList
));
if
(
!
streamList
)
{
ret
=
AVERROR
(
ENOMEM
)
;
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed create avformatcontext for output: %s"
,
av_err2str
(
AVERROR
(
ENOMEM
)))
;
}
// Request the thread to stop by setting value in promise object
void
stop
()
{
exitSignal
.
set_value
();
// find all video & audio streams for remuxing
int
i
=
0
,
streamIdx
=
0
;
for
(;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
AVStream
*
out_stream
;
AVStream
*
in_stream
=
pAVFormatInput
->
streams
[
i
];
AVCodecParameters
*
in_codecpar
=
in_stream
->
codecpar
;
if
(
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_AUDIO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_VIDEO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_SUBTITLE
)
{
streamList
[
i
]
=
-
1
;
continue
;
}
streamList
[
i
]
=
streamIdx
++
;
out_stream
=
avformat_new_stream
(
pAVFormatRemux
,
NULL
);
if
(
!
out_stream
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed allocating output stream
\n
"
);
ret
=
AVERROR_UNKNOWN
;
void
join
()
{
_run
(
);
if
(
th
.
joinable
())
{
th
.
join
(
);
}
ret
=
avcodec_parameters_copy
(
out_stream
->
codecpar
,
in_codecpar
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed to copy codec parameters
\n
"
);
}
}
void
detach
()
{
_run
();
if
(
th
.
joinable
()){
th
.
detach
();
}
while
(
checkStop
()
==
false
)
{
AVStream
*
in_stream
,
*
out_stream
;
AVPacket
packet
;
ret
=
av_read_frame
(
pAVFormatInput
,
&
packet
);
if
(
ret
<
0
)
break
;
in_stream
=
pAVFormatInput
->
streams
[
packet
.
stream_index
];
if
(
packet
.
stream_index
>=
numStreams
||
streamList
[
packet
.
stream_index
]
<
0
)
{
av_packet_unref
(
&
packet
);
continue
;
}
};
packet
.
stream_index
=
streamList
[
packet
.
stream_index
];
out_stream
=
pAVFormatRemux
->
streams
[
packet
.
stream_index
];
/* copy packet */
packet
.
pts
=
av_rescale_q_rnd
(
packet
.
pts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
AVRounding
(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
dts
=
av_rescale_q_rnd
(
packet
.
dts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
AVRounding
(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
duration
=
av_rescale_q
(
packet
.
duration
,
in_stream
->
time_base
,
out_stream
->
time_base
);
packet
.
pos
=
-
1
;
class
MyTask
:
public
Stoppable
{
protected
:
// Function to be executed by thread function
void
run
()
{
std
::
cout
<<
"Task Start"
<<
std
::
endl
;
ret
=
av_interleaved_write_frame
(
pAVFormatRemux
,
&
packet
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Error muxing packet
\n
"
);
break
;
}
av_packet_unref
(
&
packet
);
}
av_write_trailer
(
pAVFormatRemux
);
std
::
cout
<<
"Pusher Start"
<<
std
::
endl
;
// Check if thread is requested to stop ?
while
(
checkStop
()
==
false
)
{
while
(
checkStop
()
==
false
)
{
std
::
cout
<<
"Doing Some Work"
<<
std
::
endl
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
1000
));
}
std
::
cout
<<
"Task End"
<<
std
::
endl
;
}
int
setupMq
()
{
teardownMq
();
pPubContext
=
zmq_ctx_new
();
pPublisher
=
zmq_socket
(
pPubContext
,
ZMQ_PUB
);
int
rc
=
zmq_bind
(
pPublisher
,
"tcp://*:5556"
);
if
(
rc
!=
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed create pub"
);
}
return
0
;
}
int
teardownMq
()
{
if
(
pPublisher
!=
NULL
)
{
zmq_close
(
pPublisher
);
}
if
(
pPubContext
!=
NULL
)
{
zmq_ctx_destroy
(
pPubContext
);
}
return
0
;
}
};
...
...
@@ -120,7 +158,7 @@ protected:
class
VideoProcessor
{
private
:
#define SECS_SLICE (60*5/2)
AVFormatContext
*
pAVFormatInput
=
NULL
,
*
pAVFormatRemux
=
NULL
,
*
pAVFormatSlice
=
NULL
;
AVFormatContext
*
pAVFormatInput
=
NULL
,
*
pAVFormatRemux
=
NULL
;
AVCodec
*
pCodec
=
NULL
;
AVDictionary
*
pOptsRemux
=
NULL
,
*
pOptsInput
=
NULL
,
*
pOptsOutput
=
NULL
;
int
idxVideo
=
-
1
,
idxAudio
=
-
1
,
numStreams
=
0
,
numSlices
=
6
,
secsSlice
=
SECS_SLICE
;
...
...
@@ -129,21 +167,9 @@ private:
string
urlIn
,
urlOut
,
pathSlice
;
unordered_map
<
string
,
string
>
envParams
=
unordered_map
<
string
,
string
>
();
// mq
void
*
pPubContext
=
NULL
;
// for packets publishing
void
*
pPublisher
=
NULL
;
void
*
pRepContext
=
NULL
;
// for msg from edge gateway
void
*
pReqContext
=
NULL
;
// for msg to edge gateway
private
:
void
logThrow
(
void
*
avcl
,
int
lvl
,
const
char
*
fmt
,
...)
{
(
void
)
avcl
;
(
void
)
lvl
;
va_list
args
;
va_start
(
args
,
fmt
);
av_log
(
NULL
,
AV_LOG_FATAL
,
fmt
,
args
);
va_end
(
args
);
throw
fmt
;
}
void
setupParams
()
{
char
*
tmp
=
getenv
(
"URL_IN"
);
...
...
@@ -162,7 +188,7 @@ private:
pathSlice
=
(
tmp
==
NULL
?
string
(
"slices"
)
:
string
(
tmp
));
// OSX XCode doesn't ship with the filesystem header as of version 10.x
#ifdef __LINUX___
#ifdef __LINUX___
if
(
!
fs
::
exists
(
pathSlice
.
c_str
()))
{
if
(
!
fs
::
create_directory
(
pathSlice
.
c_str
()))
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"can't create directory: %s"
,
pathSlice
.
c_str
());
...
...
@@ -170,7 +196,7 @@ private:
}
fs
::
permissions
(
pathSlice
.
c_str
(),
fs
::
perms
::
all
);
}
#endif
#endif
tmp
=
getenv
(
"PUSH"
);
bPush
=
(
tmp
==
NULL
?
false
:
(
string
(
tmp
)
==
string
(
"false"
)
?
false
:
true
));
...
...
@@ -187,138 +213,114 @@ private:
}
}
int
teardownMq
()
{
if
(
pPublisher
!=
NULL
)
{
zmq_close
(
pPublisher
);
}
if
(
pPubContext
!=
NULL
)
{
zmq_ctx_destroy
(
pPubContext
);
}
return
0
;
}
int
setupMq
(){
teardownMq
();
pPubContext
=
zmq_ctx_new
();
pPublisher
=
zmq_socket
(
pPubContext
,
ZMQ_PUB
);
int
rc
=
zmq_bind
(
pPublisher
,
"tcp://*:5556"
);
if
(
rc
!=
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed create pub"
);
}
MyTask
task
;
task
.
detach
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
3000
));
task
.
stop
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
9993000
));
return
0
;
}
int
setupStreams
()
{
PacketPusher
pusher
(
urlIn
);
pusher
.
detach
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
3000
));
pusher
.
stop
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
9993000
));
int
ret
=
0
,
i
,
streamIdx
=
0
;
if
((
ret
=
avformat_open_input
(
&
pAVFormatInput
,
urlIn
.
c_str
(),
NULL
,
NULL
))
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Could not open input file '%s'"
,
urlIn
.
c_str
());
}
if
((
ret
=
avformat_find_stream_info
(
pAVFormatInput
,
NULL
))
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed to retrieve input stream information"
);
}
pAVFormatInput
->
flags
=
AVFMT_FLAG_NOBUFFER
|
AVFMT_FLAG_FLUSH_PACKETS
;
ret
=
avformat_alloc_output_context2
(
&
pAVFormatRemux
,
NULL
,
"rtsp"
,
urlOut
.
c_str
());
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed create avformatcontext for output: %s"
,
av_err2str
(
ret
));
}
numStreams
=
pAVFormatInput
->
nb_streams
;
streamList
=
(
int
*
)
av_mallocz_array
(
numStreams
,
sizeof
(
*
streamList
));
if
(
!
streamList
)
{
ret
=
AVERROR
(
ENOMEM
);
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed create avformatcontext for output: %s"
,
av_err2str
(
AVERROR
(
ENOMEM
)));
}
// find all video & audio streams for remuxing
for
(
i
=
0
;
i
<
pAVFormatInput
->
nb_streams
;
i
++
)
{
AVStream
*
out_stream
;
AVStream
*
in_stream
=
pAVFormatInput
->
streams
[
i
];
AVCodecParameters
*
in_codecpar
=
in_stream
->
codecpar
;
if
(
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_AUDIO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_VIDEO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_SUBTITLE
)
{
streamList
[
i
]
=
-
1
;
continue
;
}
streamList
[
i
]
=
streamIdx
++
;
out_stream
=
avformat_new_stream
(
pAVFormatRemux
,
NULL
);
if
(
!
out_stream
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed allocating output stream
\n
"
);
ret
=
AVERROR_UNKNOWN
;
}
ret
=
avcodec_parameters_copy
(
out_stream
->
codecpar
,
in_codecpar
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed to copy codec parameters
\n
"
);
}
}
av_dump_format
(
pAVFormatRemux
,
0
,
urlOut
.
c_str
(),
1
);
// find best video stream
idxVideo
=
av_find_best_stream
(
pAVFormatInput
,
AVMEDIA_TYPE_VIDEO
,
-
1
,
-
1
,
&
pCodec
,
0
);
if
(
idxVideo
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed find best video stream"
);
}
if
(
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Failed allocating output stream
\n
"
);
ret
=
avio_open2
(
&
pAVFormatRemux
->
pb
,
urlOut
.
c_str
(),
AVIO_FLAG_WRITE
,
NULL
,
&
pOptsRemux
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Could not open output file '%s'"
,
urlOut
.
c_str
());
}
}
// rtsp tcp
if
(
av_dict_set
(
&
pOptsRemux
,
"rtsp_transport"
,
"tcp"
,
0
)
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"failed set output pOptsRemux"
);
ret
=
AVERROR_UNKNOWN
;
}
ret
=
avformat_write_header
(
pAVFormatRemux
,
&
pOptsRemux
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Error occurred when opening output file
\n
"
);
}
while
(
1
)
{
AVStream
*
in_stream
,
*
out_stream
;
AVPacket
packet
;
ret
=
av_read_frame
(
pAVFormatInput
,
&
packet
);
if
(
ret
<
0
)
break
;
in_stream
=
pAVFormatInput
->
streams
[
packet
.
stream_index
];
if
(
packet
.
stream_index
>=
numStreams
||
streamList
[
packet
.
stream_index
]
<
0
)
{
av_packet_unref
(
&
packet
);
continue
;
}
packet
.
stream_index
=
streamList
[
packet
.
stream_index
];
out_stream
=
pAVFormatRemux
->
streams
[
packet
.
stream_index
];
/* copy packet */
packet
.
pts
=
av_rescale_q_rnd
(
packet
.
pts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
AVRounding
(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
dts
=
av_rescale_q_rnd
(
packet
.
dts
,
in_stream
->
time_base
,
out_stream
->
time_base
,
AVRounding
(
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
));
packet
.
duration
=
av_rescale_q
(
packet
.
duration
,
in_stream
->
time_base
,
out_stream
->
time_base
);
packet
.
pos
=
-
1
;
ret
=
av_interleaved_write_frame
(
pAVFormatRemux
,
&
packet
);
if
(
ret
<
0
)
{
logThrow
(
NULL
,
AV_LOG_FATAL
,
"Error muxing packet
\n
"
);
break
;
}
av_packet_unref
(
&
packet
);
}
av_write_trailer
(
pAVFormatRemux
);
//
if ((ret = avformat_open_input(&pAVFormatInput, urlIn.c_str(), NULL, NULL)) < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Could not open input file '%s'", urlIn.c_str());
//
}
//
if ((ret = avformat_find_stream_info(pAVFormatInput, NULL)) < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Failed to retrieve input stream information");
//
}
//
pAVFormatInput->flags = AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS;
//
ret = avformat_alloc_output_context2(&pAVFormatRemux, NULL, "rtsp", urlOut.c_str());
//
if (ret < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "failed create avformatcontext for output: %s", av_err2str(ret));
//
}
//
numStreams = pAVFormatInput->nb_streams;
//
streamList = (int *)av_mallocz_array(numStreams, sizeof(*streamList));
//
if (!streamList) {
//
ret = AVERROR(ENOMEM);
//
logThrow(NULL, AV_LOG_FATAL, "failed create avformatcontext for output: %s", av_err2str(AVERROR(ENOMEM)));
//
}
//
//
find all video & audio streams for remuxing
//
for (i = 0; i < pAVFormatInput->nb_streams; i++) {
//
AVStream *out_stream;
//
AVStream *in_stream = pAVFormatInput->streams[i];
//
AVCodecParameters *in_codecpar = in_stream->codecpar;
//
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
//
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
//
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
//
streamList[i] = -1;
//
continue;
//
}
//
streamList[i] = streamIdx++;
//
out_stream = avformat_new_stream(pAVFormatRemux, NULL);
//
if (!out_stream) {
//
logThrow(NULL, AV_LOG_FATAL, "Failed allocating output stream\n");
//
ret = AVERROR_UNKNOWN;
//
}
//
ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar);
//
if (ret < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Failed to copy codec parameters\n");
//
}
//
}
//
av_dump_format(pAVFormatRemux, 0, urlOut.c_str(), 1);
//
//
find best video stream
//
idxVideo = av_find_best_stream(pAVFormatInput, AVMEDIA_TYPE_VIDEO, -1, -1, &pCodec, 0);
//
if(idxVideo < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "failed find best video stream");
//
}
//
if (!(pAVFormatRemux->oformat->flags & AVFMT_NOFILE)) {
//
logThrow(NULL, AV_LOG_FATAL, "Failed allocating output stream\n");
//
ret = avio_open2(&pAVFormatRemux->pb, urlOut.c_str(), AVIO_FLAG_WRITE, NULL, &pOptsRemux);
//
if (ret < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Could not open output file '%s'", urlOut.c_str());
//
}
//
}
//
//
rtsp tcp
//
if(av_dict_set(&pOptsRemux, "rtsp_transport", "tcp", 0) < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "failed set output pOptsRemux");
//
ret = AVERROR_UNKNOWN;
//
}
//
ret = avformat_write_header(pAVFormatRemux, &pOptsRemux);
//
if (ret < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Error occurred when opening output file\n");
//
}
//
while (1) {
//
AVStream *in_stream, *out_stream;
//
AVPacket packet;
//
ret = av_read_frame(pAVFormatInput, &packet);
//
if (ret < 0)
//
break;
//
in_stream = pAVFormatInput->streams[packet.stream_index];
//
if (packet.stream_index >= numStreams || streamList[packet.stream_index] < 0) {
//
av_packet_unref(&packet);
//
continue;
//
}
//
packet.stream_index = streamList[packet.stream_index];
//
out_stream = pAVFormatRemux->streams[packet.stream_index];
//
/* copy packet */
//
packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base, out_stream->time_base, AVRounding(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
//
packet.dts = av_rescale_q_rnd(packet.dts, in_stream->time_base, out_stream->time_base, AVRounding(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
//
packet.duration = av_rescale_q(packet.duration, in_stream->time_base, out_stream->time_base);
//
packet.pos = -1;
//
ret = av_interleaved_write_frame(pAVFormatRemux, &packet);
//
if (ret < 0) {
//
logThrow(NULL, AV_LOG_FATAL, "Error muxing packet\n");
//
break;
//
}
//
av_packet_unref(&packet);
//
}
//
av_write_trailer(pAVFormatRemux);
return
ret
;
}
...
...
@@ -327,11 +329,11 @@ public:
VideoProcessor
()
{
setupParams
();
setupMq
();
setupStreams
();
}
// dtor
~
VideoProcessor
()
{
~
VideoProcessor
()
{
avformat_close_input
(
&
pAVFormatInput
);
/* close output */
if
(
pAVFormatRemux
&&
!
(
pAVFormatRemux
->
oformat
->
flags
&
AVFMT_NOFILE
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论