|
avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Base class for audio and video codec contexts. More...
#include <codeccontext.h>
Public Member Functions | |
| void | open (OptionalErrorCode ec=throws()) |
| Open the codec with the parameters set so far. | |
| void | open (const Codec &codec, OptionalErrorCode ec=throws()) |
| Open the codec, choosing it explicitly. | |
| void | open (class Dictionary &options, OptionalErrorCode ec=throws()) |
| Open the codec with options. | |
| void | open (class Dictionary &&options, OptionalErrorCode ec=throws()) |
| Open the codec with options, taking ownership of the dictionary. | |
| void | open (class Dictionary &options, const Codec &codec, OptionalErrorCode ec=throws()) |
| Open an explicitly chosen codec with options. | |
| void | open (class Dictionary &&options, const Codec &codec, OptionalErrorCode ec=throws()) |
| Open an explicitly chosen codec with options, moving the dictionary. | |
| void | close (OptionalErrorCode ec=throws()) |
| Close the codec context. | |
| bool | isOpened () const noexcept |
| Whether the codec has been opened. | |
| bool | isValid () const noexcept |
| Whether the context owns an FFmpeg codec context. | |
| Rational | timeBase () const noexcept |
| Time base of the codec. | |
| void | setTimeBase (const Rational &value) noexcept |
| Set the time base. | |
| Rational | frameRate () const noexcept |
| Frame rate advertised by the codec. | |
| void | setFrameRate (const Rational &value) noexcept |
| Set the frame rate. | |
| bool | isEof () const noexcept |
| Returns true if the codec has been flushed and all output is drained. | |
| void | flushBuffers () noexcept |
| Resets the codec internal state and the end-of-stream flag. | |
| const Stream & | stream () const noexcept |
| The stream this context is attached to. | |
| Codec | codec () const noexcept |
| The codec in use. | |
| void | setOption (const std::string &key, const std::string &val, OptionalErrorCode ec=throws()) |
| Set a private codec option. | |
| void | setOption (const std::string &key, const std::string &val, int flags, OptionalErrorCode ec=throws()) |
| Set a private codec option with AVDictionary flags. | |
| int | frameSize () const noexcept |
| Number of samples per frame the codec works with. | |
| int64_t | frameNumber () const noexcept |
| Counter of frames passed through the context. | |
| bool | isRefCountedFrames () const noexcept |
| Whether the codec hands out reference-counted frames. | |
| void | setRefCountedFrames (bool refcounted) const noexcept |
| Ask the codec for reference-counted frames. | |
| int | strict () const noexcept |
| Current strictness level of the codec. | |
| void | setStrict (int strict) noexcept |
| Set the strictness level. | |
| int64_t | bitRate () const noexcept |
| Target bit rate. | |
| std::pair< int64_t, int64_t > | bitRateRange () const noexcept |
| Allowed bit rate range. | |
| void | setBitRate (int64_t bitRate) noexcept |
| Set the target bit rate. | |
| void | setBitRateRange (const std::pair< int64_t, int64_t > &bitRateRange) noexcept |
| Set the allowed bit rate range. | |
| template<typename T> | |
| std::pair< int, const std::error_category * > | decodeCommon (T &outFrame, const class Packet &inPacket, size_t offset, int &frameFinished, int(*decodeProc)(AVCodecContext *, AVFrame *, int *, const AVPacket *)) |
| Decode one packet into a typed frame. | |
| template<typename T> | |
| std::pair< int, const std::error_category * > | encodeCommon (class Packet &outPacket, const T &inFrame, int &gotPacket, int(*encodeProc)(AVCodecContext *, AVPacket *, const AVFrame *, int *)) |
| Encode one typed frame into a packet. | |
| bool | send (const Packet &packet, OptionalErrorCode ec=throws()) |
| Submit a packet to a decoder. | |
| Packet | receive (OptionalErrorCode ec=throws()) |
| Read one decoded packet from an encoder. | |
| void | _log (int level, const char *fmt) const |
| Log through the FFmpeg log system, using this wrapper as the context. | |
| void | _log (int level, const char *fmt, const Args &... args) const |
| Log through the FFmpeg log system with arguments. | |
| void | copyContextFrom (const CodecContext2 &other, OptionalErrorCode ec=throws()) |
| Copy codec context from codec context associated with given stream or other codec context. | |
| void | setFlags (int flags) noexcept |
| Access to CODEC_FLAG_* flags. | |
| void | addFlags (int flags) noexcept |
| Add AV_CODEC_FLAG_* flags. | |
| void | clearFlags (int flags) noexcept |
| Remove AV_CODEC_FLAG_* flags. | |
| int | flags () noexcept |
| Current AV_CODEC_FLAG_* mask. | |
| bool | isFlags (int flags) noexcept |
| Whether all given flags are set. | |
| void | setFlags2 (int flags) noexcept |
| Access to CODEC_FLAG2_* flags. | |
| void | addFlags2 (int flags) noexcept |
| Add AV_CODEC_FLAG2_* flags. | |
| void | clearFlags2 (int flags) noexcept |
| Remove AV_CODEC_FLAG2_* flags. | |
| int | flags2 () noexcept |
| Current AV_CODEC_FLAG2_* mask. | |
| bool | isFlags2 (int flags) noexcept |
| Whether all given flags are set. | |
| Public Member Functions inherited from FFWrapperPtr< AVCodecContext > | |
| FFWrapperPtr ()=default | |
| Create an empty wrapper; isNull() is true. | |
| FFWrapperPtr (AVCodecContext *raw) | |
| Wrap an existing object. | |
| const AVCodecContext * | raw () const |
| Read access to the wrapped object. | |
| AVCodecContext * | raw () |
| Write access to the wrapped object. | |
| void | reset (AVCodecContext *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. | |
| void | _log (int level, const char *fmt, const Args &... args) const |
| Log through the FFmpeg log system with arguments. | |
Protected Types | |
| using | BaseWrapper = FFWrapperPtr<AVCodecContext> |
| /// The reference-counting wrapper this context builds on. | |
Protected Member Functions | |
| void | swap (CodecContext2 &other) |
| Exchange the state of two contexts. | |
| CodecContext2 (const class Stream &st, const class Codec &codec, Direction direction, AVMediaType type) | |
| Create a context attached to a stream. | |
| CodecContext2 (const class Codec &codec, Direction direction, AVMediaType type) | |
| Create a context for a codec without a stream. | |
| void | setCodec (const class Codec &codec, bool resetDefaults, Direction direction, AVMediaType type, OptionalErrorCode ec=throws()) |
| Attach a codec and validate it against the direction and media type. | |
| AVMediaType | codecType (AVMediaType contextType) const noexcept |
| Map a context media type to the effective media type. | |
| bool | isValidForEncode (Direction direction, AVMediaType type) const noexcept |
| Whether the configured codec can encode the given media type. | |
| bool | checkCodec (const Codec &codec, Direction direction, AVMediaType type, OptionalErrorCode ec) |
| Validate a codec against a direction and media type, reporting the reason. | |
| void | open (const Codec &codec, AVDictionary **options, OptionalErrorCode ec) |
| Open the codec with raw FFmpeg options. | |
| std::pair< int, const std::error_category * > | decodeCommon (AVFrame *outFrame, const class Packet &inPacket, size_t offset, int &frameFinished, int(*decodeProc)(AVCodecContext *, AVFrame *, int *, const AVPacket *)) noexcept |
| Decode one packet into an FFmpeg frame. | |
| std::pair< int, const std::error_category * > | encodeCommon (class Packet &outPacket, const AVFrame *inFrame, int &gotPacket, int(*encodeProc)(AVCodecContext *, AVPacket *, const AVFrame *, int *)) noexcept |
| Encode one typed frame into a packet. | |
| std::error_code | sendCommon (const class Packet &pkt) |
| Submit a packet to a decoder. | |
| std::error_code | receiveCommon (AVFrame *frame) |
| Read one frame from a decode context. | |
| template<typename T> | |
| std::error_code | receiveCommon (T &frame) |
| Read one typed output object from a decode context. | |
| std::error_code | sendCommon (const AVFrame *frame) |
| Submit a frame to an encoder. | |
| std::error_code | receiveCommon (class Packet &pkt) |
| Read one packet from an encode context. | |
| template<typename T> | |
| std::error_code | sendCommon (const T &frame) |
| Submit a typed frame to an encoder. | |
| Protected Member Functions inherited from av::noncopyable | |
| noncopyable (const noncopyable &)=delete | |
| void | operator= (const noncopyable &)=delete |
Protected Attributes | |
| hw::DeviceContext | m_hwDevice |
| Device attached by setHwDeviceContext() or configureHwEncoding(). | |
| hw::FramesContext | m_hwFrames |
| Pool attached by setHwFramesContext() or configureHwEncoding(). | |
| bool | m_hwTransferToSystem = false |
| Whether decoded hardware frames are copied to system memory automatically. | |
| bool | m_hwAutoUpload = true |
| Whether software frames are uploaded into the pool before encoding. | |
| hw::EncodingMode | m_hwEncodingMode = hw::EncodingMode::Auto |
| How the encoder receives hardware frames. | |
| Protected Attributes inherited from FFWrapperPtr< AVCodecContext > | |
| AVCodecContext * | m_raw |
| The wrapped pointer; owned by the derived class, not by this template. | |
|
protected |
Used by the typed subclasses, which know the direction and media type; not part of the public construction path.
| st | |
| codec | |
| direction | |
| type |
|
protected |
Used by the typed subclasses; not part of the public construction path.
| codec | |
| direction | |
| type |
|
inline |
| level | an AV_LOG_* level |
| fmt | printf-style format string without arguments |
|
inline |
| level | an AV_LOG_* level |
| fmt | printf-style format string |
| args | arguments for the format string |
|
noexcept |
| flags | flags to set |
|
noexcept |
| flags | flags to set |
|
noexcept |
|
noexcept |
|
protected |
| codec | |
| direction | |
| type | |
| ec |
|
noexcept |
| flags | flags to clear |
|
noexcept |
| flags | flags to clear |
| void av::CodecContext2::close | ( | OptionalErrorCode | ec = throws() | ) |
| ec | holder for the error code; when it is not throws() an error is reported through it instead of an exception |
|
noexcept |
|
protectednoexcept |
Codec contexts can be created for a media type that the codec overrides; this resolves the final value.
| contextType |
| void av::CodecContext2::copyContextFrom | ( | const CodecContext2 & | other, |
| OptionalErrorCode | ec = throws() ) |
This functionality useful for remuxing without deconding/encoding. In this case you need not open codecs, only copy context.
| other | stream or codec context |
| ec | holder for the error code |
|
protectednoexcept |
The typed contexts wrap this and convert the result.
| outFrame | |
| inPacket | |
| offset | |
| frameFinished | |
| decodeProc |
| std::pair< int, const std::error_category * > av::CodecContext2::decodeCommon | ( | T & | outFrame, |
| const class Packet & | inPacket, | ||
| size_t | offset, | ||
| int & | frameFinished, | ||
| int(* | decodeProc )(AVCodecContext *, AVFrame *, int *, const AVPacket *) ) |
Shared implementation of the public decode() overloads.
| outFrame | |
| inPacket | |
| offset | |
| frameFinished | |
| decodeProc |
|
protectednoexcept |
Shared implementation of the public encode() overloads.
| outPacket | |
| inFrame | |
| gotPacket | |
| encodeProc |
| std::pair< int, const std::error_category * > av::CodecContext2::encodeCommon | ( | class Packet & | outPacket, |
| const T & | inFrame, | ||
| int & | gotPacket, | ||
| int(* | encodeProc )(AVCodecContext *, AVPacket *, const AVFrame *, int *) ) |
Shared implementation of the public encode() overloads.
| outPacket | |
| inFrame | |
| gotPacket | |
| encodeProc |
|
noexcept |
|
noexcept |
|
inlinenoexcept |
Wraps avcodec_flush_buffers(). Use it to reuse the context after EOF or to seek back to a key frame.
|
noexcept |
|
noexcept |
Hardware encoders (for example h264_qsv) read this value and need it to be set before open().
|
noexcept |
|
inlinenoexcept |
An empty result of receive() with isEof() == false means that more input is required (EAGAIN), for example during the initial delay of a reordering decoder.
|
noexcept |
| flags | flags to test |
|
noexcept |
| flags | flags to test |
|
noexcept |
|
noexcept |
|
noexcept |
|
protectednoexcept |
Validation helper used by setCodec() and open().
| direction | |
| type |
| void av::CodecContext2::open | ( | class Dictionary && | options, |
| const Codec & | codec, | ||
| OptionalErrorCode | ec = throws() ) |
| options | codec options, moved into the call |
| codec | the codec to open |
| ec | holder for the error code |
| void av::CodecContext2::open | ( | class Dictionary && | options, |
| OptionalErrorCode | ec = throws() ) |
| options | codec options, moved into the call |
| ec | holder for the error code |
| void av::CodecContext2::open | ( | class Dictionary & | options, |
| const Codec & | codec, | ||
| OptionalErrorCode | ec = throws() ) |
| options | codec options; the object stays usable, but FFmpeg removes the options it recognized |
| codec | the codec to open |
| ec | holder for the error code |
| void av::CodecContext2::open | ( | class Dictionary & | options, |
| OptionalErrorCode | ec = throws() ) |
| options | codec options, for example {"threads", "4"}; the dictionary stays usable, but FFmpeg removes the options it recognized |
| ec | holder for the error code |
|
protected |
The public open() overloads convert a Dictionary and call this one.
| codec | |
| options | |
| ec |
| void av::CodecContext2::open | ( | const Codec & | codec, |
| OptionalErrorCode | ec = throws() ) |
| codec | the codec to open; it must match the direction and media type of the context |
| ec | holder for the error code |
| void av::CodecContext2::open | ( | OptionalErrorCode | ec = throws() | ) |
The codec is either the one passed to the constructor or the one set with setCodec(). Everything that has to be known at open time — size, sample rate, time base, hardware device or frames context — must be set before this call.
| ec | holder for the error code; throws() raises av::Exception |
| Packet av::CodecContext2::receive | ( | OptionalErrorCode | ec = throws() | ) |
| ec | holder for the error code |
|
protected |
Shared implementation of receive() for video decoders.
| frame |
|
protected |
Shared implementation of receive() for encoders.
| pkt |
|
protected |
Shared implementation of receive() for the typed decoders.
| frame |
| bool av::CodecContext2::send | ( | const Packet & | packet, |
| OptionalErrorCode | ec = throws() ) |
| packet | the compressed packet |
| ec | holder for the error code |
|
protected |
Shared implementation of send() for video encoders.
| frame |
|
protected |
Shared implementation of send() for decoding contexts.
| pkt |
|
protected |
Shared implementation of send() for the typed encoders.
| frame |
|
noexcept |
| bitRate | bits per second; encoders clamp it to the range they support |
|
noexcept |
| bitRateRange | minimum and maximum in bits per second |
|
protected |
The typed subclasses bind the direction and media type themselves.
| codec | |
| resetDefaults | |
| direction | |
| type | |
| ec |
|
noexcept |
Replace the AV_CODEC_FLAG_* set.
| flags | the new flag mask |
|
noexcept |
Replace the AV_CODEC_FLAG2_* set.
| flags | the new flag mask |
|
noexcept |
| value | frames per second; some encoders (QSV, for one) require it before open(), others use it as a hint |
| void av::CodecContext2::setOption | ( | const std::string & | key, |
| const std::string & | val, | ||
| int | flags, | ||
| OptionalErrorCode | ec = throws() ) |
| key | option name |
| val | option value |
| flags | combination of AV_DICT_* flags, for example AV_DICT_DONT_OVERWRITE |
| ec | holder for the error code |
| void av::CodecContext2::setOption | ( | const std::string & | key, |
| const std::string & | val, | ||
| OptionalErrorCode | ec = throws() ) |
| key | option name, as accepted by ffmpeg -h |
| val | option value |
| ec | holder for the error code; an unknown key reports Errors::InvalidArgument |
|
noexcept |
| refcounted | true makes frame copies cheap and keeps a frame valid after the next decode call, which is required for multithreaded processing |
|
noexcept |
| strict | an FF_COMPLIANCE_* value; higher levels make the codec reject streams that are not fully standard compliant |
|
noexcept |
| value | timestamp units per second; must be set before open() |
|
noexcept |
|
noexcept |
|
protected |
| other |
|
noexcept |