Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV loading video in the memory

Tags:

c++

opencv

when using cv::VideoCapture to read video from the disk, what does exactly happens?

  1. Reading the whole file in the memory then decoding it frame by frame?
  2. Fetch frame by frame directly for the disk?

If the second option is the answer, is it possible to do it in the first way?

like image 382
Humam Helfawi Avatar asked Oct 21 '25 03:10

Humam Helfawi


1 Answers

To accomplish this in Python on Linux, I simply made a copy of the input file to /dev/shm, which is a RAM-backed filesystem.

tempdir = tempfile.TemporaryDirectory(dir='/dev/shm')
copypath = os.path.join(tempdir.name, os.path.basename(args.video))
shutil.copy(args.video, copypath)
args.video = copypath

Of course there is the cost of the copy operation as well but it shouldn't be much more than simply reading the entire file (since there is no slow disk that's being written to on the other side of the copy).

like image 108
rgov Avatar answered Oct 22 '25 18:10

rgov



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!