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

Container context: the entry point for demuxing, muxing and seeking. More...

#include <formatcontext.h>

Inheritance diagram for av::FormatContext:

Public Member Functions

void setSocketTimeout (int64_t timeout)
 Abort network operations that block for too long.
void setInterruptCallback (const AvioInterruptCb &cb)
 Install a callback that can cancel blocking IO.
void setFormat (const InputFormat &format)
 Force the demuxer used by openInput().
void setFormat (const OutputFormat &format)
 Force the muxer used by openOutput().
InputFormat inputFormat () const
 The demuxer in use.
OutputFormat outputFormat () const
 The muxer in use.
bool isOutput () const
 Whether this context writes instead of reads.
bool isOpened () const
 Whether the container is open.
void flush ()
 Discard buffered packets and internal state.
void close ()
 Close the container and release its resources.
void dump () const
 Print the container layout through the FFmpeg log system.
size_t streamsCount () const
 Number of streams in the container.
Stream stream (size_t idx)
 Stream by index.
Stream stream (size_t idx, OptionalErrorCode ec)
 Stream by index, reporting an out-of-range index as an error.
Stream addStream (const Codec &codec, OptionalErrorCode ec=throws())
 Add a stream for the given codec.
Stream addStream (OptionalErrorCode ec=throws())
 Add a stream to an output container.
Stream addStream (const class VideoEncoderContext &encCtx, OptionalErrorCode ec=throws())
 Add a video stream configured from an encoder context.
Stream addStream (const class AudioEncoderContext &encCtx, OptionalErrorCode ec=throws())
 Add an audio stream configured from an encoder context.
StreamsView streams (OptionalErrorCode ec=throws()) const
 All streams as a range, for range-based for and std algorithms.
bool seekable () const noexcept
 Whether the container supports seeking.
void seek (const Timestamp &timestamp, OptionalErrorCode ec=throws())
 Seek to a timestamp in any stream.
void seek (const Timestamp &timestamp, size_t streamIndex, OptionalErrorCode ec=throws())
 Seek to a timestamp in a specific stream.
void seek (const Timestamp &timestamp, bool anyFrame, OptionalErrorCode ec=throws())
 Seek to a timestamp, choosing between key frames and any frame.
void seek (const Timestamp &timestamp, size_t streamIndex, bool anyFrame, OptionalErrorCode ec=throws())
 Seek to a timestamp in a specific stream, choosing the frame kind.
void seek (int64_t position, int streamIndex, int flags, OptionalErrorCode ec=throws())
 Seek with raw FFmpeg arguments.
Timestamp startTime () const noexcept
 Start time of the container.
Timestamp duration () const noexcept
 Duration of the container.
void substractStartTime (bool enable)
 Shift timestamps so the file starts at zero.
int eventFlags () const noexcept
 Flags to the user to detect events happening on the file.
bool eventFlags (int flags) const noexcept
 Whether any of the given events happened.
void eventFlagsClear (int flags) noexcept
 Acknowledge events.
void openInput (const std::string &uri, OptionalErrorCode ec=throws())
 Open an input and probe its container.
void openInput (const std::string &uri, Dictionary &formatOptions, OptionalErrorCode ec=throws())
 Open an input with demuxer options.
void openInput (const std::string &uri, Dictionary &&formatOptions, OptionalErrorCode ec=throws())
 Open an input with demuxer options, taking ownership of the dictionary.
void openInput (const std::string &uri, InputFormat format, OptionalErrorCode ec=throws())
 Open an input with an explicit demuxer.
void openInput (const std::string &uri, Dictionary &formatOptions, InputFormat format, OptionalErrorCode ec=throws())
 Open an input with an explicit demuxer and options.
void openInput (const std::string &uri, Dictionary &&formatOptions, InputFormat format, OptionalErrorCode ec=throws())
 Open an input with an explicit demuxer and options, moving the dictionary.
