在ffmpeg中反交错

Utk*_*nha 3 video ffmpeg video-processing

我按照这里的教程将视频文件加载到C程序中.但帧不是去隔行扫描.

从我所看到的,ffmpeg可执行文件支持-deinterlace开关.我怎么在代码中这样做?我应该阅读哪些库/功能?

Jas*_*n B 5

您必须手动调用avpicture_deinterlace以解交织每个解码帧.函数定义可以在这里找到.它基本上看起来像这样(使用教程第一页中的变量):

avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                     packet.data, packet.size);

if(frameFinished) {
    avpicture_deinterlace((AVPicture*)pDiFrame, 
                          (const AVPicture*)pFrame, 
                          pCodecCtx->pix_fmt, 
                          width, 
                          height);
     . 
     . 
     .
 }
Run Code Online (Sandbox Code Playgroud)

请记住,您必须通过创建自己的缓冲区和调用来初始化pDiFrame它们pFrameRGB在教程中初始化的方式,avcodec_alloc_frame并且avpicture_fill只有这次像素格式将是解码帧(pCodecCtx->pix_fmt)的格式,而不是24位RGB.

在逐行扫描之后,您可以执行从逐行扫描帧到RGB的转换,如教程中所示.