- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 GPU 解码 MP4 文件?
我使用 FFmpeg.AutoGen 的演示。
对代码有好处: private static unsafe void DecodeAllFramesToImages()
但这是使用CPU解码。
我想要一个使用 GPU 解码的演示。
我怎样才能做到这一点 ?
这是 FFmpeg.AutoGen 演示:
private static unsafe void DecodeAllFramesToImages()
{
// decode all frames from url, please not it might local resorce, e.g. string url = "../../sample_mpeg4.mp4";
var url = "https://rtmp-luzhi.oss-cn-beijing.aliyuncs.com/eryuan2019/%E5%84%BF%E7%AB%A5%E6%89%8B%E8%B6%B3%E5%8F%A3%E7%97%85%E7%9A%84%E9%98%B2%E6%AD%A2%E4%B8%8E%E6%B2%BB%E7%96%97.mp4"; // be advised this file holds 1440 frames
using (var vsd = new VideoStreamDecoder(url))
{
Console.WriteLine($"codec name: {vsd.CodecName}");
var info = vsd.GetContextInfo();
info.ToList().ForEach(x => Console.WriteLine($"{x.Key} = {x.Value}"));
var sourceSize = vsd.FrameSize;
var sourcePixelFormat = vsd.PixelFormat;
var destinationSize = sourceSize;
var destinationPixelFormat = AVPixelFormat.AV_PIX_FMT_BGR24;
using (var vfc = new VideoFrameConverter(sourceSize, sourcePixelFormat, destinationSize, destinationPixelFormat))
{
var frameNumber = 0;
while (vsd.TryDecodeNextFrame(out var frame))
{
var convertedFrame = vfc.Convert(frame);
using (var bitmap = new Bitmap(convertedFrame.width, convertedFrame.height, convertedFrame.linesize[0], PixelFormat.Format24bppRgb, (IntPtr) convertedFrame.data[0]))
bitmap.Save($"frame.{frameNumber:D8}.jpg", ImageFormat.Jpeg);
Console.WriteLine($"frame: {frameNumber}");
frameNumber++;
}
}
}
}
最佳答案
您需要更改 VideoStreamDecoder 类:
首先你需要配置你的AVCodecContext
使用您机器的 HWDevice。
像这样的东西:
AVCodecHWConfig* config = ffmpeg.avcodec_get_hw_config(codec, 0);
ffmpeg.av_hwdevice_ctx_create(&pCodecContext->hw_device_ctx, HWType, null, null, 0);
HWType
是您的硬件解码器类型。
ffmpeg.av_hwframe_transfer_data(cpuFrame, pFrame, 0)
pFrame
- 从硬件硬件解码器接收的帧
cpuFrame
- 数据复制到的帧。
关于ffmpeg - 如何使用 GPU 使用 ffmpeg.autogen 解码 MP4 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755563/
我正在尝试使用使用 FFmpeg.AutoGen 的 FFMediaToolkit 库。 我遇到了一个错误Invalid data found when processing input调用ffmpe
是否可以在 UWP(通用 Windows 平台)项目上使用 FFmpeg.AutoGen 包? 最佳答案 不,过去一个月我一直在寻找相同的东西,但我没有在 uwp 中直接找到任何支持 FFmpeg.a
我试图调试具有很多依赖关系的Go程序包,试图跟踪依赖关系中的函数调用,以找出错误的根源。 Delve(通过CLI和VSCode GUI调试器)对函数调用进行了一定深度的跟踪,但随后突然拒绝更深入的讨论
我在 linux 上有一个 CMake 项目,我正在使用 ExternalProject构建 Google Protobuf。它工作得很好,但是任何后续构建仍然会调用外部项目中的配置步骤(这很烦人,因
我想从这里使用 FFmpeg.AutoGen 项目:https://github.com/Ruslan-B/FFmpeg.AutoGen 我不熟悉 ffmpeg API,所以我想得到一个如何将音频文件
我正在使用 FFmpeg autogen 将从 PC 实时(60 或 30 fps)捕获的图像流式传输到 Android 应用程序。当我使用 FFmpeg autogen 提供的 h.264 编码示例
我正在尝试在基于 autogen 的项目上使用 CMake ExternalProject_Add 构建 debian。该项目安装到我设置的任何前缀目录(默认为 /usr/local)。问题是,当我在
我在 git 中启动了一个新项目,并使用 ./autogen.sh 和 xfce4-dev-tools 生成配置脚本和其他文件。 我想知道仅提供 git 版本是否是一个坏主意,或者我还需要创建 dis
我正在使用 Eclipse 3.7.2 和 Pydev 2.6 开发 Django 程序。当我将 Django 从 1.3 升级到 1.4.1 时,我发现了一个关于“DJANGO_SETTINGS_M
我已经从 http://libspatialindex.github.com/ 下载了 R 树 由于运行 ./autogen.sh 我找不到文件/文件夹,因此我从下面给出的 github 存储库下载了
我见过很多 tarball 不包含 autogen.sh文件,但我在其他一些压缩包中看到过它。 包含或不包含 autogen.sh 的理由是什么?在 tarball 中? 最佳答案 如果您要从某种发布
我编写了一个视频生成器,可以为 h264 格式 (mp4) 的视频提供版权。当我从我的 Azure 服务流式传输视频时,我看到以下网络流量: 我使用的 AVCodecContext 布局如下: AVC
全部 我在win7中使用了FFmpeg.AutoGen 3.2,vs2015,从FFmpeg复制了一个示例(http://ffmpeg.org/doxygen/trunk/filtering_vide
我正在尝试使用 从我的网络摄像机读取/解码 RTSP 流FFmpeg.AutoGen 库。 当 ffmpeg 尝试通过 UDP 连接时,服务器响应错误。 当我尝试通过 ffmpeg exe 连接时,也
我一直在试验 FFmpeg.AutoGen ( https://github.com/Ruslan-B/FFmpeg.AutoGen ) 包装器。我已经成功地将 MPG 文件从 .NET 流解码为位图
我从其他 Makefile 调用一个 autogen.sh 脚本,而这个 Makefile 是从一个 shell 脚本调用的,如果我在这个更外部的脚本上设置一个变量 VAR,我可以在这个 Makefi
我正在使用 ./autogen.sh --prefix=/usr/ 构建一个 c project配置过程(以及稍后的编译和链接步骤)创建的所有文件都位于我的源文件夹中。 我想告诉你使用不同的文件夹(比
autogen.sh 失败,输出显示我需要更高版本的 autoconf。但事实上我有一个 2.6x autoconf.... 为什么还是失败了? [mirror@home 4]$ ./autogen.
我尝试在 CMakeLists.txt 中设置 ExternalProject_Add, 为此我发现了这个问题: What is the correct usage of CMake EXTERNAL
我正在尝试编写一个 C# 重新流式传输类,它将采用 HLS/m3u8 H264 编码的视频流并将它们重新流式传输为 RTMP H264 编码的视频。 我从简单的传输流记录器示例开始,并能够使其在以下场
我是一名优秀的程序员,十分优秀!