- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.9k
 
Delete empty images dir with VideoEncodingManager. #1897
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
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds automatic cleanup of empty image directories after video encoding in the VideoEncodingManager. The change ensures that temporary image directories created during video encoding are removed once the video conversion is complete.
Key changes:
- Wraps video encoding operations with VideoEncodingManager context manager to handle cleanup
 - Adds test coverage for video dataset creation and verification of cleanup behavior
 
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description | 
|---|---|
| src/lerobot/datasets/lerobot_dataset.py | Wraps video encoding calls with VideoEncodingManager context manager for automatic cleanup | 
| tests/datasets/test_datasets.py | Adds video dataset fixture and test to verify video creation and image directory cleanup | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| with VideoEncodingManager(self): | ||
| self.encode_episode_videos(episode_index) | 
    
      
    
      Copilot
AI
    
    
    
      Sep 9, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The VideoEncodingManager context manager wraps only the encode_episode_videos call. Consider whether other operations within this conditional block should also be included in the context manager scope for consistency.
| logging.info( | ||
| f"Batch encoding {self.batch_encoding_size} videos for episodes {start_ep} to {end_ep - 1}" | ||
| ) | ||
| self.batch_encode_videos(start_ep, end_ep) | ||
| with VideoEncodingManager(self): | 
    
      
    
      Copilot
AI
    
    
    
      Sep 9, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Similar to the single episode encoding, consider whether the logging statement on line 879-881 should be included within the VideoEncodingManager context for consistency with the overall batch operation.
| logging.info( | |
| f"Batch encoding {self.batch_encoding_size} videos for episodes {start_ep} to {end_ep - 1}" | |
| ) | |
| self.batch_encode_videos(start_ep, end_ep) | |
| with VideoEncodingManager(self): | |
| with VideoEncodingManager(self): | |
| logging.info( | |
| f"Batch encoding {self.batch_encoding_size} videos for episodes {start_ep} to {end_ep - 1}" | |
| ) | 
| 
           Hi @yuya-haruna, Thank you for your contribution ! If I understand correctly, you suggest to delete the temporary images folder at the end of each episode or batch of episodes, right ? If that's indeed the case, that would mean that the folder has to be re-created at the beginning of the next episode/batch of episodes, which looks a bit troublesome. Let me know if there is something I missed ! Best, Caroline,  | 
    
| 
           Hi, @CarolinePascal Yes,  I understand this doesn’t really make things any less troublesome.  | 
    
| 
           Hi @yuya-haruna, The image folder is indeed "created" at the beginning of each episode, but that does not mean that we have to delete it at the end of each episode. It should rather be seen as a safety measure in case this folder is mistakenly deleted between episodes. Eventhough deleting the image folder as you suggest would not impact the recording process, it will 1) make the code more bloated and 2) somehow increase the recording overhead as the folder is deleted and recreated at each new episode. Unless there is something else I didn't understand (please let me know !), I suggest we close this PR. Best, Caroline.  | 
    
| 
           Hi, @CarolinePascal 
 The images directory deleted by VideoEncodingManager is only recognized when it is empty. I created this PR because it seemed unnatural that the images directory remained empty after conversion, even though all *.jpg files within it had been deleted. While minor, the increased cost of directory recreation is indeed as you pointed out.  | 
    
What this does
Delete the empty images dir after converting the video on
save_episode().Use
VideoEncodingManagerfor delete images dir.How it was tested
Added
test_add_frame_videointests/datasets/test_datasets.py.imagesdir deleted.How to checkout & try? (for the reviewer)