-
-
Save Zaneo/d8f9ea13c5157950bc7ed190b530aa9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(framefinished && nres > 0 && nres == sz) | |
{ | |
if (is_first_successful_frame){ | |
is_first_successful_frame = false; | |
img_conv_ctx = sws_getContext(m_pCodecCtx->width, m_pCodecCtx->height, m_pCodecCtx->pix_fmt, | |
m_pCodecCtx->width, m_pCodecCtx->height, PIX_FMT_BGR24, | |
SWS_BICUBIC, nullptr, nullptr, nullptr); | |
auto bytes = avpicture_get_size(m_pCodecCtx->pix_fmt, m_pCodecCtx->width, m_pCodecCtx->height); | |
auto buffer = reinterpret_cast<uint8_t *>(av_malloc(bytes * sizeof(uint8_t))); | |
avpicture_fill(reinterpret_cast<AVPicture*>(temp_frame), buffer, PIX_FMT_BGR24, m_pCodecCtx->width, m_pCodecCtx->height); | |
if (img_conv_ctx == nullptr){ | |
printf("Failed to create conversion context\n"); | |
throw 1; | |
} | |
cv::namedWindow( "frame", cv::WINDOW_AUTOSIZE ); | |
} | |
nres = sws_scale(img_conv_ctx, m_pFrame->data, m_pFrame->linesize, 0, m_pCodecCtx->height, temp_frame->data, temp_frame->linesize); | |
cv::Mat img(m_pCodecCtx->height, m_pCodecCtx->width, CV_8UC3, temp_frame->data[0], temp_frame->linesize[0]); | |
cv::imshow("frame", img); | |
cv::waitKey(15); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment