Framerate is a parameter now

This commit is contained in:
dmalad committed 2023-12-04 16:34:55 +01:00
1 parent 083693732c
commit e68cfccc50
5 files changed
+41 -18

No files matched your search

+11 -5
View File
@@ -12,19 +12,25 @@ Image2rtsp::Image2rtsp() : Node("image2rtsp"){
this->declare_parameter("topic");
this->declare_parameter("mountpoint");
this->declare_parameter("bitrate");
this->declare_parameter("caps");
this->declare_parameter("framerate");
this->declare_parameter("caps_1");
this->declare_parameter("caps_2");
this->declare_parameter("port");
this->declare_parameter("local_only");
topic = this->get_parameter("topic").as_string();
mountpoint = this->get_parameter("mountpoint").as_string();
bitrate = this->get_parameter("bitrate").as_string();
caps = this->get_parameter("caps").as_string();
framerate = this->get_parameter("framerate").as_string();
caps_1 = this->get_parameter("caps_1").as_string();
caps_2 = this->get_parameter("caps_2").as_string();
port = this->get_parameter("port").as_string();
local_only = this->get_parameter("local_only").as_bool();
// Check if the parameter is set, since no default value is provided
if (!this->has_parameter("topic") || !this->has_parameter("mountpoint") || !this->has_parameter("bitrate") || !this->has_parameter("caps") || !this->has_parameter("port")){
if (!this->has_parameter("topic") || !this->has_parameter("mountpoint") || !this->has_parameter("bitrate") ||
!this->has_parameter("framerate") || !this->has_parameter("caps_1") || !this->has_parameter("caps_2") ||
!this->has_parameter("port") || !this->has_parameter("local_only")){
rclcpp::shutdown(); // Shutdown the node if there are some issues with launch file
return;
}
@@ -39,7 +45,7 @@ Image2rtsp::Image2rtsp() : Node("image2rtsp"){
// Setup the pipeline
pipeline_head = "( appsrc name=imagesrc do-timestamp=true min-latency=0 max-latency=0 max-bytes=1000 is-live=true ! videoconvert ! videoscale ! ";
pipeline_tail = "key-int-max=30 ! video/x-h264, profile=baseline ! rtph264pay name=pay0 pt=96 )";
pipeline = pipeline_head + caps + " ! x264enc tune=zerolatency bitrate=" + bitrate + pipeline_tail;
pipeline = pipeline_head + caps_1 + framerate + caps_2 + " ! x264enc tune=zerolatency bitrate=" + bitrate + pipeline_tail;
rtsp_server_add_url(mountpoint.c_str(), pipeline.c_str(), (GstElement **)&(appsrc));
RCLCPP_INFO(this->get_logger(), "Stream available at rtsp://%s:%s%s", gst_rtsp_server_get_address(rtsp_server), port.c_str(), mountpoint.c_str());
}
@@ -52,7 +58,7 @@ int main(int argc, char *argv[]){
rclcpp::spin(node);
}
}catch (const std::exception &e){
RCLCPP_INFO(rclcpp::get_logger("image2rtsp"), "One or more required parameters are not set. Shutting down the node.");
RCLCPP_INFO(rclcpp::get_logger("image2rtsp"), "One or more required parameters are not set, or set incorrectly. Shutting down the node.");
RCLCPP_INFO(rclcpp::get_logger("image2rtsp"), "Tip: Start the node only using launch file. Also rebuild after making changes in the YAML file");
RCLCPP_ERROR(rclcpp::get_logger("image2rtsp"), "Parameter is not set: %s", e.what());
}
+1 -1
View File
@@ -131,7 +131,7 @@ GstCaps *Image2rtsp::gst_caps_new_from_image(const sensor_msgs::msg::Image::Shar
"format", G_TYPE_STRING, format->second.c_str(),
"width", G_TYPE_INT, msg->width,
"height", G_TYPE_INT, msg->height,
"framerate", GST_TYPE_FRACTION, 10, 1,
"framerate", GST_TYPE_FRACTION, stoi(framerate), 1,
nullptr);
}