H264 Decoding SW
1.H264 Decoding
The H264 decoding part is implemented on the mobile phone. This article uses the ffmpeg library for decoding
2.ffmpeg Official Website
3.Decoding Process Diagram
Figure 1. decode_flow
4.Process Explanation
Register Decoder:
avcodec_register_allUsed to register all compiled codecs.
Find Decoder:
avcodec_find_decoderSearches for the decoder corresponding to the specified decoder ID. The decoder ID for H.264 is: AV_CODEC_ID_H264.
Initialize Parser:
av_parser_initInitializes the parser context. The parser can be used for preprocessing input data before processing the data stream, such as finding frame boundaries, extracting key information, etc.
Allocate Decoder Context:
avcodec_alloc_context3Allocates an AVCodecContext structure and sets default values. AVCodecContext is a data structure in ffmpeg used to store the context information of the codec.
Open Decoder:
avcodec_open2Opens the decoder and initializes its context (AVCodecContext). After initializing the decoder context, this function opens the decoder to start the decoding process.
Receive Data
Before starting decoding each time, check if the data starts with an sps frame. Only start decoding when the data with sps beginning is found; otherwise, discard the data without decoding.
Send Data to Parser:
av_parser_parse2Parses the input media data stream, usually used to find frame boundaries.
Send Data to Decoder:
avcodec_send_packetUsed to send data packets to the decoder for decoding. It sends the input data packet to the decoder context for decoding.
Receive Decoded Data Frames:
avcodec_receive_frameUsed to receive the decoded frames from the decoder. After using the
avcodec_send_packetfunction to send data packets for decoding,avcodec_receive_framecan be used to obtain the decoded image frames from the decoder.