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

Modules

 Frame parsing
 

Macros

#define FF_INPUT_BUFFER_PADDING_SIZE   16
 Required number of additionally allocated bytes at the end of the input bitstream for decoding.
 

Enumerations

enum  AVDiscard {
  AVDISCARD_NONE =-16, AVDISCARD_DEFAULT = 0, AVDISCARD_NONREF = 8, AVDISCARD_BIDIR = 16,
  AVDISCARD_NONKEY = 32, AVDISCARD_ALL = 48
}
 

Functions

AVCodecavcodec_find_decoder (enum AVCodecID id)
 Find a registered decoder with a matching codec ID.
 
AVCodecavcodec_find_decoder_by_name (const char *name)
 Find a registered decoder with the specified name.
 
int avcodec_default_get_buffer (AVCodecContext *s, AVFrame *pic)
 
void avcodec_default_release_buffer (AVCodecContext *s, AVFrame *pic)
 
int avcodec_default_reget_buffer (AVCodecContext *s, AVFrame *pic)
 
unsigned avcodec_get_edge_width (void)
 Return the amount of padding in pixels which the get_buffer callback must provide around the edge of the image for codecs which do not have the CODEC_FLAG_EMU_EDGE flag.
 
void avcodec_align_dimensions (AVCodecContext *s, int *width, int *height)
 Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you do not use any horizontal padding.
 
