-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Comments
Thanks for opening this issue, a maintainer will get back to you shortly! In the meantime:
|
@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") |
You don't need multi-threading here. |
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 |
Issue guidelines
Issue Checklist
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
The text was updated successfully, but these errors were encountered: