FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Data Structures | Enumerations | Functions
Utility functions
Encoding/Decoding Library

Miscellaneous utility functions related to both encoding and decoding (or neither). More...

Modules

 Pixel formats
 Functions for working with pixel formats.
 
 FFT functions
 

Data Structures

struct  AVBitStreamFilterContext
 
struct  AVBitStreamFilter
 

Enumerations

enum  AVLockOp { AV_LOCK_CREATE, AV_LOCK_OBTAIN, AV_LOCK_RELEASE, AV_LOCK_DESTROY }
 Lock operation used by lockmgr. More...
 

Functions

void avcodec_set_dimensions (AVCodecContext *s, int width, int height)
 
size_t av_get_codec_tag_string (char *buf, size_t buf_size, unsigned int codec_tag)
 Put a string representing the codec tag codec_tag in buf.
 
void avcodec_string (char *buf, int buf_size, AVCodecContext *enc, int encode)
 
const char * av_get_profile_name (const AVCodec *codec, int profile)
 Return a name for the specified profile, if available.
 
int avcodec_default_execute (AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
 
int avcodec_default_execute2 (AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2, int, int), void *arg, int *ret, int count)
 
int avcodec_fill_audio_frame (AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
 Fill AVFrame audio data and linesize pointers.
 
void avcodec_flush_buffers (AVCodecContext *avctx)
 Flush buffers, should be called when seeking or when switching to a different stream.
 
void avcodec_default_free_buffers (AVCodecContext *s)
 
int av_get_bits_per_sample (enum AVCodecID codec_id)
 Return codec bits per sample.
 
enum AVCodecID av_get_pcm_codec (enum AVSampleFormat fmt, int be)
 Return the PCM codec associated with a sample format.
 
int av_get_exact_bits_per_sample (enum AVCodecID codec_id)
 Return codec bits per sample.
 
int av_get_audio_frame_duration (AVCodecContext *avctx, int frame_bytes)
 Return audio frame duration.
 
void av_register_bitstream_filter (AVBitStreamFilter *bsf)
 
AVBitStreamFilterContextav_bitstream_filter_init (const char *name)
 
int av_bitstream_filter_filter (AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
 
void av_bitstream_filter_close (AVBitStreamFilterContext *bsf)
 
AVBitStreamFilterav_bitstream_filter_next (AVBitStreamFilter *f)
 
voidav_fast_realloc (void *ptr, unsigned int *size, size_t min_size)
 Reallocate the given block if it is not large enough, otherwise do nothing.
 
void av_fast_malloc (void *ptr, unsigned int *size, size_t min_size)
 Allocate a buffer, reusing the given one if large enough.
 
void av_fast_padded_malloc (void *ptr, unsigned int *size, size_t min_size)
 Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end which will will always be 0.
 
void av_fast_padded_mallocz (void *ptr, unsigned int *size, size_t min_size)
 Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call.
 
unsigned int av_xiphlacing (unsigned char *s, unsigned int v)
 Encode extradata length to a buffer.
 
void av_log_missing_feature (void *avc, const char *feature, int want_sample)
 Log a generic warning message about a missing feature.
 
void av_log_ask_for_sample (void *avc, const char *msg,...) av_printf_format(2
 Log a generic warning message asking for a sample.
 
void void av_register_hwaccel (AVHWAccel *hwaccel)
 Register the hardware accelerator hwaccel.
 
AVHWAccelav_hwaccel_next (AVHWAccel *hwaccel)
 If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL, returns the next registered hardware accelerator after hwaccel, or NULL if hwaccel is the last one.
 
int av_lockmgr_register (int(*cb)(void **mutex, enum AVLockOp op))
 Register a user provided lock manager supporting the operations specified by AVLockOp.
 
enum AVMediaType avcodec_get_type (enum AVCodecID codec_id)
 Get the type of the given codec.
 
const char * avcodec_get_name (enum AVCodecID id)
 Get the name of a codec.
 
int avcodec_is_open (AVCodecContext *s)
 
int av_codec_is_encoder (const AVCodec *codec)
 
int av_codec_is_decoder (const AVCodec *codec)
 
const AVCodecDescriptoravcodec_descriptor_get (enum AVCodecID id)
 
const AVCodecDescriptoravcodec_descriptor_next (const AVCodecDescriptor *prev)
 Iterate over all codec descriptors known to libavcodec.
 
const AVCodecDescriptoravcodec_descriptor_get_by_name (const char *name)
 

Detailed Description

Miscellaneous utility functions related to both encoding and decoding (or neither).

Enumeration Type Documentation

enum AVLockOp

Lock operation used by lockmgr.

Enumerator:
AV_LOCK_CREATE 

Create a mutex.

AV_LOCK_OBTAIN 

Lock the mutex.

AV_LOCK_RELEASE 

Unlock the mutex.

AV_LOCK_DESTROY 

Free mutex resources.

Definition at line 5034 of file avcodec.h.

Function Documentation

void avcodec_set_dimensions ( AVCodecContext s,
int  width,
int  height 
)
size_t av_get_codec_tag_string ( char *  buf,
size_t  buf_size,
unsigned int  codec_tag 
)

Put a string representing the codec tag codec_tag in buf.

Parameters
buf_sizesize in bytes of buf
Returns
the length of the string that would have been generated if enough space had been available, excluding the trailing null

Definition at line 2160 of file utils.c.

Referenced by avcodec_string(), init_muxer(), main(), print_pix_fmt_fourccs(), and show_stream().

void avcodec_string ( char *  buf,
int  buf_size,
AVCodecContext enc,
int  encode 
)

Definition at line 2180 of file utils.c.

Referenced by avformat_find_stream_info(), and dump_stream_format().

const char* av_get_profile_name ( const AVCodec codec,
int  profile 
)

Return a name for the specified profile, if available.

Parameters
codecthe codec that is searched for the given profile
profilethe profile value for which a name is requested
Returns
A name for the profile if found, NULL otherwise.

Definition at line 2291 of file utils.c.

Referenced by avcodec_string(), and show_stream().

int avcodec_default_execute ( AVCodecContext c,
int(*)(AVCodecContext *c2, void *arg2)  func,
void arg,
int *  ret,
int  count,
int  size 
)

Definition at line 667 of file utils.c.

Referenced by avcodec_get_context_defaults3(), and avcodec_thread_execute().

int avcodec_default_execute2 ( AVCodecContext c,
int(*)(AVCodecContext *c2, void *arg2, int, int)  func,
void arg,
int *  ret,
int  count 
)
int avcodec_fill_audio_frame ( AVFrame frame,
int  nb_channels,
enum AVSampleFormat  sample_fmt,
const uint8_t buf,
int  buf_size,
int  align 
)

Fill AVFrame audio data and linesize pointers.

The buffer buf must be a preallocated buffer with a size big enough to contain the specified samples amount. The filled AVFrame data pointers will point to this buffer.

AVFrame extended_data channel pointers are allocated if necessary for planar audio.

Parameters
framethe AVFrame frame->nb_samples must be set prior to calling the function. This function fills in frame->data, frame->extended_data, frame->linesize[0].
nb_channelschannel count
sample_fmtsample format
bufbuffer to use for frame data
buf_sizesize of buffer
alignplane size sample alignment (0 = default)
Returns
>=0 on success, negative error code on failure
Todo:
return the size in bytes required to store the samples in case of success, at the next libavutil bump
Examples:
doc/examples/decoding_encoding.c, and doc/examples/muxing.c.

Definition at line 325 of file utils.c.

Referenced by audio_encode_example(), audio_get_buffer(), pad_last_frame(), and write_audio_frame().

void avcodec_flush_buffers ( AVCodecContext avctx)

Flush buffers, should be called when seeking or when switching to a different stream.

Definition at line 2327 of file utils.c.

Referenced by audio_decode_frame(), get_video_frame(), rewind_file(), subtitle_thread(), and video_thread().

void avcodec_default_free_buffers ( AVCodecContext s)

Definition at line 2367 of file utils.c.

Referenced by avcodec_close(), ff_MPV_common_end(), and frame_thread_free().

int av_get_bits_per_sample ( enum AVCodecID  codec_id)
enum AVCodecID av_get_pcm_codec ( enum AVSampleFormat  fmt,
int  be 
)

Return the PCM codec associated with a sample format.

Parameters
beendianness, 0 for little, 1 for big, -1 (or anything else) for native
Returns
AV_CODEC_ID_PCM_* or AV_CODEC_ID_NONE

Definition at line 2431 of file utils.c.

Referenced by lavfi_read_header().

int av_get_exact_bits_per_sample ( enum AVCodecID  codec_id)

Return codec bits per sample.

Only return non-zero if the bits per sample is exactly correct, not an approximation.

Parameters
[in]codec_idthe codec
Returns
Number of bits per sample or zero if unknown for the given codec.

Definition at line 2381 of file utils.c.

Referenced by av_get_audio_frame_duration(), av_get_bits_per_sample(), and new_output_stream().

int av_get_audio_frame_duration ( AVCodecContext avctx,
int  frame_bytes 
)

Return audio frame duration.

Parameters
avctxcodec context
frame_bytessize of the frame, or 0 if unknown
Returns
frame duration, in samples, if known. 0 if not able to determine.

Definition at line 2470 of file utils.c.

Referenced by build_frame_code(), do_streamcopy(), ff_get_audio_frame_size(), get_aiff_header(), rtp_send_ilbc(), and rtp_write_header().

void av_register_bitstream_filter ( AVBitStreamFilter bsf)

Definition at line 33 of file bitstream_filter.c.

AVBitStreamFilterContext* av_bitstream_filter_init ( const char *  name)

Definition at line 38 of file bitstream_filter.c.

Referenced by init(), new_output_stream(), and Stagefright_init().

int av_bitstream_filter_filter ( AVBitStreamFilterContext bsfc,
AVCodecContext avctx,
const char *  args,
uint8_t **  poutbuf,
int *  poutbuf_size,
const uint8_t buf,
int  buf_size,
int  keyframe 
)

Definition at line 61 of file bitstream_filter.c.

Referenced by decode(), init(), Stagefright_decode_frame(), and write_frame().

void av_bitstream_filter_close ( AVBitStreamFilterContext bsf)

Definition at line 53 of file bitstream_filter.c.

Referenced by exit_program(), Stagefright_close(), Stagefright_init(), and uninit().

AVBitStreamFilter* av_bitstream_filter_next ( AVBitStreamFilter f)

Definition at line 28 of file bitstream_filter.c.

Referenced by show_bsfs().

void* av_fast_realloc ( void ptr,
unsigned int *  size,
size_t  min_size 
)
void av_fast_malloc ( void ptr,
unsigned int *  size,
size_t  min_size 
)

Allocate a buffer, reusing the given one if large enough.

Contrary to av_fast_realloc the current buffer contents might not be preserved and on error the old buffer is freed, thus no special handling to avoid memleaks is necessary.

Parameters
ptrpointer to pointer to already allocated buffer, overwritten with pointer to new buffer
sizesize of the buffer *ptr points to
min_sizeminimum size of *ptr buffer after returning, *ptr will be NULL and *size 0 if an error occurred.

Definition at line 94 of file utils.c.

Referenced by allocate_buffers(), ape_decode_frame(), audio_decode_frame(), codec_reinit(), dca_decode_frame(), decode_8(), decode_frame(), decode_i_frame(), decode_p_frame(), ff_h263_decode_frame(), ff_id3v2_parse(), ff_mpeg_update_thread_context(), gif_decode_frame(), gif_read_image(), ljpeg_decode_rgb_scan(), mp_decode_frame(), parse_picture_segment(), pmp_packet(), reconfigure_at_keyframe(), spdif_header_dts4(), spdif_write_packet(), submit_packet(), svq3_decode_frame(), tak_decode_frame(), truemotion1_decode_header(), truemotion1_decode_init(), update_md5_sum(), and utvideo_encode_frame().

void av_fast_padded_malloc ( void ptr,
unsigned int *  size,
size_t  min_size 
)

Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end which will will always be 0.

In addition the whole buffer will initially and after resizes be 0-initialized so that no uninitialized data will ever appear.

Definition at line 99 of file utils.c.

Referenced by cdxl_decode_frame(), cllc_decode_frame(), decode_block(), decode_frame(), ebml_read_binary(), encode_frame(), ff_alloc_packet2(), ff_h264_decode_nal(), ff_mjpeg_find_marker(), init_buffers(), mimic_decode_frame(), mpc7_decode_frame(), tiff_unpack_strip(), and tqi_decode_frame().

void av_fast_padded_mallocz ( void ptr,
unsigned int *  size,
size_t  min_size 
)

Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call.

Definition at line 111 of file utils.c.

Referenced by encode_frame().

unsigned int av_xiphlacing ( unsigned char *  s,
unsigned int  v 
)

Encode extradata length to a buffer.

Used by xiph codecs.

Parameters
sbuffer to write to; must be at least (v/255+1) bytes long
vsize of extradata in bytes
Returns
number of bytes written to the buffer.

Definition at line 2637 of file utils.c.

Referenced by fixup_vorbis_headers(), oggvorbis_encode_init(), parse_packed_headers(), and put_main_header().

void av_log_missing_feature ( void avc,
const char *  feature,
int  want_sample 
)

Log a generic warning message about a missing feature.

This function is intended to be used internally by FFmpeg (libavcodec, libavformat, etc.) only, and would normally not be used by applications.

Parameters
[in]avca pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct
[in]featurestring containing the name of the missing feature
[in]want_sampleindicates if samples are wanted which exhibit this feature. If want_sample is non-zero, additional verbage will be added to the log message which tells the user how to report samples to the development mailing list.

Definition at line 2658 of file utils.c.

Referenced by aac_adtstoasc_filter(), amr_decode_fix_avctx(), amrnb_decode_frame(), amrnb_decode_init(), amrwb_decode_frame(), amrwb_decode_init(), decode_audio_block(), decode_frame(), decode_frame_header(), decode_ga_specific_config(), decode_ics(), decode_init(), decode_packet(), decode_seq_header(), decode_subframe(), epaf_read_header(), ff_eac3_parse_header(), ff_mjpeg_decode_sof(), ff_spdif_read_packet(), ff_vc1_parse_frame_header_adv(), flashsv_decode_frame(), h264_set_parameter_from_sps(), latm_decode_audio_specific_config(), mimic_decode_frame(), mpc8_decode_init(), ogg_replace_stream(), parse_adts_frame_header(), parse_fmtp(), parse_MP4SLDescrTag(), qt_rtp_parse_packet(), read_sbr_extension(), read_stream_mux_config(), rv10_decode_init(), skeleton_header(), smc_decode_stream(), spdif_get_offset_and_codec(), synth_superframe(), tm2_read_header(), vp6_parse_header(), and write_header().

void av_log_ask_for_sample ( void avc,
const char *  msg,
  ... 
)

Log a generic warning message asking for a sample.

This function is intended to be used internally by FFmpeg (libavcodec, libavformat, etc.) only, and would normally not be used by applications.

Parameters
[in]avca pointer to an arbitrary struct of which the first field is a pointer to an AVClass struct
[in]msgstring containing an optional message, or NULL if no message

Referenced by alac_decode_init(), ape_decode_init(), ast_read_header(), atrac1_decode_init(), av_log_missing_feature(), avpriv_adx_decode_header(), avr_read_header(), cdxl_decode_frame(), cinepak_decode(), cook_decode_init(), dca_decode_frame(), dca_exss_parse_header(), dca_parse_frame_header(), dca_subframe_header(), decode_band_hdr(), decode_bytes(), decode_channel_transform(), decode_frame(), decode_frame_headers(), decode_init(), decode_mvc2(), decode_nop(), decode_scalefactors(), decode_sgirle8(), decode_slice_header(), decode_subframe(), decode_wmv9(), determine_bitrate(), ea_read_packet(), execute_code(), ff_compute_band_indexes(), ff_mjpeg_decode_sof(), ff_parse_mpeg2_descriptor(), ff_spdif_read_packet(), fill_coding_method_array(), get_packet_header(), iff_read_header(), imc_decode_block(), imc_decode_init(), lvf_read_header(), mov_read_mdhd(), mpc7_decode_init(), mtv_read_header(), mv_read_header(), mxf_read_packet_old(), mxf_read_primer_pack(), nist_read_header(), oma_read_header(), paf_vid_decode(), parse_setup_header(), parse_video_var(), pmp_packet(), process_audio_header_eacs(), process_audio_header_elements(), process_ea_header(), process_frame_obj(), ptx_decode_frame(), ra288_decode_init(), read_block_data(), read_frame(), read_header(), read_major_sync(), read_restart_header(), read_table(), rso_read_header(), save_bits(), smjpeg_read_header(), spdif_header_dts(), spdif_header_truehd(), sunrast_decode_frame(), truemotion1_decode_header(), truespeech_decode_init(), unsupported(), vc1_decode_init(), vcr1_decode_init(), wsaud_read_header(), xa_decode(), xmv_read_header(), xwd_decode_frame(), xwma_read_header(), and zero12v_decode_init().

void void av_register_hwaccel ( AVHWAccel hwaccel)

Register the hardware accelerator hwaccel.

Definition at line 2685 of file utils.c.

AVHWAccel* av_hwaccel_next ( AVHWAccel hwaccel)

If hwaccel is NULL, returns the first registered hardware accelerator, if hwaccel is non-NULL, returns the next registered hardware accelerator after hwaccel, or NULL if hwaccel is the last one.

Definition at line 2694 of file utils.c.

Referenced by ff_find_hwaccel().

int av_lockmgr_register ( int(*)(void **mutex, enum AVLockOp op cb)

Register a user provided lock manager supporting the operations specified by AVLockOp.

mutex points to a (void *) where the lockmgr should store/get a pointer to a user allocated mutex. It's NULL upon AV_LOCK_CREATE and != NULL for all other ops.

Parameters
cbUser defined callback. Note: FFmpeg may invoke calls to this callback during the call to av_lockmgr_register(). Thus, the application must be prepared to handle that. If cb is set to NULL the lockmgr will be unregistered. Also note that during unregistration the previously registered lockmgr callback may also be invoked.

Definition at line 2710 of file utils.c.

Referenced by do_exit(), and main().

enum AVMediaType avcodec_get_type ( enum AVCodecID  codec_id)

Get the type of the given codec.

Definition at line 2819 of file utils.c.

Referenced by mkv_query_codec().

const char* avcodec_get_name ( enum AVCodecID  id)
int avcodec_is_open ( AVCodecContext s)
Returns
a positive value if s is open (i.e. avcodec_open2() was called on it with no corresponding avcodec_close()), 0 otherwise.

Definition at line 2839 of file utils.c.

Referenced by avcodec_close(), avcodec_copy_context(), avcodec_open2(), ff_mp4_read_dec_config_descr(), mpegts_find_stream_type(), mpegts_set_stream_info(), and try_decode_frame().

int av_codec_is_encoder ( const AVCodec codec)
Returns
a non-zero number if codec is an encoder, zero otherwise

Definition at line 145 of file utils.c.

Referenced by avcodec_close(), avcodec_find_encoder_by_name(), avcodec_open2(), ff_wma_end(), find_encdec(), next_codec_for_id(), and print_codec().

int av_codec_is_decoder ( const AVCodec codec)
Returns
a non-zero number if codec is a decoder, zero otherwise

Definition at line 150 of file utils.c.

Referenced by avcodec_find_decoder_by_name(), avcodec_open2(), find_encdec(), and next_codec_for_id().

const AVCodecDescriptor* avcodec_descriptor_get ( enum AVCodecID  id)
Returns
descriptor for given codec ID or NULL if no descriptor exists.

Definition at line 2531 of file codec_desc.c.

Referenced by avcodec_get_name(), avcodec_open2(), is_intra_only(), and show_help_muxer().

const AVCodecDescriptor* avcodec_descriptor_next ( const AVCodecDescriptor prev)

Iterate over all codec descriptors known to libavcodec.

Parameters
prevprevious descriptor. NULL to get the first descriptor.
Returns
next descriptor or NULL after the last descriptor

Definition at line 2541 of file codec_desc.c.

Referenced by avcodec_descriptor_get_by_name(), and get_codecs_sorted().

const AVCodecDescriptor* avcodec_descriptor_get_by_name ( const char *  name)
Returns
codec descriptor with the given name or NULL if no such descriptor exists.

Definition at line 2550 of file codec_desc.c.

Referenced by find_codec_or_die(), and show_help_codec().