Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stop enable_to_record_file()? #9423

Closed
hyebin-rdv opened this issue Jul 16, 2021 · 18 comments
Closed

How to stop enable_to_record_file()? #9423

hyebin-rdv opened this issue Jul 16, 2021 · 18 comments

Comments

@hyebin-rdv
Copy link

hyebin-rdv commented Jul 16, 2021

Required Info
Camera Model L515
Firmware Version 01.05.08.01
Operating System & Version ubuntu 18.04
Kernel Version (Linux Only) 5.4.0-77-generic
Platform PC
SDK Version 2.45.0
Language c++

Issue Description

I'm saving files using the enable_to_record_file function. I want to stop recording when a certain command comes from here.

if ( number_test == 1){
m_cfg.enable_record_to_file("/home/hyebin/bagfiles/hyebin.bag");
fprintf(stderr, "--------%d\n", number_test);
} else if ( number_test == 0) {
m_pipe.stop();
fprintf(stderr, "--------%d\n", number_test);
}

If number_test is 0, I want to stop recording&save and restart new recording when number_test is 1.

@MartyG-RealSense
Copy link
Collaborator

Hi @hyebin-rdv As you have already created code to listen for a key input of '0' or '1', what you are seeking to achieve should be straightforward to implement using the stop and start recording code in the SDK's C++ rs-record-playback example program.

https://github.com/IntelRealSense/librealsense/tree/master/examples/record-playback#record-and-playback

@hyebin-rdv
Copy link
Author

hyebin-rdv commented Jul 16, 2021

I have already seen that document. But it did not help me.

if ( number_test == 1){
m_pipe.stop();
m_cfg.enable_record_to_file("/home/hyebin/bagfiles/" + name + ".bag");
} else if ( number_test == 0) {
m_rs_devices.asrs2::recorder().pause();
m_pipe.stop();
m_cfg.disable_all_streams();
auto m_pipe = std::make_sharedrs2::pipeline();
}

how to stop record..?
The camera should keep the video on, but only the off/on function of the recording is required.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 16, 2021

I believe that the recording stop instruction should look like this in your script:

m_pipe.stop();  // Stop the pipeline that holds the file and the recorder
auto m_pipe = std::make_shared<rs2::pipeline>();  // Initiate the shared pointer with a new pipeline

You should not need to use m_cfg.disable_all_streams(); as stopping the pipeline should stop all active streams anyway.

@hyebin-rdv
Copy link
Author

Then is there a way to keep streaming and create bag recordings only?
Stream keeps coming in, but it starts recording, saves, and restarts.
Because if you I pipe.stop(), the existing stream will be cut off.

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 18, 2021

If you have the option of using ROS to record a bag file then you could use the -split command of the rosbag record tool of ROS. This allows you to define a condition for when the current bag file will stop recording and a new file will automatically be created to continue the recording without stopping. A recording can be set to close and continue the recording in a new file after a certain amount of time has passed or when the bag file recording reaches a certain file size.

http://wiki.ros.org/rosbag/Commandline#rosbag_record

image

@hyebin-rdv
Copy link
Author

hyebin-rdv commented Jul 20, 2021

Then do you know how to record video to use option of using Ros?
Now I have this rostopic list.

/rdvcam0/camera/rgb/image_mask
/rdvcam0/camera/rgb/image_raw
/rdvcam0/rdv_rcnn_topic/pc_all
/rdvcam0/rdv_rcnn_topic/plane_points
/rdvcam0/rdv_rcnn_topic/plane_points_color_mask
/rdvcam0/rdv_rcnn_topic/plane_points_color_mask_filter
/rosout
/rosout_agg

how to add video topic?

@MartyG-RealSense
Copy link
Collaborator

If you needed to convert a bag file created with rosbag record to video then the rosbag2video tool may be helpful, though it is written in Python language rather than C++.

https://github.com/mlaiacker/rosbag2video

If you are currently publishing a ROS topic that uses RGB then the instruction rosbag record --all should capture all currently active topics into a rosbag. Alternatively, you can specify a precise list of topics to record to a bag, as described in the link below.

IntelRealSense/realsense-ros#1947 (comment)

@hyebin-rdv
Copy link
Author

hyebin-rdv commented Jul 20, 2021

I got it. I know how to record it!! Thanks.
But I don't know the code to represent it like this.

