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

How to use nvdec/nvenc #395

Closed
4 tasks done
johnnynunez opened this issue Apr 28, 2024 · 7 comments
Closed
4 tasks done

How to use nvdec/nvenc #395

johnnynunez opened this issue Apr 28, 2024 · 7 comments
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response.

Comments

@johnnynunez
Copy link

Issue guidelines

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 have gone through the Bonus Examples and FAQs and found nothing related or helpful.

Describe your Question

I am trying to make a yolo detector using mp4 video or real time camera. I am trying to speed up my pipeline because the fps of the model is much higher than the video and the fps marked. How can I use hardware e.g. nvenc and nvenc to encode and decode the video?
I have opencv and ffmpeg with cuda. The device is a jetson agx orin

Terminal log output(Optional)

No response

Python Code(Optional)

No response

VidGear Version

0.3.2

Python version

3.11

Operating System version

Ubuntu 22.04

Any other Relevant Information?

No response

@johnnynunez johnnynunez added the QUESTION ❓ User asked about the working/usage of VidGear APIs. label Apr 28, 2024
Copy link

welcome bot commented Apr 28, 2024

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

  • Read our Issue Guidelines, and update your issue accordingly. Please note that your issue will be fixed much faster if you spend about half an hour preparing it, including the exact reproduction steps and a demo.
  • Go comprehensively through our dedicated FAQ & Troubleshooting section.
  • For any quick questions and typos, please refrain from opening an issue, as you can reach us on Gitter community channel.

@abhiTronix
Copy link
Owner

abhiTronix commented Apr 28, 2024

I am trying to make a yolo detector using mp4 video or real time camera. I am trying to speed up my pipeline because the fps of the model is much higher than the video and the fps marked. How can I use hardware e.g. nvdec and nvenc to encode and decode the video?
I have opencv and ffmpeg with cuda. The device is a jetson agx orin

@johnnynunez Don't use OpenCV for video IO, but FFmpeg directly which supports both nvenc and nvenc to encode and decode the video. For this purpose, You could use my deffcode library instead which will be integrated soon in #148. The complete HW transcoding example is given in this docs: https://abhitronix.github.io/deffcode/latest/recipes/advanced/transcode-hw-acceleration/#hardware-accelerated-video-transcoding

Goodluck!

@abhiTronix abhiTronix added SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response. labels Apr 28, 2024
@johnnynunez
Copy link
Author

johnnynunez commented Apr 28, 2024

I am trying to make a yolo detector using mp4 video or real time camera. I am trying to speed up my pipeline because the fps of the model is much higher than the video and the fps marked. How can I use hardware e.g. nvenc and nvenc to encode and decode the video?
I have opencv and ffmpeg with cuda. The device is a jetson agx orin

@johnnynunez Don't use OpenCV for video IO, but FFmpeg directly which supports both nvenc and nvenc to encode and decode the video. For this purpose, You could use my deffcode library instead which will be integrated soon in #148. The complete HW transcoding example is given in this docs: https://abhitronix.github.io/deffcode/latest/recipes/advanced/transcode-hw-acceleration/#hardware-accelerated-video-transcoding

Goodluck!

but Does it have threaded-queue-mode too?? https://abhitronix.github.io/vidgear/v0.3.2-stable/bonus/TQM/#threaded-queue-mode

class FrameCapture:
    def __init__(self, source=0, stabilize=False, stream_mode=False, logging=False):
        self.source = source
        if isinstance(self.source, int):
            # Use CamGear for optimized live stream handling
            self.vcap = CamGear(source=self.source, stream_mode=stream_mode, logging=logging)
            height, width, _ = self.vcap.frame.shape
            self.fps = self.vcap.framerate
        else:
            # Use VideoGear for general video file handling
            self.vcap = VideoGear(source=self.source, stabilize=stabilize, stream_mode=stream_mode, logging=logging)
            height, width, _ = self.vcap.stream.frame.shape
            self.fps = self.vcap.stream.framerate
        self.video_info = sv.VideoInfo.from_video_path(self.source)
        self.frame_count = 0
        self.frame_size = (width, height)
        self.stopped = False

    def start(self):
        self.stopped = False
        self.vcap.start()

    def read(self):
        if not self.stopped:
            frame = self.vcap.read()
            if frame is None:
                self.stop()
                return None
            self.frame_count += 1
            return frame
        return None

    def get_frame_count(self):
        return self.frame_count

    def get_fps(self):
        return self.fps

    def get_frame_size(self):
        return self.frame_size

    def get_stop(self):
        return self.stopped

    def stop(self):
        # Safely close the video stream
        self.frame_count = 0
        # self.vcap.release()
        self.vcap.stop()
        self.stopped = True


if __name__ == '__main__':
    # Example usage:
    stream = FrameCapture(0)  # 0 for default webcam
    stream.start()

    try:
        input("Press Enter to stop...")
    finally:
        stream.stop()
        print("Exiting program")

@abhiTronix
Copy link
Owner

You don't need multi-threading here.

@johnnynunez
Copy link
Author

You don't need multi-threading here.

and deffcode uses queue? Or only decoding?

@abhiTronix
Copy link
Owner

and deffcode uses queue? Or only decoding?

@johnnynunez No queue, just decoding. You could learn more about it here: https://abhitronix.github.io/deffcode/latest/recipes/advanced/decode-hw-acceleration/#hardware-accelerated-video-decoding

@johnnynunez
Copy link
Author

and deffcode uses queue? Or only decoding?

@johnnynunez No queue, just decoding. You could learn more about it here: https://abhitronix.github.io/deffcode/latest/recipes/advanced/decode-hw-acceleration/#hardware-accelerated-video-decoding

Yeah it is working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING FOR RESPONSE ⏳ Waiting for the user response.
Projects
None yet
Development

No branches or pull requests

2 participants