Skip to content

Commit da5b1cb

Browse files
authored
Let the CM be on open() (#1410)
1 parent ee03112 commit da5b1cb

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/torchcodec/encoders/_multi_stream_encoder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ def add_audio(
8989

9090
# TODO MultiStreamEncoder: Maybe there should 2 separate methods, one for
9191
# file, one for file-like.
92-
def open(self, dest, *, format: str | None = None) -> None:
92+
def open(self, dest, *, format: str | None = None) -> "StreamingEncoder":
9393
if format is not None:
9494
_core.streaming_encoder_open_file_like(self._encoder_tensor, format, dest)
9595
else:
9696
_core.streaming_encoder_open_file(self._encoder_tensor, str(dest))
97+
return self
9798

9899
def close(self) -> None:
99100
_core.streaming_encoder_close(self._encoder_tensor)

test/test_encoders.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,7 @@ def test_context_manager(self, tmp_path, method):
15891589
enc, encoder_output, open_kwargs = self._create_encoder(method, tmp_path, "mp4")
15901590
frames = torch.randint(0, 256, (5, 3, 64, 64), dtype=torch.uint8)
15911591
video = enc.add_video(height=64, width=64, frame_rate=30.0)
1592-
enc.open(**open_kwargs)
1593-
with enc:
1592+
with enc.open(**open_kwargs):
15941593
video.write(frames)
15951594

15961595
# The output is valid and decodable, proving close() was called by __exit__.

0 commit comments

Comments
 (0)