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

[Bug]: Looping Video support #28

Closed
3 tasks done
abhiTronix opened this issue Aug 12, 2022 · 1 comment
Closed
3 tasks done

[Bug]: Looping Video support #28

abhiTronix opened this issue Aug 12, 2022 · 1 comment
Assignees
Labels
Bug 🐞 Something's wrong with Deffcode APIs. WIP 🏗️ Work in Progress
Milestone

Comments

@abhiTronix
Copy link
Owner

abhiTronix commented Aug 12, 2022

Description

The DeFFcode's FFdecoder API supports -stream_loop FFmpeg parameter using the -ffprefixes attribute by way of its dictionary parameter for decoding infinite looping video frames using just a single video source. But presently, it fails to identify the given looping source and treat them as one regular video with finite duration. This create unwanted problem where video frames are decoded upto a certain duration only once like a regular video file, and then exits automatically without going for another loop, thus defeating the very purpose.

Issue Checklist

  • I have searched open or closed issues for my problem and found nothing related or helpful.
  • I have read the Documentation and found nothing related to my problem.
  • I've read the Issue Guidelines and wholeheartedly agree.

Expected behaviour

Being able to identify the given looping source and not as regular video file, and API should not exit automatically..

Actual behaviour

It identify the given source as regular video file with finite duration, and it exits automatically without going for another loop.

Steps to reproduce

Run this python given below code in Python Code section and you will see FFdecoder API exiting automatically after given video source duration is over. Also if you check the metadata extracted something similar as follows:

{
  "ffmpeg_binary_path": "C:\\Users\\fo\\AppData\\Local\\Temp\\ffmpeg-static-win64-gpl/bin/ffmpeg.exe",
  "source": "D:\\t.mp4",
  "source_extension": ".mp4",
  "source_video_resolution": [
    1920,
    1080
  ],
  "source_video_framerate": 29.97,
  "source_video_pixfmt": "yuv420p",
  "source_video_decoder": "h264",
  "source_duration_sec": 21.03,
  "approx_video_nframes": 630,
  "source_video_bitrate": "4937k",
  "source_audio_bitrate": "256k",
  "source_audio_samplerate": "48000 Hz",
  "source_has_video": true,
  "source_has_audio": true,
  "source_has_image_sequence": false,
  "output_frames_pixfmt": "bgr24",
  "ffdecoder_operational_mode": "Video-Only"
}

The approx_video_nframes value is 630 which exact value of frames in one regular video file.

Terminal log output

No response

Python Code(Optional)

# import the necessary packages
from deffcode import FFdecoder
import cv2

# define `-stream_loop 3` for looping 3 times
ffparams = {"-ffprefixes":["-stream_loop", "3"]}

# initialize and formulate the decoder with suitable source
decoder = FFdecoder("foo.mp4", frame_format="bgr24", verbose=True, **ffparams).formulate()

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

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

    # {do something with the frame here}

    # 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()

DeFFcode Version

0.2.3

Python version

3.7

Operating System version

all

Any other Relevant Information?

No response

@abhiTronix abhiTronix added Bug 🐞 Something's wrong with Deffcode APIs. Needs Triage 🧐 Assign priority to this issue. labels Aug 12, 2022
@abhiTronix abhiTronix self-assigned this Aug 12, 2022
@abhiTronix abhiTronix added WIP 🏗️ Work in Progress and removed Needs Triage 🧐 Assign priority to this issue. labels Aug 12, 2022
@abhiTronix abhiTronix added this to To do in Deffcode v0.2.4 via automation Aug 12, 2022
@abhiTronix abhiTronix added this to the v0.2.4 milestone Aug 12, 2022
@abhiTronix abhiTronix removed this from the v0.2.4 milestone Jan 10, 2023
@abhiTronix abhiTronix added this to To do in Deffcode v0.2.5 via automation Jan 10, 2023
@abhiTronix abhiTronix moved this from To do to In progress in Deffcode v0.2.5 Jan 10, 2023
@abhiTronix abhiTronix moved this from In progress to Done in Deffcode v0.2.5 Jan 10, 2023
@abhiTronix abhiTronix moved this from Done to In progress in Deffcode v0.2.5 Jan 10, 2023
@abhiTronix abhiTronix moved this from In progress to Done in Deffcode v0.2.5 Jan 10, 2023
@abhiTronix abhiTronix added this to the v0.2.5 milestone Jan 10, 2023
abhiTronix added a commit that referenced this issue Jan 10, 2023
- 💬 Now raw-frame numbers revert to null(`None`) whenever any looping is defined through filter(such as `-filter_complex "loop=loop=3:size=75:start=25"`) or prefix(`"-ffprefixes":["-stream_loop", "3"]`).

🔊 FFdecoder: Updated log message.
@abhiTronix
Copy link
Owner Author

Successfully resolved and merged in commit 4a11c34

