abhiTronix/deffcode

[Bug]: Looping Video support

Closed this issue · 1 comments

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

Successfully resolved and merged in commit 4a11c34