其他分享
首页 > 其他分享> > FFmpeg+dxva2 H265硬解码 下方出现绿条或被下方拉长

FFmpeg+dxva2 H265硬解码 下方出现绿条或被下方拉长

作者:互联网

H265的编码格式,显示下面有一块绿色,并且绿色上面一点有被拉长的现象。

主要原因是缓冲分辨率比视频分辨率多出一点宏块,传入高时减去多出来的宏块数量,或者直接传入视频分辨率即可。

在ffmpeg_dxva2.cpp下

找到dxva2_create_decoder(AVCodecContext *s)中的

    /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
    all coding features have enough room to work with */
    else if (s->codec_id == AV_CODEC_ID_HEVC)
        surface_alignment = 128;
    else
        surface_alignment = 16;

以及

   hr = ctx->decoder_service->CreateSurface(FFALIGN(s->coded_width, surface_alignment),
       FFALIGN(s->coded_height, surface_alignment),
       ctx->num_surfaces - 1,
       target_format, D3DPOOL_DEFAULT, 0,
       DXVA2_VideoDecoderRenderTarget,
       ctx->surfaces, NULL);

修改为:

该处只针对1080p和720p做处理,其他也一样,可以用vlc查看编解码器信息,根据缓冲分辨率的高进行修改
其他分辨率直接抛弃处理,不做填充。

    /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
    all coding features have enough room to work with */
    //else if (s->codec_id == AV_CODEC_ID_HEVC)
   //     surface_alignment = 128;
   else
   {
   		if(s->coded_height==736)
   		{
   			surface_alignment = 16;
   		}
   		else if(s->coded_height==1088)
   		{
   			surface_alignment = 8;
   		}
   		else
   		{
   			surface_alignment = 0;
   		}
   }
        

以及

将缓冲分辨率减去多出来的宏块

    hr = ctx->decoder_service->CreateSurface(FFALIGN(s->coded_width, surface_alignment),
        FFALIGN(s->coded_height-surface_alignment, surface_alignment),
        ctx->num_surfaces - 1,
        target_format, D3DPOOL_DEFAULT, 0,
        DXVA2_VideoDecoderRenderTarget,
        ctx->surfaces, NULL);

 
}

也可直接传入视频分辨率

    hr = ctx->decoder_service->CreateSurface(FFALIGN(s->coded_width, surface_alignment),
        FFALIGN(s->height, surface_alignment),
        ctx->num_surfaces - 1,
        target_format, D3DPOOL_DEFAULT, 0,
        DXVA2_VideoDecoderRenderTarget,
        ctx->surfaces, NULL);

 
}

标签:surfaces,FFALIGN,FFmpeg,H265,ctx,surface,coded,下方,alignment
来源: https://blog.csdn.net/weixin_44520287/article/details/117422989