void avcodec_align_dimensions2 (AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
 Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you also ensure that all line sizes are a multiple of the respective linesize_align[i].
 
int avcodec_decode_audio4 (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
 Decode the audio frame of size avpkt->size from avpkt->data into frame.
 
int avcodec_decode_video2 (AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
 Decode the video frame of size avpkt->size from avpkt->data into picture.
 
int avcodec_decode_subtitle2 (AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
 Decode a subtitle message.
 

Detailed Description

Macro Definition Documentation

#define FF_INPUT_BUFFER_PADDING_SIZE   16

Required number of additionally allocated bytes at the end of the input bitstream for decoding.

This is mainly needed because some optimized bitstream readers read 32 or 64 bit at once and could read over the end.
Note: If the first 23 bits of the additional bytes are not 0, then damaged MPEG bitstreams could cause overread and segfault.

Examples:
doc/examples/decoding_encoding.c.

Definition at line 554 of file avcodec.h.

Referenced by a64multi_init_encoder(), aac_adtstoasc_filter(), aac_decode_frame(), aac_encode_init(), aacPlus_encode_init(), add_av_stream1(), adpcm_encode_init(), adx_read_header(), afc_read_header(), aiff_read_header(), alac_encode_init(), alloc_buffers(), apc_read_header(), ape_tag_read_field(), asf_read_stream_properties(), atrac3_decode_init(), audio_decode_example(), av_fast_padded_malloc(), av_fast_padded_mallocz(), av_grow_packet(), av_new_packet(), av_packet_merge_side_data(), av_packet_new_side_data(), av_packet_split_side_data(), av_parser_change(), av_parser_parse2(), av_shrink_packet(), avcodec_copy_context(), avcodec_encode_audio2(), avcodec_encode_video2(), avformat_find_stream_info(), avi_read_header(), avio_close_dyn_buf(), avisynth_read_header(), avui_encode_init(), cdxl_decode_frame(), celt_header(), cook_decode_init(), dca_parse_params(), decode_frame(), decode_i_frame(), decode_init(), decode_p_frame(), decode_plane(), decode_stream_header(), dshow_add_device(), dump_extradata(), dv_decode_video_segment(), encode_init(), extract_header(), extract_mpeg4_header(), Faac_encode_init(), ff_alloc_packet2(), ff_asf_parse_packet(), ff_combine_frame(), ff_generate_avci_extradata(), ff_h263_decode_frame(), ff_h264_decode_nal(), ff_mjpeg_find_marker(), ff_mp4_read_dec_config_descr(), ff_mpeg_update_thread_context(), ff_parse_mpeg2_descriptor(), fixup_vorbis_headers(), flac_header(), flac_read_header(), flic_decode_frame_8BPP(), flv_get_extradata(), flv_queue_extradata(), flv_set_video_codec(), h264_mp4toannexb_filter(), h264_new_context(), handle_packets(), iff_read_header(), imx_dump_header(), jacosub_read_header(), latm_decode_audio_specific_config(), libopus_encode_init(), matroska_fix_ass_packet(), matroska_read_header(), mjpega_dump_header(), mov2textsub(), mov_read_dvc1(), mov_read_extradata(), mov_read_glbl(), mov_read_strf(), mov_read_stsz(), mov_read_wave(), mov_write_dvc1_structs(), mp3_header_compress(), mp3_header_decompress(), mp_decode_frame(), mpc8_parse_seektable(), mpc8_read_header(), mpc_read_header(), mpegts_push_data(), mss2_decode_frame(), mxf_parse_structural_metadata(), mxg_update_cache(), new_pes_packet(), noise(), ogg_new_buf(), ogg_new_stream(), ogg_read_page(), ogg_save(), oggvorbis_encode_init(), ogm_header(), oma_read_header(), opus_header(), parse_fmtp_config(), parse_packed_headers(), qdm2_parse_config(), qt_rtp_parse_packet(), rdt_parse_b64buf(), read_apic(), read_header(), read_kuki_chunk(), rl2_read_header(), rm_read_audio_stream_info(), rm_read_extradata(), sdp_parse_fmtp_config_h264(), smacker_read_header(), smush_read_header(), spdif_write_packet(), speex_header(), Stagefright_init(), submit_packet(), svq3_decode_frame(), svq3_parse_packet(), tak_read_header(), text2movsub(), theora_header(), tiff_unpack_strip(), transcode_init(), tta_read_header(), utvideo_encode_frame(), utvideo_encode_init(), vc1_decode_frame(), vc1_decode_init(), vc1_extract_headers(), vfw_read_header(), video_decode_example(), vmd_read_header(), vqf_read_header(), wma_decode_superframe(), write_frame(), wsvqa_read_header(), wsvqa_read_packet(), wv_get_value_float(), xmv_process_packet_header(), xwma_read_header(), and yop_read_header().

Enumeration Type Documentation

enum AVDiscard
Enumerator:
AVDISCARD_NONE 

discard nothing

AVDISCARD_DEFAULT 

discard useless packets like 0 size packets in avi

AVDISCARD_NONREF 

discard all non reference

AVDISCARD_BIDIR 

discard all bidirectional frames

AVDISCARD_NONKEY 

discard all frames except keyframes

AVDISCARD_ALL 

discard all

Definition at line 584 of file avcodec.h.

Function Documentation

AVCodec* avcodec_find_decoder ( enum AVCodecID  id)
AVCodec* avcodec_find_decoder_by_name ( const char *  name)

Find a registered decoder with the specified name.

Parameters
namename of the requested decoder
Returns
A decoder if one was found, NULL otherwise.

Definition at line 1985 of file utils.c.

Referenced by find_codec_or_die(), show_help_codec(), stream_component_open(), and v4l2_read_header().

int avcodec_default_get_buffer ( AVCodecContext s,
AVFrame pic 
)
void avcodec_default_release_buffer ( AVCodecContext s,
AVFrame pic 
)

Definition at line 548 of file utils.c.

Referenced by avcodec_get_context_defaults3(), codec_release_buffer(), and free_frame_buffer().

int avcodec_default_reget_buffer ( AVCodecContext s,
AVFrame pic 
)

Definition at line 583 of file utils.c.

Referenced by avcodec_get_context_defaults3().

unsigned avcodec_get_edge_width ( void  )

Return the amount of padding in pixels which the get_buffer callback must provide around the edge of the image for codecs which do not have the CODEC_FLAG_EMU_EDGE flag.

Returns
Required padding in pixels.

Definition at line 165 of file utils.c.

void avcodec_align_dimensions ( AVCodecContext s,
int *  width,
int *  height 
)

Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you do not use any horizontal padding.

May only be used if a codec with CODEC_CAP_DR1 has been opened. If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased according to avcodec_get_edge_width() before.

Definition at line 293 of file utils.c.

Referenced by alloc_buffer().

void avcodec_align_dimensions2 ( AVCodecContext s,
int *  width,
int *  height,
int  linesize_align[AV_NUM_DATA_POINTERS] 
)

Modify width and height values so that they will result in a memory buffer that is acceptable for the codec if you also ensure that all line sizes are a multiple of the respective linesize_align[i].

May only be used if a codec with CODEC_CAP_DR1 has been opened. If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased according to avcodec_get_edge_width() before.

Definition at line 180 of file utils.c.

Referenced by avcodec_align_dimensions(), and video_get_buffer().

int avcodec_decode_audio4 ( AVCodecContext avctx,
AVFrame frame,
int *  got_frame_ptr,
const AVPacket avpkt 
)

Decode the audio frame of size avpkt->size from avpkt->data into frame.

Some decoders may support multiple frames in a single AVPacket. Such decoders would then just decode the first frame. In this case, avcodec_decode_audio4 has to be called again with an AVPacket containing the remaining data in order to decode the second frame, etc... Even if no frames are returned, the packet needs to be fed to the decoder with remaining data until it is completely consumed or an error occurs.

Warning
The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
Note
You might have to align the input buffer. The alignment requirements depend on the CPU and the decoder.
Parameters
avctxthe codec context
[out]frameThe AVFrame in which to store decoded audio samples. Decoders request a buffer of a particular size by setting AVFrame.nb_samples prior to calling get_buffer(). The decoder may, however, only utilize part of the buffer by setting AVFrame.nb_samples to a smaller value in the output frame.
[out]got_frame_ptrZero if no frame could be decoded, otherwise it is non-zero.
[in]avpktThe input AVPacket containing the input buffer. At least avpkt->data and avpkt->size should be set. Some decoders might also require additional fields to be set.
Returns
A negative error code is returned if an error occurred during decoding, otherwise the number of bytes consumed from the input AVPacket is returned.
Examples:
doc/examples/decoding_encoding.c, doc/examples/demuxing.c, and doc/examples/filtering_audio.c.

Definition at line 1716 of file utils.c.

Referenced by audio_decode_example(), audio_decode_frame(), decode_audio(), decode_packet(), main(), movie_push_frame(), process_frame(), try_decode_frame(), and wrap().

int avcodec_decode_video2 ( AVCodecContext avctx,
AVFrame picture,
int *  got_picture_ptr,
const AVPacket avpkt 
)

Decode the video frame of size avpkt->size from avpkt->data into picture.

Some decoders may support multiple frames in a single AVPacket, such decoders would then just decode the first frame.

Warning
The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than the actual read bytes because some optimized bitstream readers read 32 or 64 bits at once and could read over the end.
The end of the input buffer buf should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
Note
You might have to align the input buffer avpkt->data. The alignment requirements depend on the CPU: on some CPUs it isn't necessary at all, on others it won't work at all if not aligned and on others it will work but it will have an impact on performance.

In practice, avpkt->data should have 4 byte alignment at minimum.

Note
Codecs which have the CODEC_CAP_DELAY capability set have a delay between input and output, these need to be fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames.
Parameters
avctxthe codec context
[out]pictureThe AVFrame in which the decoded video frame will be stored. Use avcodec_alloc_frame to get an AVFrame, the codec will allocate memory for the actual bitmap. with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit. with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder decodes and the decoder tells the user once it does not need the data anymore, the user app can at this point free/reuse/keep the memory as it sees fit.
[in]avpktThe input AVpacket containing the input buffer. You can create such packet with av_init_packet() and by then setting data and size, some decoders might in addition need other fields like flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least fields possible.
[in,out]got_picture_ptrZero if no frame could be decompressed, otherwise, it is nonzero.
Returns
On error a negative value is returned, otherwise the number of bytes used or zero if no frame could be decompressed.
Examples:
doc/examples/decoding_encoding.c, doc/examples/demuxing.c, and doc/examples/filtering_video.c.

Definition at line 1597 of file utils.c.

Referenced by decode_packet(), decode_video(), decode_write_frame(), ff_load_image(), get_video_frame(), main(), movie_push_frame(), process_frame(), try_decode_frame(), and wrap().

int avcodec_decode_subtitle2 ( AVCodecContext avctx,
AVSubtitle sub,
int *  got_sub_ptr,
AVPacket avpkt 
)

Decode a subtitle message.

Return a negative value on error, otherwise return the number of bytes used. If no subtitle could be decompressed, got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for simplicity, because the performance difference is expect to be negligible and reusing a get_buffer written for video codecs would probably perform badly due to a potentially very different allocation pattern.

Parameters
avctxthe codec context
[out]subThe AVSubtitle in which the decoded subtitle will be stored, must be freed with avsubtitle_free if *got_sub_ptr is set.
[in,out]got_sub_ptrZero if no subtitle could be decompressed, otherwise, it is nonzero.
[in]avpktThe input AVPacket containing the input buffer.

Definition at line 1822 of file utils.c.

Referenced by subtitle_thread(), transcode_subtitles(), try_decode_frame(), and wrap().