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

标签 ffmpeg libav nvenc

我最近按照这个示例 (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 有任何建议吗?谢谢!

最佳答案

您不必拥有 GPU 来执行解码 h264 视频。 CPU解码(h264)应该没问题。
你提到的是关于硬件加速解码。没有 GPU 没有“硬件加速”解码。

编码也是如此。您也没有 GPU,软件编解码器 (libx264) 可以正常工作。您可以使用 CPU 或 GPU 对其进行解码。

关于ffmpeg - 如何在软件中解码像素格式 AV_PIX_FMT_CUDA 的 AVFrame?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59806420/

相关文章:

ffmpeg - 如何使用 FFMPEG 向来自网络摄像头 (v4l2) 的实时流添加延迟?

ffmpeg - 无需命令行即可使用 libav?

c++ - 使用非英文文件名调用 avio_open 函数无效

ffmpeg - 直接来自 NVENC 编码器的 RTMP 直播流

visual-studio - amd64 编译器在 Visual Studio 2022 中的位置 |使用 NVENC 编译 FFmpeg

python - 每个 GPU 的 Nvenc session 限制

android - 合并两个音频文件 FFMpeg acodec

windows - FFMPEG(windows7)无法让输出视频显示超过 10 个 jpg 中的 3 个

audio - 如何使用 ffmpeg 将其他一些音频添加到音频的静音部分?

使用 NVENC 时 FFMpeg 质量下降