Utkarsh Sinha
Utkarsh Sinha

Reputation: 3305

Deinterlacing in ffmpeg

I've followed the tutorial 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?

Upvotes: 3

Views: 9391

Answers (1)

Jason B
Jason B

Reputation: 12975

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.

Upvotes: 5

Related Questions