• Docs >
  • libtorio >
  • torio::io::StreamingMediaDecoder >
  • Nightly (unstable)
Shortcuts

Warning

TorchAudio’s C++ API is a prototype feature. API/ABI backward compatibility is not guaranteed.

Note

The top-level namespace has been changed from torchaudio to torio. StreamReader has been renamed to StreamingMediaDecoder.

torio::io::StreamingMediaDecoder

StreamingMediaDecoder is the implementation used by Python equivalent and provides similar interface. When working with custom I/O, such as in-memory data, StreamingMediaDecoderCustomIO class can be used.

Both classes have the same methods defined, so their usages are the same.

Constructors

StreamingMediaDecoder

class StreamingMediaDecoder

Fetch and decode audio/video streams chunk by chunk.

Unnamed Group

private: int drain();

//////////////////////////////////////////////////////////////////////////// Retrieval //////////////////////////////////////////////////////////////////////////// public: / /

/ Pop one chunk from each output stream if it is available. std::vector<std::optional<Chunk>> pop_chunks();

/

/

Warning

doxygenfunction: Unable to resolve function “torio::io::StreamingMediaDecoder::StreamingMediaDecoder” with arguments (const std::string&, const std::optional<std::string>&, const c10::optional<OptionDict>&) in doxygen xml output for project “libtorio” from directory: cpp/xml. Potential matches:

- StreamingMediaDecoder(const std::string &src, const std::optional<std::string> &format = std::nullopt, const std::optional<OptionDict> &option = std::nullopt)

StreamingMediaDecoderCustomIO

Warning

doxygenclass: Cannot find class “torio::io::StreamingMediaDecoderCustomIO” in doxygen xml output for project “libtorio” from directory: cpp/xml

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoderCustomIO::StreamingMediaDecoderCustomIO” in doxygen xml output for project “libtorio” from directory: cpp/xml

Query Methods

find_best_audio_stream

int64_t torio::io::StreamingMediaDecoder::find_best_audio_stream() const

Find a suitable audio stream using heuristics from ffmpeg.

If successful, the index of the best stream (>=0) is returned. Otherwise a negative value is returned.

find_best_video_stream

int64_t torio::io::StreamingMediaDecoder::find_best_video_stream() const

Find a suitable video stream using heuristics from ffmpeg.

If successful, the index of the best stream (0>=) is returned. otherwise a negative value is returned.

get_metadata

OptionDict torio::io::StreamingMediaDecoder::get_metadata() const

Fetch metadata of the source media.

num_src_streams

int64_t torio::io::StreamingMediaDecoder::num_src_streams() const

Fetch the number of source streams found in the input media.

The source streams include not only audio/video streams but also subtitle and others.

get_src_stream_info

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::get_src_stream_info” in doxygen xml output for project “libtorio” from directory: cpp/xml

num_out_streams

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::num_out_streams” in doxygen xml output for project “libtorio” from directory: cpp/xml

get_out_stream_info

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::get_out_stream_info” in doxygen xml output for project “libtorio” from directory: cpp/xml

is_buffer_ready

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::is_buffer_ready” in doxygen xml output for project “libtorio” from directory: cpp/xml

Configure Methods

add_audio_stream

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::add_audio_stream” in doxygen xml output for project “libtorio” from directory: cpp/xml

add_video_stream

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::add_video_stream” in doxygen xml output for project “libtorio” from directory: cpp/xml

remove_stream

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::remove_stream” in doxygen xml output for project “libtorio” from directory: cpp/xml

Stream Methods

seek

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::seek” in doxygen xml output for project “libtorio” from directory: cpp/xml

process_packet

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::process_packet” in doxygen xml output for project “libtorio” from directory: cpp/xml

process_packet_block

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::process_packet_block” in doxygen xml output for project “libtorio” from directory: cpp/xml

process_all_packets

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::process_all_packets” in doxygen xml output for project “libtorio” from directory: cpp/xml

fill_buffer

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::fill_buffer” in doxygen xml output for project “libtorio” from directory: cpp/xml

Retrieval Methods

pop_chunks

Warning

doxygenfunction: Cannot find function “torio::io::StreamingMediaDecoder::pop_chunks” in doxygen xml output for project “libtorio” from directory: cpp/xml

Support Structures

Chunk

Warning

doxygenstruct: Cannot find class “torio::io::Chunk” in doxygen xml output for project “libtorio” from directory: cpp/xml

SrcStreaminfo

struct SrcStreamInfo

Information about source stream found in the input media.

COMMON MEMBERS

AVMediaType media_type

The stream media type.

Please see refer to the FFmpeg documentation for the available values

Todo:

Introduce own enum and get rid of FFmpeg dependency

const char *codec_name = "N/A"

The name of codec.

const char *codec_long_name = "N/A"

The name of codec in long, human friendly form.

Unnamed Group

/ /

/ Width int width = -1;

/ Height int height = -1;

/ Frame rate AVRational frame_rate{0, 1};

/

torch::Tensor frames

};

/ Stores decoded frames and metadata struct Chunk { / Audio/video frames. / / For audio, the shape is [time, num_channels], and the dtype / depends on output stream configurations. / / For video, the shape is [time, channel, height, width], and / the dtype is torch.uint8.

double pts

Presentation time stamp of the first frame, in second.

OutputStreaminfo

Warning

doxygenstruct: Cannot find class “torio::io::OutputStreamInfo” in doxygen xml output for project “libtorio” from directory: cpp/xml

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources