ffmpeg을 사용하여 동영상을 돌리고 있습니다.
디코딩하여 비트맵을 가져올 때, 어떤 동영상은 너무 속도가 빠르고, 어떤 동영상은 너무 느립니다.
ffmpeg으로 동영상을 재생할 때 1초 정도가 실제 시간 1.5초, 2초까지 느려지는 경우가 생깁니다.
h.264를 디코딩할 때 그런다던지 등등..
디코딩을 하는 함수인데, 어느 부분을 건드려주어야 재생 속도를 맞출 수 있을까요?
초당 프레임 수가 다른 것도 원인이 될 듯한데..
조언 부탁드립니다..
int decodeFrame()
{
int frameFinished = 0;
AVPacket packet;
while (av_read_frame(gFormatCtx, &packet) >= 0) {
testtime = gFrame->display_picture_number;
if (packet.stream_index == gVideoStreamIdx) {
avcodec_decode_video2(gVideoCodecCtx, gFrame, &frameFinished, &packet);
if (frameFinished) {
gImgConvertCtx = sws_getCachedContext(gImgConvertCtx,
gVideoCodecCtx->width, gVideoCodecCtx->height, gVideoCodecCtx->pix_fmt,
gVideoCodecCtx->width, gVideoCodecCtx->height, PIX_FMT_RGB565LE, SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(gImgConvertCtx, gFrame->data, gFrame->linesize, 0, gVideoCodecCtx->height, gFrameRGB->data, gFrameRGB->linesize);
av_free_packet(&packet);
return 0;
}
}
av_free_packet(&packet);
}
return -1;
}