如何在软件中解码像素格式为AV_PIX_FMT_CUDA的AVFrame?

问题描述 投票:0回答:2

最近,我跟随这个示例(https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_encode.c)使用NVENC编码AVFrame(除其他外,将AV_PIX_FMT_VAAPI和AV_PIX_FMT_CUDA换成h264_vaapi和h264_nvence)。我现在正在尝试解码我​​编码的数据包,并将其转换为AV_PIX_FMT_YUV420P,如下所示:

AVFrame *frame;
AVCodecContext *context;
AVCodec *codec;

avcodec_register_all();
codec = avcodec_find_decoder(AV_CODEC_ID_H264);

// allocate and set ffmpeg context
context = avcodec_alloc_context3(decoder->codec);

// open capture decoder
avcodec_open2(context, codec, NULL);

// alloc frame format
frame = (AVFrame *) av_frame_alloc();
frame->format = AV_PIX_FMT_CUDA;

// Receive AVPacket here ...

int success;
avcodec_decode_video2(context, frame, &success, &packet);

// Convert to YUV420P

struct SwsContext *sws_ctx = NULL;
sws_ctx = sws_getContext(1920, 1080,
          AV_PIX_FMT_YUV420P, 1920, 1080,
          AV_PIX_FMT_YUV420P,
          SWS_BILINEAR,
          NULL,
          NULL,
          NULL);

我无法将AV_PIX_FMT_CUDA传递到sws_ctx,因为它不受支持。我在网上找到的大多数示例都说遵循这个libav示例(https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c)。这里的问题是我的解码计算机上没有NVIDIA GPU,因此无法像本例中那样创建硬件设备。有人对如何将使用“ h264_nvenc”编码的AVFrame转换为YUV420P格式的AVFrame有任何建议吗?谢谢!

ffmpeg libav nvenc
2个回答
0
投票

您不必具有GPU即可解码h264视频。 CPU解码(h264)应该就可以了。您提到的是有关硬件加速解码的信息。没有GPU,没有“硬件加速”解码。


0
投票
  1. 如果可能,请使用VDPAU。只需使用vaapi修改示例即可使用vdpau(进行解码)

© www.soinside.com 2019 - 2024. All rights reserved.