librealsense: Unable to open ros file after saving using pyrealsense2
-
Before opening a new issue, we wanted to provide you with some useful suggestions (Click “Preview” above for a better view):
- Consider checking out SDK examples.
- Have you looked in our documentations?
- Is you question a frequently asked one?
- Try searching our GitHub Issues (open and closed) for a similar issue.
-
All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven’t followed any of the suggestions above 😃
Required Info | |
---|---|
Camera Model | D435 |
Firmware Version | 05.10.13.00 |
Operating System & Version | Linux (Ubuntu 16) |
Kernel Version (Linux Only) | 4.15.0-43 |
Platform | PC |
SDK Version | 2.17.1 |
Language | python 3.5.6 |
Issue Description
I’m having an issue with opening up a bag file with the realsense viewer after recording it in Python. I get this error:
Failed to load file … test.bag. Reason: Io in rs2_context_add_device(ctx:0x1274510, file:/): Failed to create ros reader: Bag unindexed
This looks similar but not quite the same as issue 2326 but I’m unable to resolve it.
The code is as follows:
import pyrealsense2 as rs
import time
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
config.enable_record_to_file('test.bag')
pipeline.start(config)
try:
start=time.time()
while time.time() - start < 20:
pipeline.wait_for_frames()
finally:
pipeline.stop()
Oddly, I’m able to open the bag file if I run this code, and then re-run it and change
pipeline.start(config)
to pipeline.start()
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
Thanks so much @lamuyang for sharing what worked for you!
I don’t have constant access to the Realsense cameras, as we are using them to collect data for a study. This is a relatively low priority issue for me, because – as expected – destruction of the objects was a sufficient work-around. As @jkenney9a and I noted, a call to .stop did not write the bag properly, but a call to .stop plus the deliberate destruction of all Realsense objects does result in a working bag. I still consider this an issue, but not one that I can spend more time on.
Did you try @jkenney9a 's code in IPython? That seems like the simplest way to reproduce the error. IPython is an important part of the equation, as it is likely preventing the wrapper from cleaning up. As dorodnic noted, the issue is likely caused by wrappers that do not completely clean up Realsense objects. As @jkenney9a and I noted, this does not seem like expected or appropriate behavior. When we call .stop, we have the expectation that we’ve written a valid bag file. But the persistence of the Realsense objects (due to IPython in @jkenney9a 's case and persistent class variables in mine) seems to prevent this.
I can’t test this right now, but the following code probably results in an improperly indexed bag:
Well shouldn’t running the command
pipeline.stop()
be sufficient to properly close and index the bag file? Sounds like this isn’t python specific, a similar issue has been brought up with C++ here.Just wanted to give a brief update. I’m using Anaconda and Spyder for code development. This issue happens when I’m running the code in Spyder and executing in the IPython console. However, if I execute it from the shell (i.e.
python video_recording.py
), then there is no issue with opening the resulting file. This is a little annoying for code development, but at the end of the day this is how we plan on making use of the file so not as major an issue for us.I am using C++ and experiencing similar issues. After a recording, I cannot open the file directly as I will get the same error. I’ve got to close and open my application (restart) in order to successfully open the bag file.
I think there is something wrong during the desconstruction of
enable_record_to_file
function/config. Some resources of some sort are not properly closed.Hopefully there will be some traction in this issue which might help my case as well. Fingers crossed