28#include <libavcodec/avcodec.h>
29#include <libavutil/mem.h>
34namespace codec_context::audio {
35void set_channels(AVCodecContext *obj,
int channels);
36void set_channel_layout_mask(AVCodecContext *obj, uint64_t mask);
37int get_channels(
const AVCodecContext *obj);
38uint64_t get_channel_layout_mask(
const AVCodecContext *obj);
41namespace codec_context::internal {
42const int *get_supported_samplerates(
const struct AVCodec *codec);
63class CodecContext2 :
public FFWrapperPtr<AVCodecContext>,
public noncopyable
70 void swap(CodecContext2 &other);
80 using BaseWrapper::BaseWrapper;
135 AVMediaType
codecType(AVMediaType contextType)
const noexcept;
206 [[deprecated(
"Start from FFmpeg 4.0 it is recommended to destroy and recreate codec context insted of close")]]
263#if AVCPP_NEW_CODEC_API
272 bool isEof() const noexcept {
return m_eof; }
283 avcodec_flush_buffers(
m_raw);
288#if AVCPP_HAS_AVFORMAT
524 std::pair<
int, const
std::error_category*>
537 int (*decodeProc)(AVCodecContext*, AVFrame*,
int *, const AVPacket *)) noexcept;
539 std::pair<
int, const
std::error_category*>
551 int (*encodeProc)(AVCodecContext*, AVPacket*,const AVFrame*,
int*)) noexcept;
553#if AVCPP_NEW_CODEC_API
611 std::pair<int, const std::error_category*>
624 const class Packet &inPacket,
627 int (*decodeProc)(AVCodecContext *, AVFrame *,
int *,
const AVPacket *));
630 std::pair<int, const std::error_category*>
644 int (*encodeProc)(AVCodecContext *, AVPacket *,
const AVFrame *,
int *));
646#if AVCPP_NEW_CODEC_API
671#if AVCPP_HAS_AVFORMAT
675#if AVCPP_NEW_CODEC_API
699#if AVCPP_HAS_AVFORMAT
742template<typename Clazz,
Direction _direction, AVMediaType _type>
756 return static_cast<Clazz&
>(*this);
757 Clazz(std::forward<Clazz>(rhs)).swap(
static_cast<Clazz&
>(*
this));
758 return static_cast<Clazz&
>(*this);
776#if AVCPP_HAS_AVFORMAT
784 : CodecContext2(st,
codec, _direction, _type)
796 : CodecContext2(
codec, _direction, _type)
850#if AVCPP_NEW_CODEC_API
867 if constexpr (_type == AVMEDIA_TYPE_SUBTITLE) {
868 throws_if(ec, Errors::CodecUnsupportedOperation);
884 ret = avcodec_send_packet(
m_raw,
nullptr);
886 ret = avcodec_send_frame(
m_raw,
nullptr);
889 if (ret == AVERROR(EAGAIN)) {
893 if (ret == AVERROR_EOF) {
915template<
typename Clazz, Direction _direction>
921 using Parent::Parent;
1022 return RAW_GET(sample_aspect_ratio, AVRational());
1038 m_raw->coded_width = w;
1054 m_raw->coded_height = h;
1101 if (quality < 0 || quality > FF_LAMBDA_MAX)
1102 quality = FF_LAMBDA_MAX;
1148 using Parent::moveOperator;
1149 using Parent::m_raw;
1202 bool autoAllocateFrame =
true);
1219 size_t &decodedBytes,
1221 bool autoAllocateFrame =
true);
1224#if AVCPP_NEW_CODEC_API
1324 size_t *decodedBytes,
1325 bool autoAllocateFrame);
1391#if AVCPP_NEW_CODEC_API
1479 hw::EncodingMode mode = hw::EncodingMode::Auto,
1531template<typename Clazz,
Direction _direction>
1537 using Parent::Parent;
1561 return codec_context::audio::get_channels(
m_raw);
1583 return codec_context::audio::get_channel_layout_mask(
m_raw);
1586#if AVCPP_API_NEW_CHANNEL_LAYOUT
1614#if AVCPP_CXX_STANDARD >= 20
1621 fflog(AV_LOG_INFO,
"Guess sample rate %d instead unsupported %d\n", sr,
sampleRate);
1624 m_raw->sample_rate = sr;
1657 if (!
isValid() || layout == 0)
1659 codec_context::audio::set_channel_layout_mask(
m_raw, layout);
1662#if AVCPP_API_NEW_CHANNEL_LAYOUT
1672 if (!
isValid() || !layout.isValid())
1674 m_raw->ch_layout = *layout.raw();
1680 using Parent::moveOperator;
1681 using Parent::m_raw;
1741#if AVCPP_NEW_CODEC_API
1835#if AVCPP_NEW_CODEC_API
1876template<
typename Clazz, Direction _direction>
1884 using Parent::Parent;
1893 if (!this->
m_raw || !this->
m_raw->subtitle_header || this->m_raw->subtitle_header_size <= 0)
1896 return {
reinterpret_cast<const char*
>(this->
m_raw->subtitle_header),
1897 static_cast<std::size_t
>(this->
m_raw->subtitle_header_size) };
1916 throws_if(ec, Errors::CodecAlreadyOpened);
1920 std::unique_ptr<uint8_t, void(*)(
void*)> copy(
nullptr, av_free);
1921 if (!header.empty()) {
1927 std::memcpy(copy.get(), header.data(), header.size());
1931 this->
m_raw->subtitle_header = copy.release();
1932 this->
m_raw->subtitle_header_size =
static_cast<int>(header.size());
1954 this->
m_raw->subtitle_header_size = 0;
1976 this->
m_raw->pkt_timebase = value;
2056#if AVCPP_NEW_CODEC_API
2111#if AVCPP_NEW_CODEC_API
FFmpeg version and API compatibility switches.
Error codes, error categories and the OptionalErrorCode convention.
Bridge to the FFmpeg logging system.
#define fflog(level, format,...)
Default in-class logger.
Definition avlog.h:41
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
Audio-specific parameters shared by audio encoders and decoders.
Definition codeccontext.h:1533
void setChannelLayout(ChannelLayout layout) noexcept
Set the channel layout from a structured value.
Definition codeccontext.h:1670
void setChannels(int channels) noexcept
Set the channel count.
Definition codeccontext.h:1632
uint64_t channelLayout() const noexcept
Channel layout as a bit mask.
Definition codeccontext.h:1579
CodecContextBase< Clazz, _direction, AVMEDIA_TYPE_AUDIO > Parent
The base class this context derives from.
Definition codeccontext.h:1536
SampleFormat sampleFormat() const noexcept
Sample format of the context.
Definition codeccontext.h:1569
void setChannelLayout(uint64_t layout) noexcept
Set the channel layout as a bit mask.
Definition codeccontext.h:1655
int channels() const noexcept
Number of audio channels.
Definition codeccontext.h:1557
void setSampleRate(int sampleRate) noexcept
Set the sample rate.
Definition codeccontext.h:1610
void setSampleFormat(SampleFormat sampleFormat) noexcept
Set the sample format.
Definition codeccontext.h:1645
int sampleRate() const noexcept
Sample rate of the context.
Definition codeccontext.h:1547
ChannelLayoutView channelLayout2() const noexcept
Channel layout as a structured view.
Definition codeccontext.h:1594
AudioDecoderContext(AudioDecoderContext &&other)
Move the decoder.
AudioCodecContext< AudioDecoderContext, Direction::Decoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:1697
bool send(const Packet &packet, OptionalErrorCode ec=throws())
Sends a packet to the decoder.
AudioSamples decode(const Packet &inPacket, OptionalErrorCode ec=throws())
Decode one audio packet.
AudioSamples receive(OptionalErrorCode ec=throws())
Receives one decoded audio buffer.
AudioDecoderContext & operator=(AudioDecoderContext &&other)
Move assignment.
AudioDecoderContext()=default
Create an empty decoder; set a codec and open() it later.
AudioSamples decode(const Packet &inPacket, size_t offset, OptionalErrorCode ec=throws())
Decode one audio packet starting at a byte offset.
Packet encode(OptionalErrorCode ec=throws())
Drain the encoder.
AudioCodecContext< AudioEncoderContext, Direction::Encoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:1787
bool send(const AudioSamples &samples, OptionalErrorCode ec=throws())
Sends audio samples to the encoder.
AudioEncoderContext & operator=(AudioEncoderContext &&other)
Move assignment.
AudioEncoderContext()=default
Create an empty encoder; set a codec and open() it later.
Packet receive(OptionalErrorCode ec=throws())
Receives one encoded packet.
Packet encode(const AudioSamples &inSamples, OptionalErrorCode ec=throws())
Encode one buffer of samples.
AudioEncoderContext(AudioEncoderContext &&other)
Move the encoder.
One buffer of decoded audio samples.
Definition frame.h:892
Non-owning view of an AVChannelLayout.
Definition channellayout.h:68
Owning channel layout.
Definition channellayout.h:240
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 isValidForEncode(Direction direction, AVMediaType type) const noexcept
Whether the configured codec can encode the given media type.
Codec codec() const noexcept
The codec in use.
hw::DeviceContext m_hwDevice
Device attached by setHwDeviceContext() or configureHwEncoding().
Definition codeccontext.h:506
CodecContext2(const class Stream &st, const class Codec &codec, Direction direction, AVMediaType type)
Create a context attached to a stream.
bool isValid() const noexcept
Whether the context owns an FFmpeg codec context.
int64_t bitRate() const noexcept
Target bit rate.
std::error_code sendCommon(const AVFrame *frame)
Submit a frame to an encoder.
void _log(int level, const char *fmt) const
Log through the FFmpeg log system, using this wrapper as the context.
Definition ffmpeg.h:85
void clearFlags(int flags) noexcept
Remove AV_CODEC_FLAG_* flags.
std::error_code receiveCommon(AVFrame *frame)
Read one frame from a decode context.
AVMediaType codecType(AVMediaType contextType) const noexcept
Map a context media type to the effective media type.
void open(class Dictionary &&options, const Codec &codec, OptionalErrorCode ec=throws())
Open an explicitly chosen codec with options, moving the dictionary.
void open(class Dictionary &options, const Codec &codec, OptionalErrorCode ec=throws())
Open an explicitly chosen codec with options.
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.
void addFlags2(int flags) noexcept
Add AV_CODEC_FLAG2_* flags.
void setFrameRate(const Rational &value) noexcept
Set the frame rate.
std::error_code sendCommon(const class Packet &pkt)
Submit a packet to a decoder.
Rational frameRate() const noexcept
Frame rate advertised by the codec.
bool send(const Packet &packet, OptionalErrorCode ec=throws())
Submit a packet to a decoder.
void setOption(const std::string &key, const std::string &val, OptionalErrorCode ec=throws())
Set a private codec option.
hw::EncodingMode m_hwEncodingMode
How the encoder receives hardware frames.
Definition codeccontext.h:522
hw::FramesContext m_hwFrames
Pool attached by setHwFramesContext() or configureHwEncoding().
Definition codeccontext.h:510
bool checkCodec(const Codec &codec, Direction direction, AVMediaType type, OptionalErrorCode ec)
Validate a codec against a direction and media type, reporting the reason.
Rational timeBase() const noexcept
Time base of the codec.
void open(class Dictionary &options, OptionalErrorCode ec=throws())
Open the codec with options.
void setBitRate(int64_t bitRate) noexcept
Set the target bit rate.
CodecContext2(const class Codec &codec, Direction direction, AVMediaType type)
Create a context for a codec without a stream.
int64_t frameNumber() const noexcept
Counter of frames passed through the context.
std::error_code receiveCommon(class Packet &pkt)
Read one packet from an encode context.
void swap(CodecContext2 &other)
Exchange the state of two contexts.
FFWrapperPtr< AVCodecContext > BaseWrapper
/// The reference-counting wrapper this context builds on.
Definition codeccontext.h:79
bool isOpened() const noexcept
Whether the codec has been opened.
void flushBuffers() noexcept
Resets the codec internal state and the end-of-stream flag.
Definition codeccontext.h:280
int flags() noexcept
Current AV_CODEC_FLAG_* mask.
void setBitRateRange(const std::pair< int64_t, int64_t > &bitRateRange) noexcept
Set the allowed bit rate range.
void copyContextFrom(const CodecContext2 &other, OptionalErrorCode ec=throws())
Copy codec context from codec context associated with given stream or other codec context.
std::error_code sendCommon(const T &frame)
Submit a typed frame to an encoder.
std::error_code receiveCommon(T &frame)
Read one typed output object from a decode context.
bool isFlags2(int flags) noexcept
Whether all given flags are set.
const Stream & stream() const noexcept
The stream this context is attached to.
void open(OptionalErrorCode ec=throws())
Open the codec with the parameters set so far.
bool isRefCountedFrames() const noexcept
Whether the codec hands out reference-counted frames.
std::pair< int64_t, int64_t > bitRateRange() const noexcept
Allowed bit rate range.
bool isEof() const noexcept
Returns true if the codec has been flushed and all output is drained.
Definition codeccontext.h:272
int strict() const noexcept
Current strictness level of the codec.
bool isFlags(int flags) noexcept
Whether all given flags are set.
bool m_hwTransferToSystem
Whether decoded hardware frames are copied to system memory automatically.
Definition codeccontext.h:514
void setFlags2(int flags) noexcept
Access to CODEC_FLAG2_* flags.
bool m_hwAutoUpload
Whether software frames are uploaded into the pool before encoding.
Definition codeccontext.h:518
void setStrict(int strict) noexcept
Set the strictness level.
void open(const Codec &codec, OptionalErrorCode ec=throws())
Open the codec, choosing it explicitly.
void setRefCountedFrames(bool refcounted) const noexcept
Ask the codec for reference-counted frames.
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.
void addFlags(int flags) noexcept
Add AV_CODEC_FLAG_* flags.
void setTimeBase(const Rational &value) noexcept
Set the time base.
int frameSize() const noexcept
Number of samples per frame the codec works with.
void clearFlags2(int flags) noexcept
Remove AV_CODEC_FLAG2_* flags.
void open(class Dictionary &&options, OptionalErrorCode ec=throws())
Open the codec with options, taking ownership of the dictionary.
void close(OptionalErrorCode ec=throws())
Close the codec context.
void setFlags(int flags) noexcept
Access to CODEC_FLAG_* flags.
int flags2() noexcept
Current AV_CODEC_FLAG2_* mask.
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.
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.
Packet receive(OptionalErrorCode ec=throws())
Read one decoded packet from an encoder.
void _log(int level, const char *fmt) const
CodecContextBase(const class Stream &st, const class Codec &codec=Codec())
Create a context attached to a stream.
Definition codeccontext.h:783
CodecContextBase()
Create an empty context of this direction and media type.
Definition codeccontext.h:770
void setCodec(const Codec &codec, OptionalErrorCode ec=throws())
Choose the codec without resetting its defaults.
Definition codeccontext.h:822
bool flush(OptionalErrorCode ec=throws())
Puts the codec into draining mode.
Definition codeccontext.h:863
void setCodec(const Codec &codec, bool resetDefaults, OptionalErrorCode ec=throws())
Choose the codec.
Definition codeccontext.h:835
CodecContextBase(CodecContextBase &&other)
Move the context.
Definition codeccontext.h:808
CodecContextBase(const Codec &codec)
Create a context for a codec, without a stream.
Definition codeccontext.h:795
Clazz & moveOperator(Clazz &&rhs)
Move-assign the derived object and return it.
Definition codeccontext.h:753
AVMediaType codecType() const noexcept
The media type of this context.
Definition codeccontext.h:845
Codec descriptor.
Definition codec.h:32
Implements interface to access to the AVDictionary entity.
Definition dictionary.h:38
AVMediaType codecType() const noexcept
The media type of the attached stream or codec.
GenericCodecContext & operator=(GenericCodecContext &&rhs)
Move assignment.
GenericCodecContext(Stream st)
Attach the context to a stream without a direction.
GenericCodecContext(GenericCodecContext &&other)
Move the context.
GenericCodecContext()=default
Create an empty context; no codec and no stream.
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
Compressed data and its metadata.
Definition packet.h:110
Rational number: a numerator and a denominator.
Definition rational.h:49
One stream inside a container.
Definition stream.h:34
Base class for subtitle codec contexts.
Definition codeccontext.h:1878
void setPktTimeBase(const Rational &value) noexcept
Set the time base used to fill AVSubtitle::pts.
Definition codeccontext.h:1973
void setSubtitleHeader(std::string_view header, OptionalErrorCode ec=throws())
Sets the subtitle header.
Definition codeccontext.h:1906
void setDefaultSubtitleHeader(OptionalErrorCode ec=throws())
Sets the built-in ASS header accepted by every text subtitle encoder provided by FFmpeg.
Definition codeccontext.h:1940
bool flush(OptionalErrorCode ec=throws())=delete
Removing the flush is deliberate: subtitle codecs do not support the send/receive API,...
std::string_view subtitleHeader() const noexcept
Subtitle header in ASS/SSA format, or an empty view when no header has been set.
Definition codeccontext.h:1891
Rational pktTimeBase() const noexcept
Time base used by the decoder to fill AVSubtitle::pts.
Definition codeccontext.h:1962
CodecContextBase< Clazz, _direction, AVMEDIA_TYPE_SUBTITLE > Parent
/// The base class this context derives from.
Definition codeccontext.h:1883
void clearSubtitleHeader() noexcept
Releases the subtitle header.
Definition codeccontext.h:1948
SubtitleCodecContext< SubtitleDecoderContext, Direction::Decoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:2002
SubtitleDecoderContext(SubtitleDecoderContext &&other)
Move the decoder.
SubtitleDecoderContext()=default
Create an empty decoder; set a codec and open() it later.
SubtitleFrame decode(const Packet &packet, OptionalErrorCode ec=throws())
Decodes one subtitle packet.
SubtitleFrame decode(const Packet &packet, size_t offset, size_t &decodedBytes, OptionalErrorCode ec=throws())
Decodes one subtitle packet starting at the given offset.
SubtitleDecoderContext & operator=(SubtitleDecoderContext &&other)
Move assignment.
SubtitleEncoderContext()=default
Create an empty encoder; set a codec and open() it later.
SubtitleEncoderContext(SubtitleEncoderContext &&other)
Move the encoder.
Packet encode(const SubtitleFrame &frame, OptionalErrorCode ec=throws())
Encodes one subtitle frame.
SubtitleEncoderContext & operator=(SubtitleEncoderContext &&other)
Move assignment.
SubtitleCodecContext< SubtitleEncoderContext, Direction::Encoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:2075
Owning, move-only subtitle frame.
Definition subtitle.h:274
Video-specific parameters shared by video encoders and decoders.
Definition codeccontext.h:917
int bitRateTolerance() const
How far the encoder may deviate from the target bit rate.
Definition codeccontext.h:1000
void setGopSize(int32_t size)
Set the distance between key frames.
Definition codeccontext.h:1112
void setCodedHeight(int h)
Set the coded height independently of the display height.
Definition codeccontext.h:1077
int height() const
Frame height stored in the context.
Definition codeccontext.h:940
void setGlobalQuality(int32_t quality)
Set the global quality for constant-quality encoders.
Definition codeccontext.h:1099
void setPixelFormat(PixelFormat pixelFormat)
Set the pixel format.
Definition codeccontext.h:1088
PixelFormat pixelFormat() const
Pixel format the codec works with.
Definition codeccontext.h:970
int codedHeight() const
Height as coded by the bitstream, before any cropping.
Definition codeccontext.h:960
void setCodedWidth(int w)
Set the coded width independently of the display width.
Definition codeccontext.h:1065
int codedWidth() const
Width as coded by the bitstream, before any cropping.
Definition codeccontext.h:950
void setSampleAspectRatio(const Rational &sampleAspectRatio)
Set the pixel aspect ratio.
Definition codeccontext.h:1142
CodecContextBase< Clazz, _direction, AVMEDIA_TYPE_VIDEO > Parent
The base class this context derives from.
Definition codeccontext.h:920
void setWidth(int w)
Set the frame width.
Definition codeccontext.h:1033
void setBitRateTolerance(int bitRateTolerance)
Set how far the encoder may deviate from the target bit rate.
Definition codeccontext.h:1122
void setMaxBFrames(int maxBFrames)
Limit the number of B-frames.
Definition codeccontext.h:1132
int maxBFrames() const
Maximum number of B-frames the encoder may use.
Definition codeccontext.h:1010
void setHeight(int h)
Set the frame height.
Definition codeccontext.h:1049
int32_t globalQuality() const
Global quality value used by constant-quality encoders.
Definition codeccontext.h:980
Rational sampleAspectRatio() const
Pixel aspect ratio of the frames.
Definition codeccontext.h:1020
int32_t gopSize() const
Distance between key frames.
Definition codeccontext.h:990
int width() const
Frame width stored in the context.
Definition codeccontext.h:930
bool isHwTransferToSystem() const noexcept
Whether decoded hardware frames are transferred to system memory.
VideoFrame decode(const Packet &packet, size_t offset, size_t &decodedBytes, OptionalErrorCode ec=throws(), bool autoAllocateFrame=true)
decodeVideo - decode video packet with additional parameters
VideoDecoderContext()=default
Create an empty decoder; set a codec and open() it later.
void clearHwDeviceContext() noexcept
Removes the hardware device and restores the default get_format().
VideoCodecContext< VideoDecoderContext, Direction::Decoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:1166
hw::DeviceContext hwDeviceContext() const noexcept
Device context set with setHwDeviceContext().
bool send(const Packet &packet, OptionalErrorCode ec=throws())
Sends a packet to the decoder.
VideoFrame receive(OptionalErrorCode ec=throws(), bool autoAllocateFrame=true)
Receives one decoded frame.
VideoDecoderContext(VideoDecoderContext &&other)
Move the decoder.
void setHwDeviceContext(const hw::DeviceContext &device, OptionalErrorCode ec=throws())
Configures a hardware device for decoding.
hw::FramesContext hwFramesContext() const noexcept
Frames context of decoded hardware frames.
VideoFrame decode(const Packet &packet, OptionalErrorCode ec=throws(), bool autoAllocateFrame=true)
decodeVideo - decode video packet
void setHwTransferToSystem(bool enabled) noexcept
Transfer decoded hardware frames to system memory automatically.
VideoDecoderContext & operator=(VideoDecoderContext &&other)
Move assignment.
hw::DeviceContext hwDeviceContext() const noexcept
Device configured for this encoder.
VideoCodecContext< VideoEncoderContext, Direction::Encoding > Parent
/// The base class this context derives from.
Definition codeccontext.h:1343
Packet encode(const VideoFrame &inFrame, OptionalErrorCode ec=throws())
encodeVideo - encode video frame
VideoEncoderContext(VideoEncoderContext &&other)
Move the encoder.
void setHwDeviceContext(const hw::DeviceContext &device, OptionalErrorCode ec=throws())
Sets AVCodecContext::hw_device_ctx before open().
VideoEncoderContext & operator=(VideoEncoderContext &&other)
Move assignment.
Packet encode(OptionalErrorCode ec=throws())
encodeVideo - Flush encoder
void configureHwEncoding(const hw::DeviceContext &device, hw::EncodingMode mode=hw::EncodingMode::Auto, PixelFormat swFormat=AV_PIX_FMT_NONE, OptionalErrorCode ec=throws())
Configures hardware encoding for the given device.
bool isHwEncoding() const noexcept
Whether hardware encoding is configured.
void setHwAutoUpload(bool enabled) noexcept
Upload software frames automatically before encoding.
void clearHwDeviceContext() noexcept
Removes the hardware device context.
hw::FramesContext hwFramesContext() const noexcept
Frames context configured for this encoder.
VideoEncoderContext()=default
Create an empty encoder; set a codec and open() it later.
void clearHwFramesContext() noexcept
Removes the hardware frames context.
Packet receive(OptionalErrorCode ec=throws())
Receives one encoded packet.
bool send(const VideoFrame &frame, OptionalErrorCode ec=throws())
Sends a frame to the encoder.
hw::EncodingMode hwEncodingMode() const noexcept
How the encoder receives hardware frames.
void setHwFramesContext(const hw::FramesContext &frames, OptionalErrorCode ec=throws())
Sets AVCodecContext::hw_frames_ctx before open().
bool isHwAutoUpload() const noexcept
Whether software frames are uploaded automatically.
One video frame.
Definition frame.h:578
Owner of an AVHWDeviceContext.
Definition hwcontext.h:126
Codec descriptors and lookup by name or id.
FFmpeg types re-exported for the public API and small value wrappers.
#define RAW_GET(field, def)
Read an AVCodecContext-style field through a possibly empty raw pointer.
Definition ffmpeg.h:114
#define RAW_SET(field, val)
Write an AVCodecContext-style field when the raw pointer is set.
Definition ffmpeg.h:121
#define RAW_GET2(cond, field, def)
Read a field when the pointer is set and a condition holds.
Definition ffmpeg.h:130
#define RAW_SET2(cond, field, val)
Write a field when the pointer is set and a condition holds.
Definition ffmpeg.h:138
Video frames, audio samples and their common frame interface.
Hardware devices, hardware frames and hardware codec configuration.
Root namespace of the library.
Definition audioresampler.h:19
void clear_if(OptionalErrorCode ec)
clear_if - clear error code if it is not av::throws()
Definition averror.h:368
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition averror.h:310
Direction
Direction a codec or a stream is used in.
Definition codecparameters.h:29
@ Invalid
Not a direction; the default state of a context that has none.
Definition codecparameters.h:31
@ Decoding
Decompressing packets into frames.
Definition codecparameters.h:35
std::error_code make_error_code(av::Errors errc) noexcept
Build an error code from an avcpp error.
Definition averror.h:223
std::unique_ptr< T, void(*)(void *)> mallocz(size_t size)
Allocate zeroed memory with the FFmpeg allocator.
Definition avutils.h:326
void freep(T *&ptr) noexcept
Frees a buffer allocated by the FFmpeg allocator and resets the pointer.
Definition avutils.h:367
FfmpegCategory & ffmpeg_category()
Error category that wraps FFmpeg return codes.
Definition averror.h:196
auto make_array_view_until(auto *ptr, auto value)
Helper to create array view with end marker.
Definition avutils.h:927
void throws_if(OptionalErrorCode ec, int errcode, const Category &cat)
Throw or store an error, depending on what the caller passed.
Definition averror.h:323
T guessValue(const T &value, L list)
Select more approptiate value from given value list.
Definition avutils.h:951
Streams inside a container: parameters, time base and disposition.
void _log(int level, const char *fmt) const
Definition ffmpeg.h:85
AVCodecContext * m_raw
Definition ffmpeg.h:105
Predicate that compares an element with a stored value.
Definition avutils.h:979
Subtitle frames: text and ASS payloads, bitmap rectangles.
std::string_view defaultAssHeader() noexcept
Returns a built-in ASS/SSA script header accepted by the FFmpeg text subtitle encoders (subrip,...