Make video encoding resilient to single invalid image frames #2651
+5
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this does
Summary
This PR makes dataset frame recording robust to user-triggered interruptions by synchronizing calls to
dataset.add_framein the control loop.When recording episodes interactively, users may terminate an episode (e.g. by pressing the
Skey) while image frames are still being written. Previously, this could result in partially written or empty image files, which later caused failures during episode saving or video encoding.By introducing a lock around
dataset.add_frame, this change ensures that frame writes are completed atomically with respect to episode termination, preventing corrupted frame files from being produced.Problem
When I run
error occurs:
I realized that the error was caused by a forced exit after pressing the S key, which interrupted the recording of the last frame’s information in the code. As a result, the final frame’s image file was corrupted, leading to this error.
Changes
threading.Lockin the control loopdataset.add_frame()with this lockThis change does not alter dataset format, recording semantics, or public APIs. It only enforces proper synchronization during frame recording.