Skip to content

Commit

Permalink
Set the default #threads to 1 in StreamWriter
Browse files Browse the repository at this point in the history
Similrt to #2949
  • Loading branch information
mthrok committed May 24, 2023
1 parent 8b85ca5 commit dbeb7b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions torchaudio/csrc/ffmpeg/stream_writer/encode_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ void open_codec(
}
}

// Default to single thread execution.
if (!av_dict_get(opt, "threads", nullptr, 0)) {
av_dict_set(&opt, "threads", "1", 0);
}

int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opt);
clean_up_dict(opt);
TORCH_CHECK(ret >= 0, "Failed to open codec: (", av_err2string(ret), ")");
Expand Down
24 changes: 23 additions & 1 deletion torchaudio/io/_stream_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,29 @@ def decorator(obj):
To list encoder options for a encoder, you can use
``ffmpeg -h encoder=<ENCODER>`` command.
Default: ``None``."""
Default: ``None``.
|
In addition to encoder-specific options, you can also pass options related
to multithreading. They are effective only if the encoder support them.
If neither of them are provided, StreamReader defaults to single thread.
``"threads"``: The number of threads (in str).
Providing the value ``"0"`` will let FFmpeg decides based on its heuristics.
``"thread_type"``: Which multithreading method to use.
The valid values are ``"frame"`` or ``"slice"``.
Note that each encoder supports different set of methods.
If not provided, a default value is used.
- ``"frame"``: Encode more than one frame at once.
Each thread handles one frame.
This will increase decoding delay by one frame per thread
- ``"slice"``: Encode more than one part of a single frame at once.
|
"""


_encoder_format = """Format used to encode media.
Expand Down

0 comments on commit dbeb7b7

Please sign in to comment.