abhiTronix added a commit that referenced this issue Jan 11, 2023
FFdecoder: 
- 🩹 Added OpenCV compatibility patch for YUV pixel-formats. (Fixes #30)
  - ⚡ Implemented new patch for handling YUV pixel-formats(such as `YUV420p`, `yuv444p`, `NV12`, `NV21` etc.) for exclusive compatibility with OpenCV APIs.
    - 📝 Note: Only YUV pixel-formats starting with `YUV` and `NV` are currently supported.
  - ✨ Added new `-enforce_cv_patch` boolean attribute for enabling OpenCV compatibility patch.
  - 🐛 Fixed Zero division bug while calculating `raw_bit_per_component`.
- 🔊 Updated log message.

FFhelper:
- 🎨 Replaced depreciating `Retry` API from `requests.packages` with `requests.adapters`.
- 🚑️ Fixed response.headers returning `content-length` as Nonetype since it may not necessarily have the Content-Length header set.
  - 💬 Reason: The response from gitlab.com  contains a Transfer-Encoding field as `'Transfer-Encoding': 'chunked'`, which means data is sent in a series of chunks, so the Content-Length header is emitted. More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding#Directives

Sourcer: 
  - ✨ Added Looping Video support. (Fixes #28)
    - 💬 Now raw-frame numbers revert to null(`None`) whenever any looping is defined through filter(such as `-filter_complex "loop=loop=3:size=75:start=25"`) or prefix(`"-ffprefixes":["-stream_loop", "3"]`).

Maintenance:
- ♻️ Replaced `raw.github.com` links with GitLab CDN links.
- 🗑️ Removed unused code.

Setup:
- 🔥 Removed unused imports and patches.

Docs: 
- ♻️ Refactored docs for Decoding and Transcoding recipes.
  - 📝 Updated Decoding Video files doc:
    - ✨ Added YUV frames example code for `Capturing and Previewing BGR frames from a video file` recipe.
    - 🚸 Updated text and admonitions.
    - 🔥 Removed depreciated text.
  - 📝 Updated Transcoding Live frames doc:
    - ✨ Added YUV frames example code for `Transcoding video using OpenCV VideoWriter API` recipe.
    - ✨ Added YUV frames example code for `Transcoding lossless video using WriteGear API` recipe.
    - 🚸 Updated text and admonitions.
    - 🔥 Removed depreciated text.
  - 📝 Updated Hardware-Accelerated Video Decoding doc:
    - Updated abstract text.
    - ✨ Added new python dependency block for recipes.
    - ✨ Added new `CUVID-accelerated Hardware-based Video Decoding and Previewing` recipe.
    - ✨ Added new `CUDA-accelerated Hardware-based Video Decoding and Previewing` recipe.
    - 📝 Reflected new OpenCV compatibility patch for YUV pixel-formats in code.
    - 🚸 Updated recipe assumptions.
    - 🧑‍💻 Updated recipe code.
    - 🔥 Removed old recipe.
  - 📝 Updated Hardware-Accelerated Video Transcoding doc:
    - 📄 Updated abstract text.
    - 📄 Updated `Limitation: Bottleneck in Hardware-Accelerated Video Transcoding performance with Real-time Frame processing` passage.
    - ✨ Added new python dependency block for recipes.
    - ✨ Added new `CUDA-accelerated Video Transcoding with OpenCV's VideoWriter API` recipe.
    - ✨ Added new `CUDA-NVENC-accelerated Video Transcoding with WriteGear API` recipe both for consuming BGR and NV12 frames.
    - ✨ Added new `CUDA-NVENC-accelerated End-to-end Lossless Video Transcoding with WriteGear API` recipe which is still WIP(💬confirmed with a GIF from tenor).
    - 📝 Reflected new OpenCV compatibility patch for YUV pixel-formats in code.
    - 🚸 Updated recipe assumptions.
    - 🧑‍💻 Updated recipe code.
    - 🔥 Removed old recipe and unnecessary text.
  - 📝 Updated FFdecoder `params.md`:
    - ✨ Added docs for `-enforce_cv_patch` boolean attribute in `ffparam` dictionary parameter.
    -🔥 Removed depreciated text.
    - ✏️ Fixed typos.
- 📝 Added docs for Looping Video support.
  - ✨ Added new `Capturing and Previewing frames from a Looping Video` recipe using `-stream_loop` option and `loop` filter".
  - 🚸 Updated text and admonitions.
  - 📝 Updated docs hyperlinks in index.md
  - 📝 Updated and corrected docs hyperlinks in ReadMe.md
- 📝 Fixed badges/shields#8671 badge issue in README.md
- 📝 Replaced `raw.github.com` links with GitLab and GH links.
- 💄 Added new `content.code.copy` and `content.code.link` features.
- 💄 Updated `Readme.md` GIF URLs.
- 💄 Updated `Readme.md` banner image URLs.
- 📄 Update Zenodo Badge and BibTex entry.
- 💄 Updated md-typeset text font size to `.75rem`.
- 📝 Updated docs hyperlinks in index.md
- 📝 Updated and corrected docs hyperlinks in ReadMe.md
- 📝 Updated `changelog.md`.
- ✏️ Fixed several typos and minor tweaks.
- ♻️ Refactored custom.css.

CI: 
- 👷 Updated `test_source` to test looping video support.
- 👷 Updated `test_frame_format` test to include `-enforce_cv_patch` boolean attribute.
- 🚑️ CI: Added fix for codecov upload bug (codecov/codecov-action#598).
  - 👷 Updated `codecov-action` workflow to `v3.
  - 👷 Added new `CODECOV_TOKEN` GitHub secret.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐞 Something's wrong with Deffcode APIs. WIP 🏗️ Work in Progress
Projects
Development

No branches or pull requests

1 participant