You recorded a depth and color session to a bag file, and the C++ side of the project now needs the rate those streams really ran at. Python reads the value from the stream info message in one line; C++ makes you open the bag yourself, and the first build usually ends in LNK2019 unresolved-external errors. This guide walks the two readings worth taking — the configured rate in the StreamInfo message and the per-frame ACTUAL_FPS metadata — plus the timestamp formula that works on any bag and the linker setup that gets the bag classes to compile in an x64 Windows project. Counting frames and dividing by the recording time never enters the plan: that average is wrong whenever the recorder starts early or drops a frame.
Why not just divide the frame count by the recording time?
Because the bag starts filling before its first frame and loses frames silently on the way to disk, so a true 30 fps session can average 29.67 fps over 60 s of wall clock.
The bag records the wall-clock window you gave the recorder, not the stream's own window. The first frame lands after the recorder is already writing — 0.70 s later in the worked example below — and every dropped frame subtracts from the count without shortening the window. Both errors push the average down, so the number fails exactly where you need it most: the acceptance check. Per-frame timestamps and metadata separate the two causes; a single average cannot.
Treat count ÷ wall clock as a smoke test only. The number that decides whether a recording ships comes from the bag itself, read one of three ways in the sections below.
How do you read the recorded FPS from the info message in C++?
Open the bag read-only, build a rosbag::View over the stream info topics, instantiate the StreamInfo message on each and read its fps field: the integer the recorder wrote when the stream started, 30 for a stream configured at 30 fps.
You need the bag from your own session, the SDK's bag reader headers and static libraries, and an x64 build of your project. The steps:
- Call
bag.open()withrosbag::bagmode::Readso the file opens read-only. - Push the two info topic strings into a
std::vector<std::string>:/device_0/sensor_0/Depth_0/infoand/device_0/sensor_1/Color_0/infofor a single-device recording. - Build a
rosbag::Viewover arosbag::TopicQueryof that vector. - Loop over the view, call
instantiate<StreamInfo>()on each message and skip the null returns. - Compare
m.getTopic()against the same two strings to assign depth and color, then print.
#include "rosbag/bag.h"
#include "rosbag/view.h"
#include "StreamInfo.h" // the SDK's bag message header, under its third-party rosbag sources
#include <iostream>
#include <string>
#include <vector>
std::string depth_fps = "0"; // configured rate of the depth stream
std::string color_fps = "0"; // configured rate of the color stream
rosbag::Bag bag;
bag.open("session_001.bag", rosbag::bagmode::Read);
std::vector<std::string> topics;
topics.push_back("/device_0/sensor_0/Depth_0/info");
topics.push_back("/device_0/sensor_1/Color_0/info");
rosbag::View view(bag, rosbag::TopicQuery(topics));
for (rosbag::MessageInstance const m : view)
{
auto info = m.instantiate<StreamInfo>(); // your SDK declares StreamInfo in its message namespace
if (info)
{
if (m.getTopic() == "/device_0/sensor_0/Depth_0/info")
depth_fps = info->fps;
else
color_fps = info->fps;
}
}
std::cout << "depth " << depth_fps << " fps, color " << color_fps << " fps" << std::endl;
Each info topic carries its values in the first message, so the loop finishes after two hits instead of touching the frame topics.
How do you fix the LNK2019 unresolved external symbol errors?
LNK2019 means a symbol is referenced but never defined at link time. With these bag classes the culprit is almost always the rosbag storage libraries missing from the linker input — include directories alone never fix it.
The linker's own error documentation states the mechanism plainly: when a symbol is referred to but never defined, the linker reports an unresolved external symbol, and it lists architecture mismatch among the common causes. Three fixes cover this case:
-
Link the libraries, not just the headers. Include directories answer
#include; LNK2019 is answered by the .lib files for the rosbag storage and serialization code, added under the linker's input settings. When the error names your project's .obj file, your code compiled fine and the definitions are the missing side. - Build x64. A Win32 configuration cannot resolve symbols from 64-bit libraries, so switch the configuration and rebuild.
- Import the SDK's property sheets. The SDK ships .props files that set include paths, library paths and linker inputs together. Importing them into a fresh project beats typing paths by hand, and copying the settings from the SDK's own sample project gives the same result.
Once the project links, the view and instantiate calls in the previous section run unchanged.
Does the fps field show the configured rate or the delivered rate?
The fps field in StreamInfo holds the configured rate fixed at stream start. The rate the camera actually delivered per frame lives in the ACTUAL_FPS metadata, and the two differ whenever exposure or drops pull a stream under target.
Read StreamInfo's fps as the contract the recording aimed at. It is written once per stream at start and never changes mid-file, so it cannot tell you whether frames arrived. The topic strings carry the mapping: in the file above, /device_0/sensor_0/Depth_0/info held depth and /device_0/sensor_1/Color_0/info color, but which physical sensor holds index 0 is the recorder's choice — the replay mapping guide shows how to match recorded files back to sensors.
A bag whose info messages both say 30 can still hold a depth stream that delivered 15: long exposure capped it at capture. The delivered rate lives in the frame metadata, taken up next.
How do you read the delivered rate from frame metadata?
If the recording was made with frame metadata enabled, replay the bag, pull a frameset and read RS2_FRAME_METADATA_ACTUAL_FPS off the depth frame: a healthy 30 fps stream prints 30 on every frame and an exposure-capped one prints 15.
Metadata rides into the file with the streams when the session is captured to a bag file rather than an AVI, which is exactly why the bag container earns its space. During playback, read the value off any depth frame:
// frameset is the set of frames you already pull during playback
std::cout << "actual fps = "
<< frameset.get_depth_frame().get_frame_metadata(
rs2_frame_metadata_value::RS2_FRAME_METADATA_ACTUAL_FPS)
<< std::endl;
The call reports the value as unsupported rather than zero when it was never recorded; the per-frame exposure guide shows the reading pattern that works around that.
How do you compute the true average from timestamps?
Every frame message carries a device timestamp, so the honest average is (N − 1) divided by the span from first to last stamp: 1,780 frames spanning 59.30 s give 1,779 / 59.30 = 30.0 fps.
The formula assumes a constant-rate stream and device timestamps in seconds; host arrival order reorders under load, which is the same reason you sync RGB and depth frames by device timestamp.
N is the frame count on the stream, t_first and t_last the device stamps of the first and last frame, and the −1 exists because N frames span N − 1 intervals. One recorded 30 fps session, worked end to end:
- Configured 30 fps; wall clock 60.0 s; frames written N = 1,780; stamps t_first = 0.70 s, t_last = 60.00 s.
- Naive average: 1,780 / 60.0 = 29.67 fps.
- Span: 60.00 − 0.70 = 59.30 s.
- True average: (1,780 − 1) / 59.30 = 1,779 / 59.30 = 30.0 fps.
- Startup gap: 60.0 − 59.3 = 0.70 s — the whole deficit.
- ACTUAL_FPS on the first frames reads 30, so the sensor held target and the file is valid at 30 fps.
Sensitivity: one dropped frame moves a 60 s file by 1 / 59.30 ≈ 0.02 fps and a 6 s file by 1 / 5.3 ≈ 0.19 fps, so short recordings expose drops that long ones hide. At 30 fps the period is 1000 / 30 = 33.3 ms, so a single drop shows as one delta of about 66.7 ms in the stamp sequence.
How do you verify the rate before you trust it?
Record a controlled session and require all three methods to agree. A stream configured at 15 fps for 10 s must read 15 in the info message, 15 in ACTUAL_FPS and 15 ± 0.5 from the timestamp span; any wider gap names its cause.
Ten seconds at 15 fps should produce roughly 140-150 frames and a span near 9.3-10.0 s. The readings cross-check like this:
| What you read | One 30 fps bag | What it decides |
|---|---|---|
| StreamInfo fps | 30 | the configured target |
| ACTUAL_FPS per frame | 30 | the delivered rate |
| (N − 1) / span | 30.0 | the average the file holds |
| frames ÷ wall clock | 29.67 | nothing on its own |
Acceptance rule: pass the file when the span average lands within 1% of the configured rate — 0.30 fps at 30 fps — and sampled frames read ACTUAL_FPS equal to the target. Fail it when ACTUAL_FPS sits under StreamInfo (exposure cap) or when deltas at multiples of the period mark drops, and re-record instead of shipping. The same distrust of a reported rate applies on the OpenCV side, where the FPS property returns zero and the rate has to be read from the stream itself — the OpenCV FPS guide covers it. On the capture side, playing a bag back without dropped frames is the other half of a valid recording.
Why does a recorded stream sit below its configured rate?
Two mechanisms pull a recording under its configured rate: exposure that forces the depth sensor to half rate, turning a 30 fps stream into 15, and dropped frames on the way to disk, visible as 66.7 ms deltas where 33.3 ms belongs.
At 30 fps one frame period is 1000 / 30 = 33.3 ms. Exposure that needs longer than one period forces the sensor to skip frames, and the metadata records the truth: StreamInfo 30, ACTUAL_FPS 15. The fix lives at capture — cap exposure below one period, add light, or configure the stream at the rate the exposure supports; the depth camera frame rate guide traces the exposure-to-rate mechanism.
Drops subtract from N permanently and show as deltas at two or more periods — 66.7 ms and up at 30 fps. Trace them at capture rather than in the file: the missing frames guide lists the causes, from recorder stalls to host contention, and the fixes.
When the camera cannot hold its configured rate at your exposure, the fix is upstream of the code: a sensor whose exposure budget fits the target rate. Browse the 3D camera finder, compare the 3D sensors below, then set the whole chain in the configurator — or talk through your rate and exposure numbers with us. The 3D topic page collects the rest of the capture-side guides.
Laser profilers and stereo 3D cameras
170 models · from $699.00The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.
Questions
Can I read the recorded FPS in Python instead?
Yes, and it is the quickest sanity check: open the bag, take the first message on each stream info topic and read its fps field, the same two values the C++ view returns. Use Python for spot checks and the C++ route when the reading ships inside your application. The timestamp-span formula is three lines there as well: first stamp, last stamp, frame count.
How do I find the info topic names in a bag with several devices?
List the bag's topics before hardcoding any string: every stream writes its info message to a topic numbered the same way as /device_0/sensor_0/Depth_0/info, and the sensor index does not guarantee depth comes first. Match on the stream name inside the topic string, then reuse the same pairing at replay time so depth and color land on the right streams. The recorder writes that mapping when the session starts.
Is ACTUAL_FPS stored in every bag automatically?
No. It travels with the frames only when frame metadata was enabled before the recording started, and a build without metadata support reports the value as unsupported rather than zero. Open one bag from your own recorder, read the metadata off a single frame and only then build an acceptance test on top of it; otherwise lean on the timestamp-span method.
Can I raise the FPS of an existing bag file?
No. The file stores frames exactly as they were captured, so a stream that landed at 15 fps cannot become a 30 fps recording afterwards. If the rate matters downstream, fix what capped it, most often the exposure, and record the session again; resampling timestamps during playback only relabels frames you already have.