Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient link handling with OpenCV's VideoCapture method? {edited}

I'm using python with OpenCV. I was passing an MP4 link to VideoCapture but then I found my code runs ~10X faster (including urllib download time) if I download the video file with urllib.request first and then pass the filename to VideoCapture.

My question is if there is a way to download a video clip (subject to my machine's hardware {and software} constraints) into a capture object and then just let that object get disposed of with the normal python garbage collection when I am done with it?

Saving a video file to disk is slow compared to just loading it into memory. Any suggestions on how to do this with an internet file?

like image 723
DanGoodrick Avatar asked Apr 29 '26 22:04

DanGoodrick


1 Answers

urllib doesn't have to save the downloaded object to disk so all I needed to do was:

import urllib.request
url = 'https://previews.customer.envatousercontent.com/h264-video-previews/f331148f-3aa1-42ff-ae89-1a67274f2bd6/2009010.mp4'
video, http = urllib.request.urlretrieve(url)
cap = cv2.VideoCapture(video)
like image 55
DanGoodrick Avatar answered May 02 '26 11:05

DanGoodrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!