avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::Stream Class Reference

One stream inside a container. More...

#include <stream.h>

Inheritance diagram for av::Stream:

Public Member Functions

bool isValid () const
 Whether the view refers to a stream.
int index () const
 Position of the stream in its container.
int id () const
 Stream identifier from the container.
Rational frameRate () const
 Frame rate declared by the stream.
Rational timeBase () const
 Time base of the timestamps in this stream.
Rational sampleAspectRatio () const
 Pixel aspect ratio declared by the stream.
Rational averageFrameRate () const
 Average frame rate of the stream.
Timestamp startTime () const
 Timestamp of the first frame in this stream.
Timestamp duration () const
 Duration of the stream.
Timestamp currentDts () const
 Decoding timestamp of the packet currently being processed by this stream.
AVMediaType mediaType () const
 Kind of media the stream carries.
bool isAudio () const
 Whether this is an audio stream.
bool isVideo () const
 Whether this is a video stream.
bool isData () const
 Whether this is a data stream.
bool isSubtitle () const
 Whether this is a subtitle stream.
bool isAttachment () const
 Whether this is an attachment stream, such as an embedded font.
Direction direction () const
 Direction the stream is used in.
void setTimeBase (const Rational &timeBase)
 Set the time base of the stream.
void setFrameRate (const Rational &frameRate)
 Set the declared frame rate.
void setSampleAspectRatio (const Rational &aspectRatio)
 Set the pixel aspect ratio.
void setAverageFrameRate (const Rational &frameRate)
 Set the average frame rate.
CodecParametersView codecParameters () const
 Codec parameters of the stream.
void setCodecParameters (CodecParametersView codecpar, OptionalErrorCode ec=throws())
 Copy codec parameters into the stream.
int eventFlags () const noexcept
 Flags to the user to detect events happening on the stream.
bool eventFlags (int flags) const noexcept
 Whether any of the given events happened.
void eventFlagsClear (int flags) noexcept
 Acknowledge events.
void setupEncodingParameters (const class VideoEncoderContext &ctx, OptionalErrorCode ec=throws())
 Configure an output stream from a video encoder.
Public Member Functions inherited from FFWrapperPtr< AVStream >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVStream * raw () const
 Read access to the wrapped object.
void reset (AVStream *raw=nullptr)
 Replace the stored pointer.
bool isNull () const
 Whether the wrapper is empty.
void _log (int level, const char *fmt) const
 Log through the FFmpeg log system, using this wrapper as the context.

Friends

class FormatContext

Additional Inherited Members

Protected Attributes inherited from FFWrapperPtr< AVStream >
AVStream * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Detailed Description

A stream is a view: it points into the AVFormatContext that owns the AVStream, so it must not outlive that context. Copying a Stream is cheap and does not copy any stream data.

Every value here has meaning only after FormatContext::findStreamInfo(): a container read only far enough to list its streams reports incomplete codec parameters and zeroed timings.

Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-decode-rasample-audio.cpp, api2-decode.cpp, api2-generate-subtitles.cpp, api2-hw-decode.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-scale-video.cpp, api2-send-receive.cpp, and api2-subtitles.cpp.

Member Function Documentation

◆ averageFrameRate()

Rational av::Stream::averageFrameRate ( ) const

Encoders and muxers prefer the average over the nominal rate for variable frame rate content.

Returns
frames per second, or an empty value when it is unknown
Examples
api2-generate-subtitles.cpp.

◆ codecParameters()

CodecParametersView av::Stream::codecParameters ( ) const
Returns
a non-owning view; it stays valid while the container is open
Examples
api2-generate-subtitles.cpp, api2-hw-decode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, and api2-remux.cpp.

◆ currentDts()

Timestamp av::Stream::currentDts ( ) const
Deprecated
For FFmpeg 5.0 and newer this returns NO_PTS: take the DTS from the packet instead.
Returns
the decoding timestamp, or NO_PTS when the stream does not provide one
Deprecated
For FFmpeg 5.0+ return NO_PTS

