h264_streamer.cpp
Go to the documentation of this file.
00001 #include "web_video_server/h264_streamer.h"
00002 
00003 namespace web_video_server
00004 {
00005 
00006 H264Streamer::H264Streamer(const async_web_server_cpp::HttpRequest& request,
00007                          async_web_server_cpp::HttpConnectionPtr connection, ros::NodeHandle& nh) :
00008     LibavStreamer(request, connection, nh, "mp4", "libx264", "video/mp4")
00009 {
00010   /* possible quality presets:
00011    * ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
00012    * no latency improvements observed with ultrafast instead of medium
00013    */
00014   preset_ = request.get_query_param_value_or_default("preset", "ultrafast");
00015 }
00016 
00017 H264Streamer::~H264Streamer()
00018 {
00019 }
00020 
00021 void H264Streamer::initializeEncoder()
00022 {
00023   av_opt_set(codec_context_->priv_data, "preset", preset_.c_str(), 0);
00024   av_opt_set(codec_context_->priv_data, "tune", "zerolatency", 0);
00025   av_opt_set_int(codec_context_->priv_data, "crf", 20, 0);
00026   av_opt_set_int(codec_context_->priv_data, "bufsize", 100, 0);
00027   av_opt_set_int(codec_context_->priv_data, "keyint", 30, 0);
00028   av_opt_set_int(codec_context_->priv_data, "g", 1, 0);
00029 
00030   // container format options
00031   if (!strcmp(format_context_->oformat->name, "mp4")) {
00032     // set up mp4 for streaming (instead of seekable file output)
00033     av_dict_set(&opt_, "movflags", "+frag_keyframe+empty_moov+faststart", 0);
00034   }
00035 }
00036 
00037 H264StreamerType::H264StreamerType() :
00038     LibavStreamerType("mp4", "libx264", "video/mp4")
00039 {
00040 }
00041 
00042 boost::shared_ptr<ImageStreamer> H264StreamerType::create_streamer(const async_web_server_cpp::HttpRequest& request,
00043                                                                   async_web_server_cpp::HttpConnectionPtr connection,
00044                                                                   ros::NodeHandle& nh)
00045 {
00046   return boost::shared_ptr<ImageStreamer>(new H264Streamer(request, connection, nh));
00047 }
00048 
00049 }


web_video_server
Author(s): Mitchell Wills
autogenerated on Thu Jun 6 2019 18:02:48