【正文】
給出了一個(gè)陽(yáng)春版的解碼器,我們來(lái)仔細(xì)看看 陽(yáng)春后面的故事,為了方便講述,我先貼出代碼: include ffmpeg/ include ffmpeg/ include void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) { FILE *pFile。 char szFilename[32]。 if(pFile==NULL) return。 y++) fwrite(pFramedata[0]+y*pFramelinesize[0], 1, width*3, pFile)。 AVCodecContext *pCodecCtx。 AVPacket packet。 if(argc 2) { printf(Please provide a movie file\n)。pFormatCtx, argv[1], NULL, 0, NULL)!=0) return 1。t find stream information // Dump information about file onto standard error dump_format(pFormatCtx, 0, argv[1], 0)。 i++) if(pFormatCtxstreams[i]codeccodec_type==CODEC_TYPE_VIDEO) { videoStream=i。t find a video stream // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtxstreams[videoStream]codec。 // Codec not found } // Open codec if(avcodec_open(pCodecCtx, pCodec)0) return 1。 // Determine required buffer size and allocate buffer numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtxwidth, pCodecCtxheight)。 while(av_read_frame(pFormatCtx, amp。 // Save the frame to disk if(++i=5) SaveFrame(pFrameRGB, pCodecCtxwidth, pCodecCtxheight, i)。 av_free(pFrameRGB)。 return 0。 } ...... err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap)。 我們來(lái)看看如何獲取 Packet,又如何從 Packet 中解碼 frame 的。 從幀中解碼 。 真正的難度,其實(shí)就是上面的 [1],[2],[3],[4],其他部分