Deinterlacing in ffmpeg

泄露秘密 提交于 2019-12-10 10:31:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4165517/deinterlacing-in-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!