Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal]: Improve ScreenGear capture rate using DXcam (Windows) #316

Closed
ReenigneArcher opened this issue Jun 26, 2022 · 11 comments · Fixed by #365, #367 or #379
Closed

[Proposal]: Improve ScreenGear capture rate using DXcam (Windows) #316

ReenigneArcher opened this issue Jun 26, 2022 · 11 comments · Fixed by #365, #367 or #379
Assignees
Labels
ENHANCEMENT ⚡ New Feature/Addition/Improvement PROPOSAL 📩 A proposal/proposition SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!
Milestone

Comments

@ReenigneArcher
Copy link

ReenigneArcher commented Jun 26, 2022

Brief Description

While mss and pil are capable of decent capture rates, the rate can be greatly improved using DXcam.

DXcam uses the Windows Desktop Duplication API.

Context

Allowing faster capture rates would allow vidgear to capture video game input far more accurately. I was able to achieve capturing frames > 90 fps average as compared to ~30 fps using mss or Pillow.

Your Current Environment

  • VidGear version: 0.2.5
  • Branch: PyPi
  • Python version: 3.9.6
  • Operating System and version: Win 11
@ReenigneArcher ReenigneArcher added the PROPOSAL 📩 A proposal/proposition label Jun 26, 2022
@abhiTronix abhiTronix added ENHANCEMENT ⚡ New Feature/Addition/Improvement UNDER CONSIDERATION 🤔 This issue/PR is under consideration and may be worked on soon. labels Jun 26, 2022
@abhiTronix
Copy link
Owner

@ReenigneArcher Thanks. This looks promising! I'll run some tests and let you know soon.

@abhiTronix abhiTronix self-assigned this Jun 26, 2022
@abhiTronix abhiTronix added the WORK IN PROGRESS 🚧 currently been worked on. label Jun 26, 2022
@ReenigneArcher
Copy link
Author

I don't mean to spam your repo, but I am highly interested in vidgear as it seems like an awesome library with a lot of potential. I'll just put this here for now, although it's a slightly different topic. I can open it in a separate issue/proposal if you prefer.

I've also been looking into screen capture with ffmpeg. I'm not sure how good the performance is as of yet. One advantage is that initial testing (from command line only) actually captures the mouse movement (on windows) which is probably worth investigating it further just for that reason. https://trac.ffmpeg.org/wiki/Capture/Desktop

I've used ffmpy for re-encoding videos in python before, but not yet for screen capture or piping the output.

There's another library that looks interesting for handling ffmpeg streams as well (https://pypi.org/project/python-ffmpeg-video-streaming/). I wasn't able to get it to work but I didn't put in too much effort honestly.

@abhiTronix
Copy link
Owner

abhiTronix commented Jun 26, 2022

I've also been looking into screen capture with ffmpeg. I'm not sure how good the performance is as of yet. One advantage is that initial testing (from command line only) actually captures the mouse movement (on windows) which is probably worth investigating it further just for that reason. https://trac.ffmpeg.org/wiki/Capture/Desktop

That's why I'm working on deffcode. It will replace OpenCV here.

I don't mean to spam your repo, but I am highly interested in vidgear as it seems like an awesome library with a lot of potential. I'll just put this here for now, although it's a slightly different topic. I can open it in a separate issue/proposal if you prefer.

No ffmpeg backend for Videocapture is already opened in #148. So you can't open duplicate issues here.

@abhiTronix abhiTronix added EXTERNAL BUG 👾 Bug caused by external dependent library POSTPONED ⌛ This issue/PR is postponed for later due to some missing resources. and removed WORK IN PROGRESS 🚧 currently been worked on. UNDER CONSIDERATION 🤔 This issue/PR is under consideration and may be worked on soon. labels Jun 27, 2022
@abhiTronix
Copy link
Owner

@ReenigneArcher DXcam cannot employed as ScreenGear backend untill unless ra1nty/DXcam#17 is resolved. Also, we'll have to wait untill DXcam becomes stable. I'll reopen this issue when these problems are fully addressed by DXcam author(s).

@abhiTronix abhiTronix closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2022
@ReenigneArcher
Copy link
Author

Okay, thanks for the update.

You can also install without the test pypi repo.

python -m pip install git+https://github.com/ra1nty/DXcam.git@cd1c36783d206027075309d7a9be89ef5099d10a#egg=dxcam

or latest:
python -m pip install git+https://github.com/ra1nty/DXcam.git@main#egg=dxcam

If you use poetry instead of pip, it's also possible to install directly from git.