void openInput (CustomIO *io, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object.
void openInput (CustomIO *io, Dictionary &formatOptions, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object with demuxer options.
void openInput (CustomIO *io, Dictionary &&formatOptions, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object with demuxer options, moving the dictionary.
void openInput (CustomIO *io, InputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object with an explicit demuxer.
void openInput (CustomIO *io, Dictionary &formatOptions, InputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object with an explicit demuxer and options.
void openInput (CustomIO *io, Dictionary &&formatOptions, InputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open an input on a custom IO object with an explicit demuxer and options, moving the dictionary.
void findStreamInfo (OptionalErrorCode ec=throws())
 Read the stream parameters of an opened input.
void findStreamInfo (DictionaryArray &streamsOptions, OptionalErrorCode ec=throws())
 Read the stream parameters with per-stream options.
void findStreamInfo (DictionaryArray &&streamsOptions, OptionalErrorCode ec=throws())
 Read the stream parameters with per-stream options, moving them in.
Packet readPacket (OptionalErrorCode ec=throws())
 Read the next packet from any stream.
void openOutput (const std::string &uri, OptionalErrorCode ec=throws())
 Open an output.
void openOutput (const std::string &uri, Dictionary &options, OptionalErrorCode ec=throws())
 Open an output with muxer options.
void openOutput (const std::string &uri, Dictionary &&options, OptionalErrorCode ec=throws())
 Open an output with muxer options, moving the dictionary.
void openOutput (const std::string &uri, OutputFormat format, OptionalErrorCode ec=throws())
 Open an output with an explicit muxer.
void openOutput (const std::string &uri, Dictionary &options, OutputFormat format, OptionalErrorCode ec=throws())
 Open an output with an explicit muxer and options.
void openOutput (const std::string &uri, Dictionary &&options, OutputFormat format, OptionalErrorCode ec=throws())
 Open an output with an explicit muxer and options, moving the dictionary.
void writeHeader (OptionalErrorCode ec=throws())
 Write the container header.
void writeHeader (Dictionary &options, OptionalErrorCode ec=throws())
 Write the container header with muxer options.
void writeHeader (Dictionary &&options, OptionalErrorCode ec=throws())
 Write the container header with muxer options, moving the dictionary.
void writePacket (OptionalErrorCode ec=throws())
 Flush the muxer queue.
void writePacket (const Packet &pkt, OptionalErrorCode ec=throws())
 Write one packet.
void writePacketDirect (OptionalErrorCode ec=throws())
 Flush the muxer queue without intercepting FFmpeg errors.
void writePacketDirect (const Packet &pkt, OptionalErrorCode ec=throws())
 Write one packet without intercepting FFmpeg errors.
bool checkUncodedFrameWriting (size_t streamIndex, std::error_code &ec) noexcept
 Whether an uncompressed frame can be written to a stream.
bool checkUncodedFrameWriting (size_t streamIndex) noexcept
 Whether an uncompressed frame can be written to a stream.
void writeUncodedFrame (class VideoFrame &frame, size_t streamIndex, OptionalErrorCode ec=throws())
 Write an uncompressed video frame through the muxer.
void writeUncodedFrameDirect (class VideoFrame &frame, size_t streamIndex, OptionalErrorCode ec=throws())
 Write an uncompressed video frame without intercepting FFmpeg errors.
void writeUncodedFrame (class AudioSamples &frame, size_t streamIndex, OptionalErrorCode ec=throws())
 Write uncompressed audio samples through the muxer.
void writeUncodedFrameDirect (class AudioSamples &frame, size_t streamIndex, OptionalErrorCode ec=throws())
 Write uncompressed audio samples without intercepting FFmpeg errors.
void writeTrailer (OptionalErrorCode ec=throws())
 Write the container trailer and close the output.
void openOutput (CustomIO *io, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object.
bool openOutput (CustomIO *io, Dictionary &formatOptions, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object with explicit muxer options.
bool openOutput (CustomIO *io, Dictionary &&formatOptions, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object with muxer options, moving the dictionary.
void openOutput (CustomIO *io, OutputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object with an explicit output format.
bool openOutput (CustomIO *io, Dictionary &formatOptions, OutputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object with an explicit output format and muxer options.
bool openOutput (CustomIO *io, Dictionary &&formatOptions, OutputFormat format, OptionalErrorCode ec=throws(), size_t internalBufferSize=CUSTOM_IO_DEFAULT_BUFFER_SIZE)
 Open output on a custom IO object with an explicit format and options, moving the dictionary.
bool initOutput (OptionalErrorCode ec=throws())
 Init output without writing the header.
bool initOutput (Dictionary &options, OptionalErrorCode ec=throws())
 Init the output with muxer options instead of writing the header.
bool initOutput (Dictionary &&options, OptionalErrorCode ec=throws())
 Init the output with muxer options, moving the dictionary.
Public Member Functions inherited from FFWrapperPtr< AVFormatContext >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVFormatContext * raw () const
 Read access to the wrapped object.
void reset (AVFormatContext *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.

Static Public Attributes

static constexpr size_t CUSTOM_IO_DEFAULT_BUFFER_SIZE = 200000
 Default size of the buffer avcpp allocates around a custom IO object.

Additional Inherited Members

Protected Member Functions inherited from av::noncopyable
 noncopyable (const noncopyable &)=delete
void operator= (const noncopyable &)=delete
Protected Attributes inherited from FFWrapperPtr< AVFormatContext >
AVFormatContext * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Detailed Description

The context owns the streams and the streams own the packets that come out of them. Reading is a loop of readPacket()/writePacket(); the container itself is opened once and closed by the destructor.

The context is not copyable: it owns resources and FFmpeg refers to it by pointer, so moving it would invalidate the relationships between the streams, the packets and the IO layer.

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-demux-seek.cpp, api2-generate-subtitles.cpp, api2-hw-decode.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, api2-scale-video.cpp, api2-send-receive.cpp, and api2-subtitles.cpp.

Member Function Documentation

◆ addStream() [1/4]

Stream av::FormatContext::addStream ( const class AudioEncoderContext & encCtx,
OptionalErrorCode ec = throws() )
Parameters
encCtxan opened audio encoder; its parameters are copied
echolder for the error code
Returns
the new stream, or an invalid one on failure

◆ addStream() [2/4]

Stream av::FormatContext::addStream ( const class VideoEncoderContext & encCtx,
OptionalErrorCode ec = throws() )
Parameters
encCtxan opened video encoder; its parameters are copied
echolder for the error code
Returns
the new stream, or an invalid one on failure

◆ addStream() [3/4]

Stream av::FormatContext::addStream ( const Codec & codec,
OptionalErrorCode ec = throws() )
Deprecated
The codec argument is not used by the FFmpeg API. Use addStream() without a codec and attach the configured codec context to the returned stream.
Parameters
codeccodec the stream is created for
echolder for the error code; when it is not throws() an error is reported through it instead of an exception
Returns
the new stream, or an invalid one on failure
Deprecated
Codec is not used by the FFmpeg API. Use addStream() without codec and point configured codec context after
Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ addStream() [4/4]

Stream av::FormatContext::addStream ( OptionalErrorCode ec = throws())

The stream parameters are set afterwards, usually by copying them from an input stream or by attaching a configured encoder context.

Parameters
echolder for the error code
Returns
the new stream, or an invalid one on failure

◆ checkUncodedFrameWriting() [1/2]

bool av::FormatContext::checkUncodedFrameWriting ( size_t streamIndex)
noexcept
Parameters
streamIndexindex of the output stream
Returns
true when writeUncodedFrame() can be used

◆ checkUncodedFrameWriting() [2/2]

bool av::FormatContext::checkUncodedFrameWriting ( size_t streamIndex,
std::error_code & ec )
noexcept

Some muxers accept raw frames instead of encoded packets; this checks the stream configuration before the frame is handed over.

Parameters
streamIndexindex of the output stream
ecset when the check fails
Returns
true when writeUncodedFrame() can be used

◆ close()

void av::FormatContext::close ( )

Called by the destructor; call it explicitly only to release file handles early.

Examples
api2-scale-video.cpp.

◆ dump()

void av::FormatContext::dump ( ) const

◆ duration()

Timestamp av::FormatContext::duration ( ) const
noexcept
Returns
the duration, or NoPts when the container does not report one
Examples
api2-decode-audio.cpp.

◆ eventFlags() [1/2]

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

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

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

◆ eventFlags() [2/2]

bool av::FormatContext::eventFlags ( int flags) const
noexcept
Parameters
flagscombination of AVFMT_EVENT_FLAG_* to test
Returns
true when at least one of the flags is set

◆ eventFlagsClear()

void av::FormatContext::eventFlagsClear ( int flags)
noexcept
Parameters
flagsthe AVFMT_EVENT_FLAG_* bits to clear

◆ findStreamInfo() [1/3]

void av::FormatContext::findStreamInfo ( DictionaryArray && streamsOptions,
OptionalErrorCode ec = throws() )
Parameters
streamsOptionsone dictionary per stream, moved into the call
echolder for the error code

◆ findStreamInfo() [2/3]

void av::FormatContext::findStreamInfo ( DictionaryArray & streamsOptions,
OptionalErrorCode ec = throws() )
Parameters
streamsOptionsone dictionary per stream; FFmpeg removes the options it recognizes
echolder for the error code

◆ findStreamInfo() [3/3]

◆ flush()

void av::FormatContext::flush ( )

Used after seeking, so that data read before the seek does not leak into the stream that follows it.

Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, and api2-scale-video.cpp.

◆ initOutput() [1/3]

bool av::FormatContext::initOutput ( Dictionary && options,
OptionalErrorCode ec = throws() )
Parameters
optionsmuxer options, moved into the call
echolder for the error code
Returns
true when the format was initialized here, false when it will be initialized by writeHeader()

◆ initOutput() [2/3]

bool av::FormatContext::initOutput ( Dictionary & options,
OptionalErrorCode ec = throws() )
Parameters
optionsmuxer options; the object stays usable, but FFmpeg removes the options it recognized
echolder for the error code
Returns
true when the format was initialized here, false when it will be initialized by writeHeader()

◆ initOutput() [3/3]

bool av::FormatContext::initOutput ( OptionalErrorCode ec = throws())

All overloads accept the output options as a dictionary, or use the ones set on the context. If a dictionary is passed here, writeHeader() must not be called with the same dictionary.

Parameters
echolder for the error code; when it is not throws() an error is reported through it instead of an exception
Return values
trueformat initialized in avformat_init_output(),
See also
AVSTREAM_INIT_IN_INIT_OUTPUT
Return values
falseformat will be initialized in avformat_write_header(),
See also
AVSTREAM_INIT_IN_WRITE_HEADER

◆ inputFormat()

InputFormat av::FormatContext::inputFormat ( ) const
Returns
the input format, or an empty one when the context is not an input

◆ isOpened()

bool av::FormatContext::isOpened ( ) const
Returns
true between a successful open and close(), or until destruction

◆ isOutput()

bool av::FormatContext::isOutput ( ) const
Returns
true for an output context

◆ openInput() [1/12]

void av::FormatContext::openInput ( const std::string & uri,
Dictionary && formatOptions,
InputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatOptionsdemuxer options, moved into the call
formatthe demuxer to use
echolder for the error code

◆ openInput() [2/12]

void av::FormatContext::openInput ( const std::string & uri,
Dictionary && formatOptions,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatOptionsdemuxer options, moved into the call
echolder for the error code

◆ openInput() [3/12]

void av::FormatContext::openInput ( const std::string & uri,
Dictionary & formatOptions,
InputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatOptionsdemuxer options; the object stays usable, but FFmpeg removes the options it recognized
formatthe demuxer to use
echolder for the error code

◆ openInput() [4/12]

void av::FormatContext::openInput ( const std::string & uri,
Dictionary & formatOptions,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatOptionsdemuxer options; the object stays usable, but FFmpeg removes the options it recognized
echolder for the error code

◆ openInput() [5/12]

void av::FormatContext::openInput ( const std::string & uri,
InputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatthe demuxer to use instead of probing
echolder for the error code

◆ openInput() [6/12]

◆ openInput() [7/12]

void av::FormatContext::openInput ( CustomIO * io,
Dictionary && formatOptions,
InputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iothe source of the bytes; it must outlive the context
formatOptionsdemuxer options, moved into the call
formatthe demuxer to use
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openInput() [8/12]

void av::FormatContext::openInput ( CustomIO * io,
Dictionary && formatOptions,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
inline
Parameters
iothe source of the bytes; it must outlive the context
formatOptionsdemuxer options, moved into the call
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openInput() [9/12]

void av::FormatContext::openInput ( CustomIO * io,
Dictionary & formatOptions,
InputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iothe source of the bytes; it must outlive the context
formatOptionsdemuxer options; the object stays usable, but FFmpeg removes the options it recognized
formatthe demuxer to use
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openInput() [10/12]

void av::FormatContext::openInput ( CustomIO * io,
Dictionary & formatOptions,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
inline
Parameters
iothe source of the bytes; it must outlive the context
formatOptionsdemuxer options; the object stays usable, but FFmpeg removes the options it recognized
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openInput() [11/12]

void av::FormatContext::openInput ( CustomIO * io,
InputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iothe source of the bytes; it must outlive the context
formatthe demuxer to use instead of probing
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openInput() [12/12]

void av::FormatContext::openInput ( CustomIO * io,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
inline
Parameters
iothe source of the bytes; it must outlive the context
echolder for the error code
internalBufferSizesize of the IO buffer avcpp allocates

◆ openOutput() [1/12]

void av::FormatContext::openOutput ( const std::string & uri,
Dictionary && options,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
optionsmuxer options, moved into the call
echolder for the error code

◆ openOutput() [2/12]

void av::FormatContext::openOutput ( const std::string & uri,
Dictionary && options,
OutputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
optionsmuxer options, moved into the call
formatthe muxer to use
echolder for the error code

◆ openOutput() [3/12]

void av::FormatContext::openOutput ( const std::string & uri,
Dictionary & options,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
optionsmuxer options; the object stays usable, but FFmpeg removes the options it recognized
echolder for the error code

◆ openOutput() [4/12]

void av::FormatContext::openOutput ( const std::string & uri,
Dictionary & options,
OutputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
optionsmuxer options; the object stays usable, but FFmpeg removes the options it recognized
formatthe muxer to use
echolder for the error code

◆ openOutput() [5/12]

void av::FormatContext::openOutput ( const std::string & uri,
OptionalErrorCode ec = throws() )

The muxer comes from the format set on the context or from the file name.

Parameters
uriresource name
echolder for the error code
Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ openOutput() [6/12]

void av::FormatContext::openOutput ( const std::string & uri,
OutputFormat format,
OptionalErrorCode ec = throws() )
Parameters
uriresource name
formatthe muxer to use
echolder for the error code

◆ openOutput() [7/12]

bool av::FormatContext::openOutput ( CustomIO * io,
Dictionary && formatOptions,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iocustom IO object that receives the output
formatOptionsmuxer options, moved into the call
echolder for the error code
internalBufferSizesize of the buffer allocated around the custom IO object
Returns
true when the format was initialized during the call, false when it will be initialized by writeHeader()

◆ openOutput() [8/12]

bool av::FormatContext::openOutput ( CustomIO * io,
Dictionary && formatOptions,
OutputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iocustom IO object that receives the output
formatOptionsmuxer options, moved into the call
formatmuxer to use
echolder for the error code
internalBufferSizesize of the buffer allocated around the custom IO object
Returns
true when the format was initialized during the call, false when it will be initialized by writeHeader()

◆ openOutput() [9/12]

bool av::FormatContext::openOutput ( CustomIO * io,
Dictionary & formatOptions,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )

The options are passed to initOutput(), so writeHeader() must not be called with the same dictionary.

Parameters
iocustom IO object that receives the output
formatOptionsmuxer options
echolder for the error code
internalBufferSizesize of the buffer allocated around the custom IO object
Returns
true when the format was initialized during the call, false when it will be initialized by writeHeader()
Return values
truethe format was initialized during the call
falsethe format will be initialized by writeHeader()

◆ openOutput() [10/12]

bool av::FormatContext::openOutput ( CustomIO * io,
Dictionary & formatOptions,
OutputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iocustom IO object that receives the output
formatOptionsmuxer options, passed to initOutput()
formatmuxer to use
echolder for the error code
internalBufferSizesize of the buffer allocated around the custom IO object
Returns
true when the format was initialized during the call, false when it will be initialized by writeHeader()
Return values
truethe format was initialized during the call
falsethe format will be initialized by writeHeader()

◆ openOutput() [11/12]

void av::FormatContext::openOutput ( CustomIO * io,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )

The output format is deduced from the file name, from OutputFormat set on the context, or from the muxer passed explicitly in the overloads below.

Parameters
iocustom IO object that receives the output
echolder for the error code; when it is not throws() an error is reported through it instead of an exception
internalBufferSizesize of the buffer allocated around the custom IO object

◆ openOutput() [12/12]

void av::FormatContext::openOutput ( CustomIO * io,
OutputFormat format,
OptionalErrorCode ec = throws(),
size_t internalBufferSize = CUSTOM_IO_DEFAULT_BUFFER_SIZE )
Parameters
iocustom IO object that receives the output
formatmuxer to use instead of deducing it from the name
echolder for the error code
internalBufferSizesize of the buffer allocated around the custom IO object

◆ outputFormat()

OutputFormat av::FormatContext::outputFormat ( ) const
Returns
the output format, or an empty one when the context is not an output
Examples
api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ readPacket()

◆ seek() [1/5]

void av::FormatContext::seek ( const Timestamp & timestamp,
bool anyFrame,
OptionalErrorCode ec = throws() )
Parameters
timestamptarget position
anyFrametrue stops at any frame, false at a key frame, which is what a decoder needs to start from
echolder for the error code

◆ seek() [2/5]

void av::FormatContext::seek ( const Timestamp & timestamp,
OptionalErrorCode ec = throws() )
Parameters
timestamptarget position; a default timestamp seeks to the start
echolder for the error code
Examples
api2-demux-seek.cpp.

◆ seek() [3/5]

void av::FormatContext::seek ( const Timestamp & timestamp,
size_t streamIndex,
bool anyFrame,
OptionalErrorCode ec = throws() )
Parameters
timestamptarget position in that stream's time base
streamIndexindex of the stream to seek in
anyFrametrue stops at any frame, false at a key frame
echolder for the error code

◆ seek() [4/5]

void av::FormatContext::seek ( const Timestamp & timestamp,
size_t streamIndex,
OptionalErrorCode ec = throws() )
Parameters
timestamptarget position in that stream's time base
streamIndexindex of the stream to seek in
echolder for the error code

◆ seek() [5/5]

void av::FormatContext::seek ( int64_t position,
int streamIndex,
int flags,
OptionalErrorCode ec = throws() )
Parameters
positionbyte position in AV_TIME_BASE units when streamIndex is -1, otherwise in the stream time base
streamIndexstream to seek in, or -1 for the container default
flagscombination of AVSEEK_FLAG_*
echolder for the error code

◆ seekable()

bool av::FormatContext::seekable ( ) const
noexcept
Returns
true when the IO layer reports seek support
Examples
api2-demux-seek.cpp.

◆ setFormat() [1/2]

void av::FormatContext::setFormat ( const InputFormat & format)

◆ setFormat() [2/2]

void av::FormatContext::setFormat ( const OutputFormat & format)
Parameters
formatthe output format; must be set before addStream()

◆ setInterruptCallback()

void av::FormatContext::setInterruptCallback ( const AvioInterruptCb & cb)
Parameters
cbthe callback; it is copied and called from the IO thread

◆ setSocketTimeout()

void av::FormatContext::setSocketTimeout ( int64_t timeout)
Parameters
timeoutmilliseconds without progress before the operation is interrupted; a negative value disables the check

◆ startTime()

Timestamp av::FormatContext::startTime ( ) const
noexcept
Returns
the first timestamp of the file, or NoPts when it is unknown
Examples
api2-decode-audio.cpp.

◆ stream() [1/2]

Stream av::FormatContext::stream ( size_t idx)

◆ stream() [2/2]

Stream av::FormatContext::stream ( size_t idx,
OptionalErrorCode ec )
Parameters
idxzero-based index
echolder for the error code
Returns
the stream handle, or an invalid one when the index is out of range

◆ streams()

StreamsView av::FormatContext::streams ( OptionalErrorCode ec = throws()) const
Parameters
echolder for the error code
Returns
a lazy view over the streams, valid while the context is alive
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.

◆ streamsCount()

◆ substractStartTime()

void av::FormatContext::substractStartTime ( bool enable)
Parameters
enabletrue subtracts startTime() from every timestamp handed out
Examples
api2-decode-audio.cpp.

◆ writeHeader() [1/3]

void av::FormatContext::writeHeader ( Dictionary && options,
OptionalErrorCode ec = throws() )
Parameters
optionsmuxer options, moved into the call
echolder for the error code

◆ writeHeader() [2/3]

void av::FormatContext::writeHeader ( Dictionary & options,
OptionalErrorCode ec = throws() )
Parameters
optionsmuxer options; the object stays usable, but FFmpeg removes the options it recognized
echolder for the error code

◆ writeHeader() [3/3]

void av::FormatContext::writeHeader ( OptionalErrorCode ec = throws())

Must be called after the streams are added and the output is opened, and before the first packet is written.

Parameters
echolder for the error code
Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ writePacket() [1/2]

void av::FormatContext::writePacket ( const Packet & pkt,
OptionalErrorCode ec = throws() )

The packet must already carry the output stream index and timestamps in that stream's time base.

Parameters
pktthe packet to write
echolder for the error code

◆ writePacket() [2/2]

void av::FormatContext::writePacket ( OptionalErrorCode ec = throws())

Call it before writeTrailer() when the muxer may still hold packets, which some formats do for reordering.

Parameters
echolder for the error code
Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ writePacketDirect() [1/2]

void av::FormatContext::writePacketDirect ( const Packet & pkt,
OptionalErrorCode ec = throws() )

Used when the caller needs the raw error codes instead of the avcpp categories.

Parameters
pktthe packet to write
echolder for the error code

◆ writePacketDirect() [2/2]

void av::FormatContext::writePacketDirect ( OptionalErrorCode ec = throws())
Parameters
echolder for the error code

◆ writeTrailer()

void av::FormatContext::writeTrailer ( OptionalErrorCode ec = throws())

Without it a file can be unplayable even though its size looks plausible: the index is written here.

Parameters
echolder for the error code
Examples
api2-decode-encode-audio.cpp, api2-decode-encode-video.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, api2-generate-subtitles.cpp, api2-hw-encode.cpp, api2-hw-scale.cpp, api2-hw-transcode.cpp, api2-remux.cpp, and api2-scale-video.cpp.

◆ writeUncodedFrame() [1/2]

void av::FormatContext::writeUncodedFrame ( class AudioSamples & frame,
size_t streamIndex,
OptionalErrorCode ec = throws() )
Parameters
framethe samples to write
streamIndexindex of the output stream
echolder for the error code

◆ writeUncodedFrame() [2/2]

void av::FormatContext::writeUncodedFrame ( class VideoFrame & frame,
size_t streamIndex,
OptionalErrorCode ec = throws() )

Only formats that accept raw video take this path; check it with checkUncodedFrameWriting() first.

Parameters
framethe frame to write; the muxer may reference it
streamIndexindex of the output stream
echolder for the error code

◆ writeUncodedFrameDirect() [1/2]

void av::FormatContext::writeUncodedFrameDirect ( class AudioSamples & frame,
size_t streamIndex,
OptionalErrorCode ec = throws() )
Parameters
framethe samples to write
streamIndexindex of the output stream
echolder for the error code

◆ writeUncodedFrameDirect() [2/2]

void av::FormatContext::writeUncodedFrameDirect ( class VideoFrame & frame,
size_t streamIndex,
OptionalErrorCode ec = throws() )
Parameters
framethe frame to write
streamIndexindex of the output stream
echolder for the error code

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