FFmpeg  1.2.12
Data Structures | Typedefs | Functions
Frame parsing
Decoding

Data Structures

struct  AVCodecParserContext
struct  AVCodecParser

Typedefs

typedef struct AVCodecParserContext AVCodecParserContext
typedef struct AVCodecParser AVCodecParser
typedef struct AVCodecParserContext AVCodecParserContext
typedef struct AVCodecParser AVCodecParser
typedef struct AVCodecParserContext AVCodecParserContext
typedef struct AVCodecParser AVCodecParser

Functions

AVCodecParserav_parser_next (AVCodecParser *c)
void av_register_codec_parser (AVCodecParser *parser)
AVCodecParserContextav_parser_init (int codec_id)
int av_parser_parse2 (AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
 Parse a packet.
int av_parser_change (AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
void av_parser_close (AVCodecParserContext *s)

Detailed Description

Find a registered decoder with a matching codec ID.

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

Find a registered decoder with the specified name.

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

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.

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.

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.

Wrapper function which calls avcodec_decode_audio4.

Deprecated:
Use avcodec_decode_audio4 instead.

Decode the audio frame of size avpkt->size from avpkt->data into samples. Some decoders may support multiple frames in a single AVPacket, such decoders would then just decode the first frame. In this case, avcodec_decode_audio3 has to be called again with an AVPacket that contains the remaining data in order to decode the second frame etc. If no frame could be outputted, frame_size_ptr is zero. Otherwise, it is the decompressed frame size in bytes.

Warning
You must set frame_size_ptr to the allocated size of the output buffer before calling avcodec_decode_audio3().
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 avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
You must not provide a custom get_buffer() when using avcodec_decode_audio3(). Doing so will override it with avcodec_default_get_buffer. Use avcodec_decode_audio4() instead, which does allow the application to provide a custom get_buffer().
Note
You might have to align the input buffer avpkt->data and output buffer samples. 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 and samples should be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do).

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]samplesthe output buffer, sample type in avctx->sample_fmt If the sample format is planar, each channel plane will be the same size, with no padding between channels.
[in,out]frame_size_ptrthe output buffer size in bytes
[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. All decoders are designed to use the least fields possible though.
Returns
On error a negative value is returned, otherwise the number of bytes used or zero if no frame data was decompressed (used) from the input AVPacket.

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.

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.

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.

Find a registered decoder with a matching codec ID.

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

Find a registered decoder with the specified name.

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

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.

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.

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.

Wrapper function which calls avcodec_decode_audio4.

Deprecated:
Use avcodec_decode_audio4 instead.

Decode the audio frame of size avpkt->size from avpkt->data into samples. Some decoders may support multiple frames in a single AVPacket, such decoders would then just decode the first frame. In this case, avcodec_decode_audio3 has to be called again with an AVPacket that contains the remaining data in order to decode the second frame etc. If no frame could be outputted, frame_size_ptr is zero. Otherwise, it is the decompressed frame size in bytes.

Warning
You must set frame_size_ptr to the allocated size of the output buffer before calling avcodec_decode_audio3().
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 avpkt->data should be set to 0 to ensure that no overreading happens for damaged MPEG streams.
You must not provide a custom get_buffer() when using avcodec_decode_audio3(). Doing so will override it with avcodec_default_get_buffer. Use avcodec_decode_audio4() instead, which does allow the application to provide a custom get_buffer().
Note
You might have to align the input buffer avpkt->data and output buffer samples. 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 and samples should be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do).

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]samplesthe output buffer, sample type in avctx->sample_fmt If the sample format is planar, each channel plane will be the same size, with no padding between channels.
[in,out]frame_size_ptrthe output buffer size in bytes
[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. All decoders are designed to use the least fields possible though.
Returns
On error a negative value is returned, otherwise the number of bytes used or zero if no frame data was decompressed (used) from the input AVPacket.

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.

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.

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.

Typedef Documentation

typedef struct AVCodecParser AVCodecParser
typedef struct AVCodecParser AVCodecParser
typedef struct AVCodecParser AVCodecParser

Function Documentation

int av_parser_change ( AVCodecParserContext s,
AVCodecContext avctx,
uint8_t **  poutbuf,
int *  poutbuf_size,
const uint8_t buf,
int  buf_size,
int  keyframe 
)
Returns
0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
Deprecated:
use AVBitstreamFilter
Returns
0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
Deprecated:
use AVBitstreamFilter
Returns
0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
Deprecated:
use AVBitstreamFilter

Definition at line 169 of file parser.c.

void av_parser_close ( AVCodecParserContext s)
AVCodecParserContext * av_parser_init ( int  codec_id)
AVCodecParser * av_parser_next ( AVCodecParser c)

Definition at line 30 of file parser.c.

int av_parser_parse2 ( AVCodecParserContext s,
AVCodecContext avctx,
uint8_t **  poutbuf,
int *  poutbuf_size,
const uint8_t buf,
int  buf_size,
int64_t  pts,
int64_t  dts,
int64_t  pos 
)

Parse a packet.

Parameters
sparser context.
avctxcodec context.
poutbufset to pointer to parsed buffer or NULL if not yet finished.
poutbuf_sizeset to size of parsed buffer or zero if not yet finished.
bufinput buffer.
buf_sizeinput length, to signal EOF, this should be 0 (so that the last frame can be output).
ptsinput presentation timestamp.
dtsinput decoding timestamp.
posinput byte position in stream.
Returns
the number of bytes of the input bitstream used.

Example:

while(in_len){
in_data, in_len,
pts, dts, pos);
in_data += len;
in_len -= len;
if(size)
}

Definition at line 112 of file parser.c.

Referenced by check_format(), decode(), and parse_packet().

void av_register_codec_parser ( AVCodecParser parser)

Definition at line 35 of file parser.c.