24,855
社区成员
发帖
与我相关
我的任务
分享
//一帧一帧读取视频
int frameFinished=0;
av_seek_frame(pAVFormatContext,videoStreamIndex,0*1000,AVSEEK_FLAG_BACKWARD);
while (av_read_frame(pAVFormatContext, &pAVPacket) >= 0){
if(pAVPacket.stream_index==videoStreamIndex){
avcodec_decode_video2(pAVCodecContext, pAVFrame, &frameFinished, &pAVPacket);
if (frameFinished){
mutex.lock();
sws_scale(pSwsContext,(const uint8_t* const *)pAVFrame->data,pAVFrame->linesize,0,videoHeight,pAVPicture.data,pAVPicture.linesize);
//OpenCV显示一帧图像信号
Mat rgb_mat=Mat(videoHeight,videoWidth,CV_8UC3,pAVPicture.data[0]);
Mat bgr_mat;
cvtColor(out_mat,bgr_mat,CV_RGB2BGR);
imshow("Show",bgr_mat);
mutex.unlock();
}
}
av_free_packet(&pAVPacket);//释放资源,否则内存会一直上升
sleep(100);
}