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

✨ [v0.2.1] Implement support for live input devices/sources. (Fixes #16) #17

Merged
merged 76 commits into from
Jul 14, 2022

Conversation

abhiTronix
Copy link
Owner

@abhiTronix abhiTronix commented Jul 8, 2022

Brief Description

Added support for Live-Device Inputs such as Webcams, Screen-capture, virtual webcams will be added to DeFFcode.

PR Key features:

✨ New Features

  • Sourcer API:
    • Implemented support for extracting metadata from live input devices/sources.
    • Added new source_demuxer and forced_validate parameters to validate_source internal method.
    • Implemented logic to validate source_demuxer value against FFmpeg supported demuxers.
    • Rearranged metadata dict.
    • Updated Code comments.
  • FFdecoder API:
    • Implemented functionality to supported live devices by allowing device path and respective demuxer into pipeline.
    • Included -f FFmpeg parameter into pipeline to specify source device demuxer.
    • Added special case for discarding -framerate value with Nonetype.
  • CI:
    • Added new unittest test_camera_capture() to test support for live Virtual Camera devices.
    • Added new v4l2loopback-dkms, v4l2loopback-utils and kernel related APT dependencies.
  • Bash Script:
    • Added new FFmpeg command to extract image datasets from given video on Linux envs.
    • Created live Virtual Camera devices through v4l2loopback library on Github Actions Linux envs.
      • Added v4l2loopback modprobe command to setup Virtual Camera named VCamera dynamically at /dev/video2.
      • Added v4l2-ctl --list-devices command for debugging.
      • Implemented FFmpeg command through nohup(no hangup) to feed video loop input to Virtual Camera in the background.

⚡️ Updates/Improvements

  • Sourcer API:
    • Only either source_demuxer or source_extension attribute can be present in metadata.
    • Enforced forced_validate for live input devices/sources in validate_source internal method.
  • FFdecoder API:
    • Rearranged FFmpeg parameters in pipeline.
    • Removed redundant code.
    • Updated Code comments.
  • FFhelper API:
    • Logged error message on metadata extraction failure.
  • CI:
    • Restricted test_camera_capture() unittest to Linux envs only.
    • Removed return_generated_frames_path() method support for Linux envs.
    • Pinned jinja2 3.1.0 or above breaking mkdocs.
  • Bash Script:
    • Updated to latest FFmpeg Static Binaries links.
      • Updated download links to abhiTronix/ffmpeg-static-builds * hosting latest available versions.
      • Updated date/version tag to 12-07-2022.
      • Removed depreciated binaries download links and code.
  • Setup:
    • Bumped version to 0.2.1.
  • Docs:
    • Updated Roadmap in README.md

💥 Updates/Changes

  • Implement support for live input devices/sources.
    • source parameter now accepts device name or path.
    • Added source_demuxer parameter to specify demuxer for live input devices/sources.
    • Implemented Automated inserting of -f FFmpeg parameter whenever source_demuxer is specified by the user.

🐛 Bug-fixes

  • Sourcer API:
    • Fixed Nonetype value bug in source_demuxer assertion logic.
    • Fixed typos in parameter names.
    • Added missing import.
  • FFhelper API:
    • Logged error message on metadata extraction failure.
    • Fixed bug with get_supported_demuxers not detecting name patterns with commas.
    • Removed redundant logging.
  • CI:
    • Fixed critical permission bug causing v4l2loopback to fail on Github Actions Linux envs.
      • Elevated privileges to root by adding sudo to all commands(including bash scripts and python commands).
      • Updated vidgear dependency to pip install from its git testing branch with recent bug fixes.
      • Replaced relative paths with absolute paths in unit tests.
    • Fixed WriteGear API unable to write frames due to permission errors.
    • Fixed test_source_playback() test failing on Darwin envs with OLD FFmpeg binaries.
      • Removed custom_ffmpeg value for Darwin envs.
    • Fixed various naming typos.
    • Fixed missing APT dependencies.

Requirements / Checklist

  • I have read the DeFFcode PR Guidelines.
  • I have read the DeFFcode Documentation.
  • I have updated the documentation files accordingly(if required).

Related Issue

#16

Context

The crucial VideoCapture support for live(realtime) device inputs(such as Webcams, Screen-capture, virtual webcams etc.) are still missing from Deffcode. This PR will implementation this functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Miscellaneous (if available):

Example code for real-time screen-capturing on windows:

# import the necessary packages
from deffcode import FFdecoder
import cv2

# initialize and formulate the decoder for BGR24 output
decoder = FFdecoder("desktop", source_demuxer="gdigrab", frame_format="bgr24", verbose=True).formulate()

# grab the RGB24(default) frame from the decoder
for frame in decoder.generateFrame():

    # check if frame is None
    if frame is None:
        break

    # Show output window
    cv2.imshow("Output", frame)

    # check for 'q' key if pressed
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

# close output window
cv2.destroyAllWindows()
# terminate the decoder
decoder.terminate()

…sources. (#16)

- ⚡️ Implemented support for extracting metadata from live input devices/sources.
- 🚧 `source` parameter now accepts device name or path.
- 🚩 Added `source_demuxer` parameter to specify demuxer for live input devices/sources.
- ✨ Added new `source_demuxer` and `forced_validate` parameters to `validate_source` internal method.
- 🥅 Implemented logic to validate `source_demuxer` value against available demuxers.
- 🚩 Included `-f` FFmpeg parameter into pipeline to specify source device demuxer.
… in metadata.

- 🎨 Only either `source_demuxer` or `source_extension` attribute can be present in metadata.
- 🚩 Added `source_demuxer` parameter to specify demuxer for live input devices/sources.
- 🚧 Implemented functionality to supported live devices by allowing device path and respective demuxer into pipeline.
- ✨ Automated inserting of `-f` FFmpeg parameter whenever `source_demuxer` is specified by the user.
- ✏️ Fixed typos in parameter names.
- 🔥 Removed redundant code.
- 🎨 Minor tweaks in code formatting.
@abhiTronix abhiTronix self-assigned this Jul 8, 2022
@abhiTronix abhiTronix added Enhancement ⚡ New feature Issue/Request enhancing DeFFcode APIs. WIP 🏗️ Work in Progress Idea 💡 New ideas for improving or enhancing DeFFcode APIs. labels Jul 8, 2022
@abhiTronix abhiTronix added this to In progress in Deffcode v0.2.1 via automation Jul 8, 2022
@abhiTronix abhiTronix added this to the v0.2.1 milestone Jul 8, 2022
@abhiTronix abhiTronix linked an issue Jul 8, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #17 (a22465f) into master (f3a9e74) will decrease coverage by 0.13%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   96.21%   96.08%   -0.14%     
==========================================
  Files           6        6              
  Lines         582      587       +5     
==========================================
+ Hits          560      564       +4     
- Misses         22       23       +1     
Impacted Files Coverage Δ
deffcode/version.py 100.00% <ø> (ø)
deffcode/ffdecoder.py 90.90% <40.00%> (-0.97%) ⬇️
deffcode/ffhelper.py 100.00% <100.00%> (ø)
deffcode/sourcer.py 98.11% <100.00%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3a9e74...a22465f. Read the comment docs.

- ✅ Added new `test_cameradevice` to test FFdecoder's webcam playback capabilities.
- ✨ Added `array_data` to generate random data of given frame-size and frame number.
- ➕ Added `pyvirtualcam` pip dependency.
- ➕ Added `v4l2loopback-dkms` apt dependency.
- 🥅 `test_cameradevice` will be enabled for Linux platforms only.
- 🚧 Added necessary imports.
- Added `v4l2-ctl` command for debugging.
@abhiTronix
Copy link
Owner Author

Finally it worked. FK U v4l2loopback. 🖕🏽

@abhiTronix abhiTronix changed the title ✨ [WIP] Implement support for live input devices/sources. (Fixes #16) ✨ [v0.2.1] Implement support for live input devices/sources. (Fixes #16) Jul 14, 2022
@abhiTronix abhiTronix merged commit df7568e into master Jul 14, 2022
Deffcode v0.2.1 automation moved this from In progress to Done Jul 14, 2022
@abhiTronix abhiTronix deleted the dev branch July 14, 2022 09:27
@abhiTronix abhiTronix added Solved 🥅 Final goal achieved. and removed WIP 🏗️ Work in Progress labels Jul 14, 2022
@abhiTronix abhiTronix mentioned this pull request Jul 19, 2022
@abhiTronix abhiTronix linked an issue Aug 8, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ⚡ New feature Issue/Request enhancing DeFFcode APIs. Idea 💡 New ideas for improving or enhancing DeFFcode APIs. Solved 🥅 Final goal achieved.
Projects
Development

Successfully merging this pull request may close these issues.

[Meta]: Roadmap Ahead [Idea]: Add Live-Device Inputs support
1 participant