@abhiTronix
Copy link
Owner

You can also install without the test pypi repo.

python -m pip install git+https://github.com/ra1nty/DXcam.git@cd1c36783d206027075309d7a9be89ef5099d10a#egg=dxcam

or latest:
python -m pip install git+https://github.com/ra1nty/DXcam.git@main#egg=dxcam

If you use poetry instead of pip, it's also possible to install directly from git.

Yeah I know, but TestPypi test binaries cannot integrate into a stable PyPi project. Furthermore, Pypi is preferred over poetry for vidgear because of its simplicity, and also cloning git repository directly is not a good idea for any stable project. Therefore, DXcam will only be consider as backend only when the ra1nty/DXcam#17 is resolved and it is ready for testing.

@ra1nty
Copy link

ra1nty commented Sep 4, 2022

Hi @abhiTronix , pypi has been release on pypi: https://pypi.org/project/dxcam/0.0.5/
We fixed all the known issues and I can say it's relatively stable now.

@abhiTronix abhiTronix reopened this Sep 5, 2022
@abhiTronix
Copy link
Owner

@ra1nty Thanks, I'll add this to TODO list.

@abhiTronix abhiTronix added WORK IN PROGRESS 🚧 currently been worked on. and removed EXTERNAL BUG 👾 Bug caused by external dependent library POSTPONED ⌛ This issue/PR is postponed for later due to some missing resources. labels Sep 5, 2022
@abhiTronix abhiTronix added this to To do in VidGear v0.3.0 via automation Sep 5, 2022
@abhiTronix abhiTronix added this to the v0.3.0 milestone Sep 5, 2022
@abhiTronix
Copy link
Owner

abhiTronix commented Jan 7, 2023

@ReenigneArcher @ra1nty This issue is resolved on my local machine, and it is working great 😃. But until ra1nty/DXcam#45 is resolved, the changes cannot be commit into vidgear. Looking forward to it.

@abhiTronix abhiTronix added WAITING FOR RESPONSE ⏳ Waiting for the user response. PARTIALLY RESOLVED ⌛ This issue is partially resolved through a temporary solution. and removed WORK IN PROGRESS 🚧 currently been worked on. labels Jan 7, 2023
@ReenigneArcher
Copy link
Author

Fantastic news. Thank you for your efforts!

