Commit 0c5a8bf7 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Add StreamWriter tutorial (#2698)

Summary:
Add a tutorial for basic usage of torchaudio.io.StreamWriter.

https://output.circle-artifacts.com/output/job/55d9a495-af7a-483c-84cb-de9a08cfd2f3/artifacts/0/docs/tutorials/streamwriter_basic_tutorial.html

Pull Request resolved: https://github.com/pytorch/audio/pull/2698

Reviewed By: carolineechen

Differential Revision: D40133007

Pulled By: carolineechen

fbshipit-source-id: 141f692c32343981bfb228357f21562ffe36f623
parent fdbf1450
...@@ -16,5 +16,6 @@ wide variety of media formats, including audio and video, coming from many diffe ...@@ -16,5 +16,6 @@ wide variety of media formats, including audio and video, coming from many diffe
tutorials/audio_io_tutorial tutorials/audio_io_tutorial
tutorials/streamreader_basic_tutorial tutorials/streamreader_basic_tutorial
tutorials/streamreader_advanced_tutorial tutorials/streamreader_advanced_tutorial
tutorials/streamwriter_basic_tutorial
tutorials/streamwriter_advanced tutorials/streamwriter_advanced
hw_acceleration_tutorial hw_acceleration_tutorial
This diff is collapsed.
...@@ -238,8 +238,7 @@ void open_codec( ...@@ -238,8 +238,7 @@ void open_codec(
AVDictionary* opt = get_option_dict(option); AVDictionary* opt = get_option_dict(option);
int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opt); int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opt);
clean_up_dict(opt); clean_up_dict(opt);
TORCH_CHECK( TORCH_CHECK(ret >= 0, "Failed to open codec: (", av_err2string(ret), ")");
ret >= 0, "Failed to open audio codec: (", av_err2string(ret), ")");
} }
AVFramePtr get_audio_frame( AVFramePtr get_audio_frame(
......
...@@ -15,7 +15,7 @@ def _format_doc(**kwargs): ...@@ -15,7 +15,7 @@ def _format_doc(**kwargs):
_encoder = """The name of the encoder to be used. _encoder = """The name of the encoder to be used.
When provided, use the specified encoder instead of the default one. When provided, use the specified encoder instead of the default one.
To list the available encoders, you can use ``ffmpeg -h encoders`` command. To list the available encoders, you can use ``ffmpeg -encoders`` command.
Default: ``None``.""" Default: ``None``."""
...@@ -256,22 +256,25 @@ class StreamWriter: ...@@ -256,22 +256,25 @@ class StreamWriter:
self._is_open = False self._is_open = False
def write_audio_chunk(self, i: int, chunk: torch.Tensor): def write_audio_chunk(self, i: int, chunk: torch.Tensor):
"""Write the audio data """Write audio data
Args: Args:
i (int): Stream index. i (int): Stream index.
chunk (Tensor): Waveform tensor. Shape: `(frame, channel)`. chunk (Tensor): Waveform tensor. Shape: `(frame, channel)`.
The ``dtype`` must match what was passed to :py:func:`add_audio_stream` method. The ``dtype`` must match what was passed to :py:meth:`add_audio_stream` method.
""" """
self._s.write_audio_chunk(i, chunk) self._s.write_audio_chunk(i, chunk)
def write_video_chunk(self, i: int, chunk: torch.Tensor): def write_video_chunk(self, i: int, chunk: torch.Tensor):
"""Write the audio data """Write video/image data
Args: Args:
i (int): Stream index. i (int): Stream index.
chunk (Tensor): Waveform tensor. Shape: `(frame, channel, height, width)`. chunk (Tensor): Video/image tensor.
``dtype``: ``torch.uint8``. Shape: `(time, channel, height, width)`.
The ``dtype`` must be ``torch.uint8``.
The shape (height, width and the number of channels) must match
what was configured when calling :py:meth:`add_video_stream`
""" """
self._s.write_video_chunk(i, chunk) self._s.write_video_chunk(i, chunk)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment