我在过去 3 天里一直在研究它并做到了这一点
现在帧是 BitBlt 到 dc 成功,但它们是颠倒的
请让我知道代码是否有任何问题
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
pCodecCtx->width, pCodecCtx->height);
int w = pCodecCtx->width;
int h = pCodecCtx->height;
img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt,
w, h, PIX_FMT_RGB24,
SWS_BICUBIC, NULL, NULL, NULL);
/*CClientDC dc;*/
BITMAPINFO bmi = {0};
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = -pCodecCtx->height;
bmi.bmiHeader.biWidth = pCodecCtx->width;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biSizeImage = pCodecCtx->height * pCodecCtx->width * 3;
hbmp = CreateDIBSection(hdcmem, &bmi, DIB_RGB_COLORS, &pbmpdata , NULL, 0); //&pbmpdata
hdcscr = GetDC(0);
hdcmem = CreateCompatibleDC(hdcscr);
i=0;
while((av_read_frame(pFormatCtx, &packet)>=0)) {
// Is this a packet from the video stream?
if(packet.stream_index==videoStreamIdx) {
/// Decode video frame
//avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if(frameFinished) {
i++;
sws_scale(img_convert_ctx, pFrame->data,
pFrame->linesize, 0, pCodecCtx->height,
pFrameRGB->data, pFrameRGB->linesize);
pFrameRGB->data[0] = (uint8_t*)pbmpdata;
pFrameRGB->linesize[0] = pCodecCtx->width * 3;
SelectObject(hdcmem, hbmp);//hbmp
BitBlt(hdcscr, 0, 0, pCodecCtx->width, pCodecCtx->height, hdcmem , 0, 0, SRCCOPY);
Sleep(10);
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
}