第一次提问,格式可能不对,请见谅
numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height,4);
out_buffer_rgb = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t));
av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, out_buffer_rgb, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 4);
/*
img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
*/
img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
AV_PIX_FMT_NV12, pCodecCtx->width, pCodecCtx->height,
AV_PIX_FMT_RGB24, SWS_POINT, NULL, NULL, NULL);
int got_picture = 0;
while (1)
{
ret = packet_queue_get(&ps->video_packet_queue, packet, 0);
if (ret <= 0)
{
cout << " video_packet_queue empty" << endl;
continue;
}
int ret = avcodec_send_packet(ps->pvideo_codec_ctx, packet);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
continue;
ret = avcodec_receive_frame(ps->pvideo_codec_ctx, pDecodedFrame);
if (ret < 0 && ret != AVERROR_EOF)
continue;
ret = av_hwframe_transfer_data(pFrame,pDecodedFrame, 0);
if (ret < 0)
continue;
//if (got_picture)
{
Uint32 pretimer = SDL_GetTicks();
int ret = sws_scale(img_convert_ctx,
(uint8_t const *const *)pFrame->data,
pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data,
pFrameRGB->linesize);
cout << "sws_scale" << SDL_GetTicks() - pretimer << endl;
//glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, data->codec_ctx->width, data->codec_ctx->height, GL_RGB, GL_UNSIGNED_BYTE, ...);
}
av_packet_unref(packet);
}
使用上述代码,在处理4K视频时 sws_scale 使用的时间较长,请问如何解决。
类似问题
https://stackoverflow.com/questions/50644157/extremely-slow-ffmpeg-sws-scale-only-on-heavy-duty
https://ffmpeg.org/pipermail/libav-user/2015-August/008348.html