ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to get number of frames?

asked 2019-09-10 17:50:31 -0500

Abraham gravatar image

updated 2019-09-11 12:09:26 -0500

I used a Intel® RealSense™ Depth Camera D435 to record several videos. I am very new to ROSBAG.

I am using rs-convert to extract PNG frames from a .bag file. However, I noticed that frames have been dropped, and I am trying to identify whether the frames were dropped during recording or during extraction. To do this, I need to check the number of frames in the original .bag file.

How can I use the rosbag command line tools to find the number of frames in a .bag file?

(I have installed the melodic rosdistro on Ubuntu 18.04.)

EDIT: After using the rs-convert tool to extract PNG files, I was able to get 20879 PNG frames.

Is the "duration" the true length of the video? Since I know the D435 camera records at 30fps, I could do 20879 frames/ 699s = 29.87fps --> close enough to 30fps --> conclusion: no frames were dropped.

Below is the output when I run rosbag info <BAG_FILE>. Any insight on the output of this would be helpful, as I am very new to all this.

path:         <BAG_FILENAME>.bag
version:      2.0
duration:     11:39s (699s)
start:        Dec 31 1969 19:00:00.00 (0.00)
end:          Dec 31 1969 19:11:39.81 (699.81)
size:         35.9 GB
messages:     125361
compression:  lz4 [20883/20883 chunks; 66.67%]
uncompressed: 53.8 GB @ 78.7 MB/s
compressed:   35.9 GB @ 52.5 MB/s (66.67%)
types:        diagnostic_msgs/KeyValue  [cf57fdc6617a881a88c16e768132149c]
              geometry_msgs/Transform   [ac9eff44abf714214112b05d54a3cf9b]
              realsense_msgs/StreamInfo [311d7e24eac31bb87271d041bf70ff7d]
              sensor_msgs/CameraInfo    [c9a58c1b0b154e0e6da7578cb991d214]
              sensor_msgs/Image         [060021388200f6f0f447d0fcd9c64743]
              std_msgs/Float32          [73fcbf46b49191e672908e50842a83d4]
              std_msgs/String           [992ce8a1687cec8c8bd883ec73ca41d1]
              std_msgs/UInt32           [304a39449588c7f8ce2df6e8001c5fce]
topics:       /device_0/info                                                         9 msgs    : diagnostic_msgs/KeyValue 
              /device_0/sensor_0/info                                                1 msg     : diagnostic_msgs/KeyValue 
              /device_0/sensor_0/option/Depth Units/description                      1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Depth Units/value                            1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Emitter Enabled/description                  1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Emitter Enabled/value                        1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Enable Auto Exposure/description             1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Enable Auto Exposure/value                   1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Error Polling Enabled/description            1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Error Polling Enabled/value                  1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Exposure/description                         1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Exposure/value                               1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Frames Queue Size/description                1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Frames Queue Size/value                      1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Gain/description                             1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Gain/value                                   1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Inter Cam Sync Mode/description              1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Inter Cam Sync Mode/value                    1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Laser Power/description                      1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Laser Power/value                            1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Output Trigger Enabled/description           1 msg     : std_msgs/String          
              /device_0/sensor_0/option/Output Trigger Enabled/value                 1 msg     : std_msgs/Float32         
              /device_0/sensor_0/option/Stereo Baseline/description                  1 msg     : std_msgs/String ...
edit retag flag offensive close merge delete



Does rosbag info <YOUR_BAG_FILE> help? You will see the number of messages in each topic. I'm not familiar with rs-convert, but if this is only converting each message of a single topic, this should be sufficient.

mgruhler gravatar image mgruhler  ( 2019-09-11 01:33:37 -0500 )edit

@Abraham, you can use rostopic hz <image_topic> to find the rate at which it is being published. This applies while both recording and playing back a rosback. Usually rate of publishing and rate of recording are same in ROS

BV_Pradeep gravatar image BV_Pradeep  ( 2019-09-11 01:59:27 -0500 )edit

@mgruhler, I have added the output of rosbag info <BAG_FILE> in my question. I am not sure if this helps me.

Abraham gravatar image Abraham  ( 2019-09-11 12:10:25 -0500 )edit

@BV_Pradeep, I still do not completely understand how ROSBAG works, and I am not able to run rostopic hz <image_topic> as I cannot playback the BAG file with rosbag play, I am getting errors about localhost and such.

Abraham gravatar image Abraham  ( 2019-09-11 12:11:53 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-09-11 18:16:03 -0500

updated 2019-09-12 07:14:22 -0500

You can find the answer you're looking for in the output of rosbag info as recommended by @mgruhler :

          /device_0/sensor_1/Color_0/image/data                              20882 msgs    : sensor_msgs/Image

This tells you the bag contains 20882 sensor_msgs/Image messages. So based on your update, you dropped 3 frames.

edit flag offensive delete link more


This worked! Thank you very much!

This is a good solution since I do not have to try to playback the BAG file, and can simply use rosbag info.

Abraham gravatar image Abraham  ( 2019-09-12 10:34:09 -0500 )edit

@PeteBlackerThe3rd I have a follow up question, and I have posted that here:

Abraham gravatar image Abraham  ( 2019-09-12 13:24:48 -0500 )edit

Question Tools

1 follower


Asked: 2019-09-10 17:50:31 -0500

Seen: 1,600 times

Last updated: Sep 12 '19