opencv / opencv/opencv-python

ffmpeg video decode is not hardware accelerated on Windows

Open
#520 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

Expected behaviour

ffmpeg/libavcodec video decoding should be hardware accelerated via D3D11.

Actual behaviour

ffmpeg/libavcodec video decoding is not hardware accelerated.

Steps to reproduce

cap = cv2.VideoCapture('file.mp4')
frame = True
while frame:
frame = cap.read()

Running on Windows 10 x64, Intel Core i7-3520M, Python 3.9, opencv-python 4.5.3.56.
The same test H264 file opened in VLC with D3D11 hardware acceleration via libavcodec at a similar decoding rate uses much less CPU.

Although hwaccels is no longer disabled in the ffmpeg build script (https://github.com/opencv/opencv_3rdparty/commit/7342d31a948774b2a56ccee9015ad36429762d9b#diff-6862fa01d6f0bc4c9601c1a0a9d170cb49cf255b25bfc66a02f958fa47be43a2), D3D11 support is not getting built in the Windows ffmpeg DLLs used with opencv-python.

I suspect the D3D11 headers and libraries need to be added for support to be enabled at the time of ffmpeg compile, and either need to be borrowed from VLC or compiled using MSVC which includes the headers in the Windows SDK, instead of MinGW or gcc cross-compile.

Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the ffmpeg build script at the linked opencv_3rdparty commit and the process that produces the Windows ffmpeg DLLs. Check how D3D11 headers and libraries are supplied during compilation, then reproduce the opencv-python VideoCapture test on Windows. Done means D3D11 hardware decoding is enabled in the produced DLLs and the expected test uses less CPU.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.