Skip to content
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

Accept 'auto' in num_ffmpeg_threads #400

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/torchcodec/decoders/_video_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class VideoDecoder:
cheap no-copy operation that allows these frames to be
transformed using the `torchvision transforms
<https://pytorch.org/vision/stable/transforms.html>`_.
num_ffmpeg_threads (int, optional): The number of threads to use for decoding.
num_ffmpeg_threads (int or str, optional): The number of threads to use for decoding.
Use 1 for single-threaded decoding which may be best if you are running multiple
instances of ``VideoDecoder`` in parallel. Use a higher number for multi-threaded
decoding which is best if you are running a single instance of ``VideoDecoder``.
"auto" is equivalent to passing 0 and lets FFmpeg automatically decide.
Default: 1.
device (str or torch.device, optional): The device to use for decoding. Default: "cpu".

Expand All @@ -64,7 +65,7 @@ def __init__(
*,
stream_index: Optional[int] = None,
dimension_order: Literal["NCHW", "NHWC"] = "NCHW",
num_ffmpeg_threads: int = 1,
num_ffmpeg_threads: Union[int, str] = 1,
device: Optional[Union[str, device]] = "cpu",
):
if isinstance(source, str):
Expand All @@ -88,6 +89,14 @@ def __init__(
f"Supported values are {', '.join(allowed_dimension_orders)}."
)

if isinstance(num_ffmpeg_threads, str):
if num_ffmpeg_threads != "auto":
raise ValueError(
"num_ffmpeg_threads should be 'auto' when it's a string. "
f"Got {num_ffmpeg_threads}"
)
num_ffmpeg_threads = 0

core.scan_all_streams_to_update_metadata(self._decoder)
core.add_video_stream(
self._decoder,
Expand Down
Loading