c++ - FFMPEG - Read video file and convert to Bitmap -
i can read video file using ffmpeg
now want show these video frames on mfc mdi.
for need bitmap feed cbitmap::fromhandle() function
memdc.createcompatibledc(dc); cbitmap * bmp = cbitmap::fromhandle(); cbitmap * oldbmp = memdc.selectobject(bmp); dc->bitblt(0,0,320,240,&memdc,0,0,srccopy);
for ffmpeg using dranger tutorial 01
http://dranger.com/ffmpeg/tutorial01.html
please advise how convert frames bitmap
thanks
i have been working on last 3 days , gotten far
now frames bitblt dc upside down
please let me know if there wrong code
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)) { // packet 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 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 packet allocated av_read_frame av_free_packet(&packet); }
Comments
Post a Comment