From 3bd2ae5f2394dd725363d66bf85979fa7c02c341 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sun, 28 Apr 2019 14:03:45 -0500 Subject: [PATCH] Integrating VDPAU decoding into libopenshot --- doc/HW-ACCEL.md | 6 ++++++ src/FFmpegReader.cpp | 21 +++++++++++++++++++++ src/examples/Example.cpp | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/doc/HW-ACCEL.md b/doc/HW-ACCEL.md index 34e05e4f..b785a9ce 100644 --- a/doc/HW-ACCEL.md +++ b/doc/HW-ACCEL.md @@ -96,3 +96,9 @@ copied to GPU memory for encoding. That is necessary because the modifications are done by the CPU. Using the GPU for that too will make it possible to do away with these two copies. A possible solution would be to use Vulkan compute which would be available on Linux and Windows natively and on MacOS via MoltenVK. + +## Credit + +A big thanks to Peter M (https://github.com/eisneinechse) for all his work +on integrating hardware accelleration into libopenshot! The community thanks +you for this major contribution! diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 2ea6fcbb..929ddf72 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -186,6 +186,23 @@ static enum AVPixelFormat get_hw_dec_format_cu(AVCodecContext *ctx, const enum A ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::get_hw_dec_format_cu (Unable to decode this file using hardware decode.)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); return AV_PIX_FMT_NONE; } + +static enum AVPixelFormat get_hw_dec_format_vd(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts) +{ + const enum AVPixelFormat *p; + + for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) { + switch (*p) { + case AV_PIX_FMT_VDPAU: + hw_de_av_pix_fmt_global = AV_PIX_FMT_VDPAU; + hw_de_av_device_type_global = AV_HWDEVICE_TYPE_VDPAU; + return *p; + break; + } + } + ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::get_hw_dec_format_vd (Unable to decode this file using hardware decode.)", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1); + return AV_PIX_FMT_NONE; +} #endif #if defined(_WIN32) @@ -377,6 +394,10 @@ void FFmpegReader::Open() { hw_de_av_device_type = AV_HWDEVICE_TYPE_CUDA; pCodecCtx->get_format = get_hw_dec_format_cu; break; + case 6: + hw_de_av_device_type = AV_HWDEVICE_TYPE_VDPAU; + pCodecCtx->get_format = get_hw_dec_format_vd; + break; default: hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI; pCodecCtx->get_format = get_hw_dec_format_va; diff --git a/src/examples/Example.cpp b/src/examples/Example.cpp index 411abdda..80339684 100644 --- a/src/examples/Example.cpp +++ b/src/examples/Example.cpp @@ -36,6 +36,10 @@ using namespace openshot; int main(int argc, char* argv[]) { + Settings *s = Settings::Instance(); + s->HARDWARE_DECODER = 2; // 1 VA-API, 2 NVDEC + s->HW_DE_DEVICE_SET = 1; + FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-720p.mp4"); r9.Open(); r9.DisplayInfo();