Documentation ¶
Overview ¶
Package avcodec is a wrapper around FFmpeg/release6.1. See: https://github.com/FFmpeg/FFmpeg/tree/release/6.1
Index ¶
- Constants
- func EncoderIsAvailable(enc string) bool
- type Codec
- type Context
- func (ctxt *Context) Close() int
- func (ctxt *Context) FreeContext()
- func (ctxt *Context) Open2(c *Codec, d **Dictionary) int
- func (ctxt *Context) ReceivePacket(a *Packet) int
- func (ctxt *Context) SendFrame(f *Frame) int
- func (ctxt *Context) SetEncodeParams(width, height int, pxlFmt PixelFormat, hasBFrames bool, gopSize int)
- func (ctxt *Context) SetFramerate(fps int)
- type Dictionary
- type Frame
- type Packet
- type PixelFormat
Constants ¶
const AvPixFmtYuv420p = C.AV_PIX_FMT_YUV420P
AvPixFmtYuv420p the pixel format AV_PIX_FMT_YUV420P
Variables ¶
This section is empty.
Functions ¶
func EncoderIsAvailable ¶
EncoderIsAvailable returns true if the given encoder is available, false otherwise.
Types ¶
type Codec ¶
type Codec C.struct_AVCodec
Codec an AVCodec
func FindEncoderByName ¶
FindEncoderByName Find a registered encoder with the specified name.
@param name the name of the requested encoder @return An encoder if one was found, NULL otherwise.
func (*Codec) AllocContext3 ¶
AllocContext3 Allocate an AVCodecContext and set its fields to default values. The resulting struct should be freed with avcodec_free_context().
@param codec if non-NULL, allocate private data and initialize defaults
for the given codec. It is illegal to then call avcodec_open2() with a different codec. If NULL, then the codec-specific defaults won't be initialized, which may result in suboptimal default settings (this is important mainly for encoders, e.g. libx264).
@return An AVCodecContext filled with default values or NULL on failure.
type Context ¶
type Context C.struct_AVCodecContext
Context an AVCodecContext
func (*Context) Close ¶
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself).
Calling this function on an AVCodecContext that hasn't been opened will free the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL codec. Subsequent calls will do nothing.
@note Do not use this function. Use avcodec_free_context() to destroy a codec context (either open or closed). Opening and closing a codec context multiple times is not supported anymore -- use multiple codec contexts instead.
func (*Context) FreeContext ¶ added in v0.18.0
func (ctxt *Context) FreeContext()
FreeContext Free the codec context and everything associated with it and write NULL to the provided pointer.
func (*Context) Open2 ¶
func (ctxt *Context) Open2(c *Codec, d **Dictionary) int
Open2 Initialize the AVCodecContext to use the given AVCodec. Prior to using this function the context has to be allocated with avcodec_alloc_context3().
The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for retrieving a codec.
Depending on the codec, you might need to set options in the codec context also for decoding (e.g. width, height, or the pixel or audio sample format in the case the information is not available in the bitstream, as when decoding raw audio or video).
Options in the codec context can be set either by setting them in the options AVDictionary, or by setting the values in the context itself, directly or by using the av_opt_set() API before calling this function.
Example: @code av_dict_set(&opts, "b", "2.5M", 0); codec = avcodec_find_decoder(AV_CODEC_ID_H264); if (!codec)
exit(1);
context = avcodec_alloc_context3(codec);
if (avcodec_open2(context, codec, opts) < 0)
exit(1);
@endcode
In the case AVCodecParameters are available (e.g. when demuxing a stream using libavformat, and accessing the AVStream contained in the demuxer), the codec parameters can be copied to the codec context using avcodec_parameters_to_context(), as in the following example:
@code AVStream *stream = ...; context = avcodec_alloc_context3(codec); if (avcodec_parameters_to_context(context, stream->codecpar) < 0)
exit(1);
if (avcodec_open2(context, codec, NULL) < 0)
exit(1);
@endcode
@note Always call this function before using decoding routines (such as @ref avcodec_receive_frame()).
@param avctx The context to initialize. @param codec The codec to open this context for. If a non-NULL codec has been
previously passed to avcodec_alloc_context3() or for this context, then this parameter MUST be either NULL or equal to the previously passed codec.
@param options A dictionary filled with AVCodecContext and codec-private
options, which are set on top of the options already set in avctx, can be NULL. On return this object will be filled with options that were not found in the avctx codec context.
@return zero on success, a negative value on error @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context()
func (*Context) ReceivePacket ¶
ReceivePacket Read encoded data from the encoder.
@param avctx codec context @param avpkt This will be set to a reference-counted packet allocated by the
encoder. Note that the function will always call av_packet_unref(avpkt) before doing anything else.
@retval 0 success @retval AVERROR(EAGAIN) output is not available in the current state - user must
try to send input
@retval AVERROR_EOF the encoder has been fully flushed, and there will be no
more output packets
@retval AVERROR(EINVAL) codec not opened, or it is a decoder @retval "another negative error code" legitimate encoding errors
func (*Context) SendFrame ¶
SendFrame Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet() to retrieve buffered output packets.
@param avctx codec context @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
Ownership of the frame remains with the caller, and the encoder will not write to the frame. The encoder may create a reference to the frame data (or copy it if the frame is not reference-counted). It can be NULL, in which case it is considered a flush packet. This signals the end of the stream. If the encoder still has packets buffered, it will return them after this call. Once flushing mode has been entered, additional flush packets are ignored, and sending frames will return AVERROR_EOF. For audio: If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame can have any number of samples. If it is not set, frame->nb_samples must be equal to avctx->frame_size for all frames except the last. The final frame may be smaller than avctx->frame_size.
@retval 0 success @retval AVERROR(EAGAIN) input is not accepted in the current state - user must
read output with avcodec_receive_packet() (once all output is read, the packet should be resent, and the call will not fail with EAGAIN).
@retval AVERROR_EOF the encoder has been flushed, and no new frames can
be sent to it
@retval AVERROR(EINVAL) codec not opened, it is a decoder, or requires flush @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar @retval "another negative error code" legitimate encoding errors
func (*Context) SetEncodeParams ¶
func (ctxt *Context) SetEncodeParams(width, height int, pxlFmt PixelFormat, hasBFrames bool, gopSize int)
SetEncodeParams sets the context's width, height, pixel format (pxlFmt), if it has b-frames and GOP size.
func (*Context) SetFramerate ¶
SetFramerate sets the context's framerate
type Packet ¶
type Packet C.struct_AVPacket
Packet an AVPacket
func PacketAlloc ¶
func PacketAlloc() *Packet
PacketAlloc Allocate an AVPacket and set its fields to default values. The resulting struct must be freed using av_packet_free().
@return An AVPacket filled with default values or NULL on failure.
@note this only allocates the AVPacket itself, not the data buffers. Those must be allocated through other means such as av_new_packet.
@see av_new_packet