我最近遵循了这个示例(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有任何建议吗?谢谢!
答案 0 :(得分:0)
您不必具有GPU即可执行h264视频的解码。 CPU解码(h264)应该就可以了。 您提到的是有关硬件加速解码的信息。没有GPU,没有“硬件加速”解码。
编码也一样。您也没有GPU,软件编解码器(libx264)可以正常工作。您可以使用CPU或GPU对其进行解码。
答案 1 :(得分:0)
如果可能,请使用VDPAU。只需使用vaapi修改示例即可与vdpau一起使用(进行解码)
如果要使用NVIDIA的编解码器,则可以按名称使用编解码器搜索,例如h264_cuvid,并像普通编解码器一样使用它。例如“ h264_cuvid”