◆ direction()

Direction av::Stream::direction ( ) const
inline
Returns
Encoding for an output stream, Decoding for an input one

◆ duration()

Timestamp av::Stream::duration ( ) const
Returns
the duration in the stream time base, or NoPts when unknown

◆ eventFlags() [1/2]

int av::Stream::eventFlags ( ) const
noexcept

A combination of AVSTREAM_EVENT_FLAG_*. Must be cleared by the user.

See also
AVFormatContext::event_flags
Returns
Events FFmpeg raised for this stream, as a bit mask.
a combination of AVSTREAM_EVENT_FLAG_*; the caller must clear it

◆ eventFlags() [2/2]

bool av::Stream::eventFlags ( int flags) const
noexcept
Parameters
flagsthe AVSTREAM_EVENT_FLAG_* bits to test
Returns
true when at least one of the flags is set

◆ eventFlagsClear()

void av::Stream::eventFlagsClear ( int flags)
noexcept
Parameters
flagsthe bits to clear

◆ frameRate()

Rational av::Stream::frameRate ( ) const

◆ id()

int av::Stream::id ( ) const

Unlike index(), the id is stable across containers and is what muxers store, but FFmpeg does not require it to be unique.

Returns
the container's stream id

◆ index()

int av::Stream::index ( ) const
Returns
the index used to match packets and frames to this stream
Examples
api2-decode.cpp, api2-generate-subtitles.cpp, api2-hw-decode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-send-receive.cpp, and api2-subtitles.cpp.

◆ isAttachment()

bool av::Stream::isAttachment ( ) const
Returns
true for AVMEDIA_TYPE_ATTACHMENT

◆ isAudio()

bool av::Stream::isAudio ( ) const
Returns
true for AVMEDIA_TYPE_AUDIO

◆ isData()

bool av::Stream::isData ( ) const
Returns
true for AVMEDIA_TYPE_DATA

◆ isSubtitle()

bool av::Stream::isSubtitle ( ) const
Returns
true for AVMEDIA_TYPE_SUBTITLE

◆ isValid()

◆ isVideo()

bool av::Stream::isVideo ( ) const
Returns
true for AVMEDIA_TYPE_VIDEO

◆ mediaType()

AVMediaType av::Stream::mediaType ( ) const
Returns
the AVMEDIA_TYPE_* value

◆ sampleAspectRatio()

Rational av::Stream::sampleAspectRatio ( ) const
Returns
width divided by height of one pixel, or an empty value when it is not declared

◆ setAverageFrameRate()

void av::Stream::setAverageFrameRate ( const Rational & frameRate)

◆ setCodecParameters()

void av::Stream::setCodecParameters ( CodecParametersView codecpar,
OptionalErrorCode ec = throws() )

This is how a muxer learns what the packets will contain during remuxing, without opening any codec.

Parameters
codecparthe parameters to copy
echolder for the error code
Examples
api2-remux.cpp.

◆ setFrameRate()

◆ setSampleAspectRatio()

void av::Stream::setSampleAspectRatio ( const Rational & aspectRatio)
Parameters
aspectRatiowidth divided by height of one pixel

◆ setTimeBase()

void av::Stream::setTimeBase ( const Rational & timeBase)
Parameters
timeBasetimestamp units per second; must be set before the header of an output container is written
Examples
api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, and api2-scale-video.cpp.

◆ setupEncodingParameters()

void av::Stream::setupEncodingParameters ( const class VideoEncoderContext & ctx,
OptionalErrorCode ec = throws() )

Copies the encoder parameters into the stream: size, pixel format, frame rate, aspect ratio and time base.

Parameters
ctxan opened encoder
echolder for the error code

◆ startTime()

Timestamp av::Stream::startTime ( ) const
Returns
the start time in the stream time base, or NoPts when unknown
Examples
api2-generate-subtitles.cpp.

◆ timeBase()

Rational av::Stream::timeBase ( ) const
Returns
timestamp units per second

The documentation for this class was generated from the following file: