abhiTronix / deffcode

A cross-platform High-performance FFmpeg based Real-time Video Frames Decoder in Pure Python 🎞️⚡
https://abhitronix.github.io/deffcode
Apache License 2.0
178 stars 3 forks source link

[Question]: How do I capture progress using tqdm while Reading & Writing media from/to file #38

Closed ghost closed 1 year ago

ghost commented 1 year ago

Issue guidelines

Issue Checklist

Describe your Question

Hi DeffCode Team, In the Basic Recipes --->Decoding Video Files Code ,I want to able to see a progress bar while the file was being read but I could not see a way to access the total frames present in the file. I usually use tqdm library to enable progress bars for reading/writing video. For me to implement a manual progress bar in tqdm I need to know the total frames present. In OpenCV I have access to fps and frame count using the code-block given below

    import cv2
    from tqdm.notebook import trange

    vid_capture = cv2.VideoCapture(input_video_path)
    if (vid_capture.isOpened() == False): 
     print("Unable to read video feed")
    input_fps = vid_capture.get(cv2.CAP_PROP_FPS)
    total_frames = int(vid_capture.get(cv2.CAP_PROP_FRAME_COUNT))
    for fno in trange(total_frames,desc="Reading Video",leave=True):
        pass

Could you please point me to a way to achieve the same using deffcode API

Terminal log output(Optional)

No response

Python Code(Optional)

No response

DeFFcode Version

0.2.5

Python version

3.9.16

Operating System version

Linux

Any other Relevant Information?

No response

abhiTronix commented 1 year ago

I could not see a way to access the total frames present in the file.

@avadhut-00 It is in docs, you can easily access number of frames using the approx_video_nframes parameter in metadata: https://abhitronix.github.io/deffcode/latest/recipes/basic/extract-video-metadata/#extracting-video-metadata-using-sourcer-api

# import the necessary packages
from deffcode import Sourcer

# initialize and formulate the decoder using suitable source
sourcer = Sourcer("foo.mp4").probe_stream()

# print `approx_video_nframes` metadata
print(sourcer.retrieve_metadata()["approx_video_nframes"])

I have access to fps

Similarily for FPS you can see source_video_framerate parameter in metadata:

# import the necessary packages
from deffcode import Sourcer

# initialize and formulate the decoder using suitable source
sourcer = Sourcer("foo.mp4").probe_stream()

# print `source_video_framerate` metadata
print(sourcer.retrieve_metadata()["source_video_framerate"])
ghost commented 1 year ago

The solution provided works correctly for tracking progress( via tqdm library ) for reading video files