/camera/align_to_color/parameter_descriptions
/camera/align_to_color/parameter_updates
/camera/aligned_depth_to_color/camera_info
/camera/aligned_depth_to_color/image_raw
/camera/aligned_depth_to_color/image_raw/compressed
/camera/aligned_depth_to_color/image_raw/compressed/parameter_descriptions
/camera/aligned_depth_to_color/image_raw/compressed/parameter_updates
/camera/aligned_depth_to_color/image_raw/compressedDepth
/camera/aligned_depth_to_color/image_raw/compressedDepth/parameter_descriptions
/camera/aligned_depth_to_color/image_raw/compressedDepth/parameter_updates
/camera/color/camera_info
/camera/color/image_raw
/camera/depth/camera_info
/camera/depth/image_rect_raw
/camera/extrinsics/depth_to_color
/camera/motion_module/parameter_descriptions
/camera/motion_module/parameter_updates
/camera/realsense2_camera_manager/bond
/camera/rgb_camera/auto_exposure_roi/parameter_descriptions
/camera/rgb_camera/auto_exposure_roi/parameter_updates
/camera/rgb_camera/parameter_descriptions
/camera/rgb_camera/parameter_updates
/camera/stereo_module/auto_exposure_roi/parameter_descriptions
/camera/stereo_module/auto_exposure_roi/parameter_updates
/camera/stereo_module/parameter_descriptions
/camera/stereo_module/parameter_updates

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Jul 20, 2021

To create an instruction to record a list of topics with rosbag record, you just put rosbag record at the start and then the list of topics that you want to record after it.

image

So in your case, it might look like this:

rosbag record /rdvcam0/camera/rgb/image_mask /rdvcam0/camera/rgb/image_raw /rdvcam0/rdv_rcnn_topic/pc_all
/rdvcam0/rdv_rcnn_topic/plane_points /rdvcam0/rdv_rcnn_topic/plane_points_color_mask /rdvcam0/rdv_rcnn_topic/plane_points_color_mask_filter /rosout /rosout_agg

@hyebin-rdv
Copy link
Author

hyebin-rdv commented Jul 20, 2021

nono, I know how to record but my rostopic list doesn't show that.
https://github.com/IntelRealSense/realsense-ros

If I use 'roslaunch realsense2_camerars_camera.launch' here, and 'rostopic list', I can get the list I want.

I want the same list to come out of the code I've written now. How can I use that roslaunch code with my code?

@MartyG-RealSense
Copy link
Collaborator

Okay, I think I understand now. You want to record the list of topics below but you do not have those topics available when using the rs_camera.launch roslauch instruction.

/rdvcam0/camera/rgb/image_mask
/rdvcam0/camera/rgb/image_raw
/rdvcam0/rdv_rcnn_topic/pc_all
/rdvcam0/rdv_rcnn_topic/plane_points
/rdvcam0/rdv_rcnn_topic/plane_points_color_mask
/rdvcam0/rdv_rcnn_topic/plane_points_color_mask_filter
/rosout
/rosout_agg

Could you launch rs_camera in one terminal and the perform the launch that produces the above non-RealSense topic list in a separate ROS terminal? And then use rosbag record in a third ROS terminal to record the above list to a bag with:

rosbag record /rdvcam0/camera/rgb/image_mask /rdvcam0/camera/rgb/image_raw /rdvcam0/rdv_rcnn_topic/pc_all
/rdvcam0/rdv_rcnn_topic/plane_points /rdvcam0/rdv_rcnn_topic/plane_points_color_mask /rdvcam0/rdv_rcnn_topic/plane_points_color_mask_filter /rosout /rosout_agg

@hyebin-rdv
Copy link
Author

Thanks. Then can I get a video, not an image, using the 'rosbag record'? The image is obtained by recording like that, but the video is not obtained. Is there a way to add topic as a video?

@hyebin-rdv
Copy link
Author

Or do you know how to do two functions with one camera?
"The device is busy!" So that the message doesn't appear.

@MartyG-RealSense
Copy link
Collaborator

At this point, let's pause and confirm what you are trying to achieve so that there is not confusion.

Are you hoping to publish topics in ROS and then read those topics with a C++ ROS node script? Or are you only using rosbag record now.

@hyebin-rdv
Copy link
Author

Anything.

My ultimate goal is to record videos whenever I want.

My program is already using the realsense camera to capture images. I want to record a video whenever I want regardless of the capture motion. I want to record a video whenever I want regardless of the capture motion.

The enable_record_to_file function requires pipe.stop() to stop and restart recording.
Topic saves images only when the topic is called. The same goes for rosbag.

This is what I want to ultimately get "video" from using topics.

If I want to get a video using topics, do I have to keep calling it into an infinite loop?

@MartyG-RealSense
Copy link
Collaborator

If you are open to using any method, the link below has a Python script for recording depth and color in real-time as .avi format videos.

#2731 (comment)

Further Python options for video recording are discussed in the link below.

#8969

The link below about making video recordings using the ROS image_view tool also looks interesting.

http://wiki.ros.org/image_view#image_view.2Fdiamondback.video_recorder

@hyebin-rdv
Copy link
Author

Ok, Thank you! It is so helpful!

@MartyG-RealSense
Copy link
Collaborator

You are very welcome @hyebin-rdv - thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants