I. Avcodec_find_decoder
Gets the decoder. Before use must ensure that the decoder used has been registered, the simplest is to call the avcodec_register_all() function, just like before the registration of the wrapper, but also to register a bit.
Avcodec *avcodec_find_decoder (enum avcodecid ID);
Find the decoder, the first method is directly through the ID number lookup, this ID number from where to get it? Just like after we unpacked, you can see that there is actually a codecid in our avstream, and that ID number is the ID number of the decoder we are going to use. Of course, if you know the ID number of the format, you can also go directly into it (generally we use h264, then this codecid is 28). Find the decoder and return to the Avcodec. The avcodec is stored in the decoder format configuration information, does not represent the final decoder to be processed.
Avcodec *avcodec_find_decoder_by_name (const char name);
In addition to locating the decoder with the decoder's ID number, it is possible to open the decoder by name. Example: Avcodec_find_decoder_by_name ("H264_mediacodec"); Using the decoding module that comes with Android)
Two. Avcodeccontext Decoder context
Avcodeccontext *avcode_alloc_context3 (const AVCODEC *CODEC); Apply for Avcodeccontext space. You need to pass an encoder or not, but it does not contain an encoder.
void Avcodec_free_context (Avcodeccontext **avctx); Clean and avcodeccontext space.
int Avcodec_open2 (Avcodeccontext *avctx, const AVCODEC *CODEC, avdictionary **options);
Turn on the video decoder. If there is no decoder at the time of Avcode_alloc_context3 , it is necessary to pass it here, and the following options are optional parameters. See also: Libavcodec/options_table.h.
Common parameters of Avcodeccontext:
int thread_count; Used to configure the number of decoding threads
Time_base//Time base.
Three.Avcodec_parameters_to_context
Avcodec_parameters_to_context (codec, p). This function is used to copy the parameters inside the stream, that is, the arguments inside the Avstream directly into the avcodeccontext context.
Four. Open Audio Video Decoder example
//Register DecoderAvcodec_register_all (); Avcodec*VC = Avcodec_find_decoder (ic->streams[videostream]->codecpar->codec_id);//Soft Solution//VC = avcodec_find_decoder_by_name ("H264_mediacodec");//Hard Solution if(!vc) {LOGE ("Avcodec_find_decoder[videostream] Failure"); returnEnv->Newstringutf (Hello.c_str ()); } //Configure the decoderAvcodeccontext *VCT =Avcodec_alloc_context3 (VC); Avcodec_parameters_to_context (VCT, IC->streams[videostream]->Codecpar); VCT->thread_count =1; //Open Decoder intRe = Avcodec_open2 (VCT, VC,0); if(Re! =0) {LOGE ("avcodec_open2 Failure"); returnEnv->Newstringutf (Hello.c_str ()); }
FFmpeg (8)-Open and configure the audio and video decoder (Avcodec_find_decoder (), AVCODEC_ALLOC_CONTEXT3 ())