Deinterlacing in ffmpeg
I've followed the tu开发者_开发问答torial here to load video files into a C program. But the frames aren't deinterlaced.
From what I've seen, the ffmpeg executable supports a -deinterlace switch. How to I do this in code? What library/functions should I read about?
You have to manually call avpicture_deinterlace
to deinterlace each decoded frame. The function definition can be found here. It will basically look like this (using the variables from the first page of the tutorial):
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
packet.data, packet.size);
if(frameFinished) {
avpicture_deinterlace((AVPicture*)pDiFrame,
(const AVPicture*)pFrame,
pCodecCtx->pix_fmt,
width,
height);
.
.
.
}
Keep in mind that you have to initialize pDiFrame
similarly to how they initialize pFrameRGB
in the tutorial by creating your own buffer and calling avcodec_alloc_frame
and avpicture_fill
, only this time the pixel format will be that of the decoded frame(pCodecCtx->pix_fmt
), not 24-bit RGB.
After deinterlacing, you can then perform the conversion from the deinterlaced frame to RGB as it shows in the tutorial.
精彩评论