@abhiTronix abhiTronix removed the WAITING FOR RESPONSE ⏳ Waiting for the user response. label Jan 26, 2023
@abhiTronix abhiTronix added WORK IN PROGRESS 🚧 currently been worked on. and removed PARTIALLY RESOLVED ⌛ This issue is partially resolved through a temporary solution. labels Jan 26, 2023
@abhiTronix abhiTronix modified the milestones: v0.3.0, v0.3.1 Jan 26, 2023
@abhiTronix abhiTronix moved this from To do to In progress in VidGear v0.3.0 Jan 26, 2023
@abhiTronix abhiTronix removed this from In progress in VidGear v0.3.0 Jan 26, 2023
@abhiTronix abhiTronix added this to To do in VidGear v0.3.1 via automation Jan 26, 2023
@abhiTronix abhiTronix moved this from To do to In progress in VidGear v0.3.1 Jan 26, 2023
abhiTronix added a commit that referenced this issue Jun 14, 2023
- 🎉 Added initial `dxcam` support for Windows machines. (Fixes #316)
  - ✨ Implemented complete workflow for dxcam backend.
  - 🏗️ `dxcam` is now the default backend for Windows machine.
  - ✨ Added support for tuple value in monitor to specify device and output indexes as `(int[device_idx], int[output_idx])` in dxcam backend only.
    - 🧑‍💻 `int` index is also allowed as value for selecting device index.
  - ⚡️ Added support for variable screen dimensions, to capture an area from screen.
  - 🚩 Added `dxcam_target_fps` optional flag to control target fps in dxcam. Defaults to `0`(disabled).
  - ⚡️ RGB frames from dxcam is converted into BGR automatically.
  - ⚡️ For better performance, `video_mode` is enabled by default.
  - ➕ Added necessary imports.
  - ♻️ Refactored code blocks to ensure backward compatibility.
- 💥 Enforced threaded queue mode is now removed completely, there might be boost in performance.
  - 💬 Reason: The IO is automatically blocked by screen refresh rate, so adding overhead of maintaining separate queue is pointless.
  - 💥 Removed `THREAD_TIMEOUT` optional flag.
  - 🔥 Cleaned related unused imports and code blocks.
  - 🍻 Note: Multi-Threading is still there.
- 🎨 Implemented short-circuiting.
- 🔊 Improved logging.
- ✏️ Fixed comment typos.
@abhiTronix abhiTronix linked a pull request Jul 4, 2023 that will close this issue
6 tasks
abhiTronix added a commit that referenced this issue Jul 6, 2023
- 🎉 Added initial `dxcam` support for Windows machines.
  - ✨ Implemented a complete workflow for the `dxcam` backend.
  - 🏗️ `dxcam` is now the default backend for Windows machines.
  - ✨ Added support for tuple values in the monitor parameter to specify device and output indexes as `(int[device_idx], int[output_idx])` in the `dxcam` backend only.
    - 🧑‍💻 `int` index is also allowed as a value for selecting device index.
  - ⚡️ Added support for variable screen dimensions to capture an area from the screen.
  - 🚩 Added the optional flag `dxcam_target_fps` to control the target fps in `dxcam`. Defaults to `0` (disabled).
  - ⚡️ RGB frames from `dxcam` are automatically converted into BGR.
  - ⚡️ For better performance, `video_mode` is enabled by default.
  - ➕ Added necessary imports.
  - ♻️ Refactored code blocks to ensure backward compatibility.
  
- 💥 Enforced threaded queue mode is now completely removed, resulting in a potential performance boost.
  - 💬 Reason: The IO is automatically blocked by the screen refresh rate, so adding the overhead of maintaining a separate queue is pointless.
  - 💥 Removed the `THREAD_TIMEOUT` optional flag.
  - 🔥 Cleaned up unused imports and code blocks.
  - 🍻 Note: Multi-Threading is still available.

- 🏗️ Enforced `dxcam` backend (if installed) when `monitor` is defined on Windows machines.
- 🐛 Fixed backend not defined while logging.

Docs:
- 📝 Added docs for controlling Chunk size in HLS stream. (Fixes #359)
  - 🎨 Fixed context and added separate methods for controlling Chunk size in HLS and DASH streams.
- ⚡️ Updated docs for ScreenGear with respect to recent changes.
  - 🧑‍💻 Updated usage example docs, added new relevant information, updated requirements.
- ✨ Added `dxcam` API specific prerequisites for ScreenGear API when installing on Windows via pip.
- ♻️ Refactored `monitor` and `backend` parameters docs of ScreenGear API.
- 📝 Added a new description for ScreenGear API.
- 🗑️ Removed ScreenGear from Threaded Queue Mode docs.
- 🎨 Updated ScreenGear FAQs.
- ✨ Added new hyperlinks.
- 🔥 Cleaned redundant code.

Setup.py:
- ⬆️ Added `dxcam` dependency in `core` and `asyncio` extra requires.
- 📌 Pinned mss==7.0.1.
  - 🚑️ Starting from version `8.0.0`, the python-mss library dropped support for Python `3.7`, so as a temporary measure, it has been pinned to version `7.0.1`.

Helper: 
- ⚡️ Added multiple server support for downloading assets.
  - 🧑‍💻 Added GitHub server to the `generate_webdata` method to make it more robust for rate limits and other shortcomings.
    - 🩹 Now, the `generate_webdata` method will retry a different server when one fails.

Maintenance:
- 🗑️ Removed unused imports.
- 🎨 Implemented short-circuiting.
- 🔊 Improved logging.
- ✏️ Fixed comment typos.
- 💡 Updated comments.

CI: 
- 🐛 Fixed m3u8 module failing to recognize Windows paths in ScreenGear tests.
- 🚑️ Fixed a path bug by replacing the absolute file path with the decoded file content as a string in its `loads()` function.
@abhiTronix
Copy link
Owner

@ReenigneArcher Sorry for the delay. The support for DXcam backend has been added in commit 612dee0 and will be available in next release. 🎉

VidGear v0.3.1 automation moved this from In progress to Done Jul 6, 2023
@abhiTronix abhiTronix added SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! and removed WORK IN PROGRESS 🚧 currently been worked on. labels Jul 6, 2023
@abhiTronix abhiTronix pinned this issue Jul 6, 2023
@abhiTronix abhiTronix linked a pull request Jul 9, 2023 that will close this issue
6 tasks
@abhiTronix abhiTronix linked a pull request Sep 10, 2023 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ENHANCEMENT ⚡ New Feature/Addition/Improvement PROPOSAL 📩 A proposal/proposition SOLVED 🏁 This issue/PR is resolved now. Goal Achieved!
Projects
No open projects
3 participants