63 #define LICENSE_PREFIX "libavcodec license: "
71 for (
i = 0;
i < count;
i++) {
84 for (
i = 0;
i < count;
i++) {
119 switch (
ctx->codec_type) {
128 if (bits_per_sample) {
129 bit_rate =
ctx->sample_rate * (int64_t)
ctx->channels;
130 if (bit_rate > INT64_MAX / bits_per_sample) {
133 bit_rate *= bits_per_sample;
147 int codec_init_ok = 0;
154 if (!codec && !avctx->
codec) {
158 if (codec && avctx->
codec && codec != avctx->
codec) {
160 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
164 codec = avctx->
codec;
181 #if FF_API_OLD_ENCDEC
284 avctx->
codec = codec;
304 "The %s '%s' is experimental but experimental codecs are not enabled, "
305 "add '-strict %d' if you want to use it.\n",
329 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
373 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
374 "ignoring specified channel layout\n",
391 "supported with subtitles codecs\n");
396 "subtitles character encoding will be ignored\n",
407 iconv_t cd = iconv_open(
"UTF-8", avctx->
sub_charenc);
408 if (cd == (iconv_t)-1) {
411 "with input character encoding \"%s\"\n", avctx->
sub_charenc);
417 "conversion needs a libavcodec built with iconv support "
426 #if FF_API_AVCTX_TIMEBASE
445 (codec_init_ok > 0 || (codec_init_ok < 0 &&
457 #if FF_API_CODED_FRAME
470 #if FF_API_OLD_ENCDEC
502 "that doesn't support it\n");
514 #if FF_API_OLD_ENCDEC
543 #if FF_API_OLD_ENCDEC
555 for (
i = 0;
i <
sub->num_rects;
i++) {
567 memset(
sub, 0,
sizeof(*
sub));
588 #if FF_API_OLD_ENCDEC
635 #if FF_API_CODED_FRAME
649 return str ?
str :
"unknown";
655 const char *codec_name;
663 if (!buf || buf_size <= 0)
681 snprintf(buf + strlen(buf), buf_size - strlen(buf),
682 ", %d reference frame%s",
683 enc->
refs, enc->
refs > 1 ?
"s" :
"");
686 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s / 0x%04X)",
692 char detail[256] =
"(";
696 snprintf(buf + strlen(buf), buf_size - strlen(buf),
712 if (strcmp(col, pri) || strcmp(col, trc)) {
721 const char *field_order =
"progressive";
723 field_order =
"top first";
725 field_order =
"bottom first";
727 field_order =
"top coded first (swapped)";
729 field_order =
"bottom coded first (swapped)";
731 av_strlcatf(detail,
sizeof(detail),
"%s, ", field_order);
739 if (strlen(detail) > 1) {
740 detail[strlen(detail) - 2] = 0;
746 av_strlcat(buf, new_line ? separator :
", ", buf_size);
748 snprintf(buf + strlen(buf), buf_size - strlen(buf),
755 snprintf(buf + strlen(buf), buf_size - strlen(buf),
763 snprintf(buf + strlen(buf), buf_size - strlen(buf),
764 " [SAR %d:%d DAR %d:%d]",
766 display_aspect_ratio.
num, display_aspect_ratio.
den);
770 snprintf(buf + strlen(buf), buf_size - strlen(buf),
776 snprintf(buf + strlen(buf), buf_size - strlen(buf),
780 snprintf(buf + strlen(buf), buf_size - strlen(buf),
781 ", Closed Captions");
783 snprintf(buf + strlen(buf), buf_size - strlen(buf),
791 snprintf(buf + strlen(buf), buf_size - strlen(buf),
797 snprintf(buf + strlen(buf), buf_size - strlen(buf),
802 snprintf(buf + strlen(buf), buf_size - strlen(buf),
806 snprintf(buf + strlen(buf), buf_size - strlen(buf),
809 snprintf(buf + strlen(buf), buf_size - strlen(buf),
817 snprintf(buf + strlen(buf), buf_size - strlen(buf),
824 snprintf(buf + strlen(buf), buf_size - strlen(buf),
832 snprintf(buf + strlen(buf), buf_size - strlen(buf),
835 snprintf(buf + strlen(buf), buf_size - strlen(buf),
840 snprintf(buf + strlen(buf), buf_size - strlen(buf),
841 ", %"PRId64
" kb/s",
bitrate / 1000);
843 snprintf(buf + strlen(buf), buf_size - strlen(buf),
850 return !!
s->internal;
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void lock_avcodec(const AVCodec *codec)
int avcodec_default_execute2(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr), void *arg, int *ret, int count)
static void unlock_avcodec(const AVCodec *codec)
static const char * unknown_if_null(const char *str)
static AVMutex codec_mutex
const char av_codec_ffversion[]
static int64_t get_bit_rate(AVCodecContext *ctx)
Libavcodec external API header.
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define FF_THREAD_FRAME
Decode more than one frame at once.
#define FF_SUB_CHARENC_MODE_DO_NOTHING
do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for inst...
#define FF_CODEC_PROPERTY_LOSSLESS
#define FF_SUB_CHARENC_MODE_AUTOMATIC
libavcodec will select the mode itself
#define FF_SUB_CHARENC_MODE_PRE_DECODER
the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define CONFIG_FRAME_THREAD_ENCODER
#define FFMPEG_CONFIGURATION
int ff_decode_preinit(AVCodecContext *avctx)
Perform decoder initialization and validation.
static float sub(float src0, float src1)
int ff_encode_preinit(AVCodecContext *avctx)
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
const OptionDef options[]
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options)
void ff_frame_thread_encoder_free(AVCodecContext *avctx)
void av_opt_free(void *obj)
Free all allocated objects in obj.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
int av_codec_is_encoder(const AVCodec *codec)
int av_codec_is_decoder(const AVCodec *codec)
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
const char * avcodec_configuration(void)
Return the libavcodec build-time configuration.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
unsigned avcodec_version(void)
Return the LIBAVCODEC_VERSION_INT constant.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
const char * avcodec_license(void)
Return the libavcodec license.
av_cold int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
@ AV_CODEC_ID_PCM_S8_PLANAR
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
int av_lockmgr_register(int(*cb)(void **mutex, enum AVLockOp op))
Register a user provided lock manager supporting the operations specified by AVLockOp.
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
AVLockOp
Lock operation used by lockmgr.
const char * avcodec_profile_name(enum AVCodecID codec_id, int profile)
Return a name for the specified profile, if available.
int avcodec_is_open(AVCodecContext *s)
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_log_get_level(void)
Get the current log level.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define av_fourcc2str(fourcc)
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
int av_image_check_sar(unsigned int w, unsigned int h, AVRational sar)
Check if the given sample aspect ratio of an image is valid.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
#define FF_MAX_EXTRADATA_SIZE
Maximum size in bytes of extradata.
#define FF_SANE_NB_CHANNELS
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
int ff_thread_init(AVCodecContext *avctx)
void ff_thread_free(AVCodecContext *avctx)
#define LIBAVCODEC_VERSION_MICRO
#define LIBAVCODEC_VERSION_INT
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
#define attribute_align_arg
#define AV_MUTEX_INITIALIZER
static int ff_mutex_unlock(AVMutex *mutex)
static int ff_mutex_lock(AVMutex *mutex)
Memory handling functions.
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_chroma_location_name(enum AVChromaLocation location)
const char * av_color_range_name(enum AVColorRange range)
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCHROMA_LOC_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
enum AVMediaType codec_type
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int64_t pts_correction_last_dts
PTS of the last frame.
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
int width
picture width / height.
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
int64_t pts_correction_last_pts
Number of incorrect DTS values so far.
attribute_deprecated int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
enum AVSampleFormat sample_fmt
audio sample format
int64_t max_pixels
The number of pixels per image to maximally accept.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
char * sub_charenc
DTS of the last frame.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
int qmin
minimum quantizer
enum AVMediaType codec_type
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
uint8_t * dump_separator
dump format separator.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
enum AVFieldOrder field_order
Field order.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
int active_thread_type
Which multithreading methods are in use by the codec.
int sub_charenc_mode
Subtitles character encoding mode.
char * codec_whitelist
',' separated list of allowed decoders.
int64_t bit_rate
the average bitrate
const struct AVCodec * codec
unsigned properties
Properties of the stream that gets decoded.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
enum AVColorSpace colorspace
YUV colorspace type.
int initial_padding
Audio only.
int sample_rate
samples per second
int frame_number
Frame counter, set by libavcodec.
int refs
number of reference frames
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int qmax
maximum quantizer
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
uint8_t * subtitle_header
Header containing style information for text subtitles.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
int trailing_padding
Audio only.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
int coded_width
Bitstream width / height, may be different from width/height e.g.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
uint64_t channel_layout
Audio channel layout.
struct AVCodecInternal * internal
Private context used for internal data.
const char * name
Name of the codec described by this descriptor.
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
AVPacket * last_pkt_props
Properties (timestamps+side data) extracted from the last packet passed for decoding.
unsigned int byte_buffer_size
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
void * hwaccel_priv_data
hwaccel-specific private data
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
int skip_samples_multiplier
int draining
checks API usage: after codec draining, flush is required to resume operation
AVFrame * compat_decode_frame
void * frame_thread_encoder
AVPacket * compat_encode_packet
int caps_internal
Internal codec capabilities.
const AVClass * priv_class
AVClass for the private context.
int(* init)(struct AVCodecContext *)
void(* flush)(struct AVCodecContext *)
Flush buffers.
const char * name
Name of the codec implementation.
int(* close)(struct AVCodecContext *)
int capabilities
Codec capabilities.
int depth
Number of bits in the component.
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
int(* uninit)(AVCodecContext *avctx)
Uninitialize the hwaccel private data.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Rational number (pair of numerator and denominator).
static double cb(void *priv, double x, double y)