src
h264_streamer.cpp
Go to the documentation of this file.
1
#include "
web_video_server/h264_streamer.h
"
2
3
namespace
web_video_server
4
{
5
6
H264Streamer::H264Streamer
(
const
async_web_server_cpp::HttpRequest
& request,
7
async_web_server_cpp::HttpConnectionPtr
connection,
ros::NodeHandle
& nh) :
8
LibavStreamer
(request, connection, nh,
"mp4"
,
"libx264"
,
"video/mp4"
)
9
{
10
/* possible quality presets:
11
* ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
12
* no latency improvements observed with ultrafast instead of medium
13
*/
14
preset_
= request.
get_query_param_value_or_default
(
"preset"
,
"ultrafast"
);
15
}
16
17
H264Streamer::~H264Streamer
()
18
{
19
}
20
21
void
H264Streamer::initializeEncoder
()
22
{
23
av_opt_set(
codec_context_
->priv_data,
"preset"
,
preset_
.c_str(), 0);
24
av_opt_set(
codec_context_
->priv_data,
"tune"
,
"zerolatency"
, 0);
25
av_opt_set_int(
codec_context_
->priv_data,
"crf"
, 20, 0);
26
av_opt_set_int(
codec_context_
->priv_data,
"bufsize"
, 100, 0);
27
av_opt_set_int(
codec_context_
->priv_data,
"keyint"
, 30, 0);
28
av_opt_set_int(
codec_context_
->priv_data,
"g"
, 1, 0);
29
30
// container format options
31
if
(!strcmp(
format_context_
->oformat->name,
"mp4"
)) {
32
// set up mp4 for streaming (instead of seekable file output)
33
av_dict_set(&
opt_
,
"movflags"
,
"+frag_keyframe+empty_moov+faststart"
, 0);
34
}
35
}
36
37
H264StreamerType::H264StreamerType
() :
38
LibavStreamerType
(
"mp4"
,
"libx264"
,
"video/mp4"
)
39
{
40
}
41
42
boost::shared_ptr<ImageStreamer>
H264StreamerType::create_streamer
(
const
async_web_server_cpp::HttpRequest
& request,
43
async_web_server_cpp::HttpConnectionPtr
connection,
44
ros::NodeHandle
& nh)
45
{
46
return
boost::shared_ptr<ImageStreamer>
(
new
H264Streamer
(request, connection, nh));
47
}
48
49
}
web_video_server::H264Streamer::~H264Streamer
~H264Streamer()
Definition:
h264_streamer.cpp:17
boost::shared_ptr< HttpConnection >
web_video_server::LibavStreamer::codec_context_
AVCodecContext * codec_context_
Definition:
libav_streamer.h:40
web_video_server::LibavStreamerType
Definition:
libav_streamer.h:62
web_video_server::H264Streamer
Definition:
h264_streamer.h:12
web_video_server::LibavStreamer
Definition:
libav_streamer.h:24
web_video_server::H264Streamer::preset_
std::string preset_
Definition:
h264_streamer.h:20
async_web_server_cpp::HttpRequest
async_web_server_cpp::HttpRequest::get_query_param_value_or_default
std::string get_query_param_value_or_default(const std::string &name, const std::string &default_value) const
web_video_server::H264StreamerType::H264StreamerType
H264StreamerType()
Definition:
h264_streamer.cpp:37
web_video_server::H264StreamerType::create_streamer
virtual boost::shared_ptr< ImageStreamer > create_streamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection, ros::NodeHandle &nh)
Definition:
h264_streamer.cpp:42
web_video_server
Definition:
h264_streamer.h:9
web_video_server::H264Streamer::H264Streamer
H264Streamer(const async_web_server_cpp::HttpRequest &request, async_web_server_cpp::HttpConnectionPtr connection, ros::NodeHandle &nh)
Definition:
h264_streamer.cpp:6
web_video_server::LibavStreamer::opt_
AVDictionary * opt_
Definition:
libav_streamer.h:43
web_video_server::H264Streamer::initializeEncoder
virtual void initializeEncoder()
Definition:
h264_streamer.cpp:21
web_video_server::LibavStreamer::format_context_
AVFormatContext * format_context_
Definition:
libav_streamer.h:38
h264_streamer.h
ros::NodeHandle
web_video_server
Author(s): Mitchell Wills
autogenerated on Wed Mar 2 2022 01:13:35