def __init__(self, videoFileName, debug=False): # cv2.VideoCapture.__init__(self, videoFileName) # Does not work on my machine! \Quick fix using VideoCapture from skvideo VideoCapture.__init__(self, videoFileName) # Sub-class attributes self._debug = debug self.videoFileName = videoFileName self.nbFrames = self.info['streams'][0]['nb_frames'] self.fps = int( np.round(self.nbFrames / float(self.info['format']['duration'])))
def __init__(self, videoFileName, debug=False): # cv2.VideoCapture.__init__(self, videoFileName) # Does not work on my machine! \Quick fix using VideoCapture from skvideo VideoCapture.__init__(self, videoFileName) # Sub-class attributes self._debug = debug self.videoFileName = videoFileName self.nbFrames = self.info['streams'][0]['nb_frames'] self.fps = int(np.round(self.nbFrames/float(self.info['format']['duration']))) # self.timeRef = None # in datetime
def GetFrames(fileName, redFact=0.5, skipLength=1, debug=False): ''' returns numpy array of frames ''' cap = VideoCapture(fileName) cap.open() frameList = [] cnt = -1 if debug: print "Started creating Frame List" while True: retval, image = cap.read() cnt = (cnt + 1) % skipLength if (cnt != 0): continue if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:, :, ::-1] image = np.array(image, dtype=np.uint8) frameList.append(image) cap.release() if debug: print "Finished creating Frame List" frameList = np.array(frameList) return frameList
def GetFrames(fileName, redFact = 0.5, skipLength = 1, debug = False): ''' returns numpy array of frames ''' cap = VideoCapture(fileName) cap.open() frameList = [] cnt = -1 if debug: print "Started creating Frame List" while True: retval, image = cap.read() cnt = (cnt+1)%skipLength if (cnt != 0): continue if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:,:,::-1] image = np.array(image, dtype = np.uint8) frameList.append(image) cap.release() if debug: print "Finished creating Frame List" frameList = np.array(frameList) return frameList
def PlayVideo(fileName, redFact=0.5): ''' Plays video using opencv functions Press 'q' to stop in between returns None ''' cap = VideoCapture(fileName) cap.open() while True: retval, image = cap.read() print len(image), len(image[0]) if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:, :, ::-1] cv2.imshow('frame', image) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
def test_on_video(net, vid_fn, out_fn): # capture cap = VideoCapture(vid_fn) ret, img = cap.read() # writer orig_shape = (227, 227) # img.shape wri = VideoWriter(out_fn, frameSize=(orig_shape[1], orig_shape[0])) wri.open() frame = 0 while cap.isOpened(): ret, img = cap.read() if ret: img = draw_joints(img, net) # img = cv.resize(img, (orig_shape[1], orig_shape[0])) wri.write(img) frame += 1 print frame else: print 'finished' break cap.release() wri.release()
def PlayVideo(fileName, redFact = 0.5): ''' Plays video using opencv functions Press 'q' to stop in between returns None ''' cap = VideoCapture(fileName) cap.open() while True: retval, image = cap.read() print len(image), len(image[0]) if not retval: break image = cv2.resize(image, None, fx=redFact, fy=redFact) image = image[:,:,::-1] cv2.imshow('frame',image) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
from skvideo.io import VideoCapture import sys filename = sys.argv[1] cap = VideoCapture(filename) print(str(cap.get_info())) cap.open() retval, image = cap.read() frame_num = 0 import numpy import pygame while True: retval, image = cap.read() if not retval: print("done") sys.exit() surface = pygame.surfarray.make_surface(image) surface = pygame.Surface((100, 100)) numpy_surface = numpy.frombuffer(surface.get_buffer())
from skvideo.io import VideoCapture import sys import matplotlib.pyplot as plt import matplotlib.animation as animation filename = sys.argv[1] cap = VideoCapture(filename) print(str(cap.get_info())) cap.open() retval, image = cap.read() plt_fig = plt.figure() plt_image = plt.imshow(image) frame_num = 0 def updatefig(*args): global cap, frame_num retval, image = cap.read() if not retval: print("done") sys.exit() print("frame %d" % (frame_num)) frame_num += 1
from skvideo.io import VideoCapture, VideoWriter import sys cap_filename, wr_filename = sys.argv[1], sys.argv[2] cap = VideoCapture(cap_filename) cap.open() print str(cap.get_info()) retval, image = cap.read() wr = VideoWriter(wr_filename, 'H264', 30, (image.shape[1], image.shape[0])) wr.open() frame_num = 0 while True: retval, image = cap.read() if not retval: break wr.write(image) print "frame %d" % (frame_num) frame_num += 1 wr.release() cap.release() print "done"
from skvideo.io import VideoCapture cap = VideoCapture(filename) cap.open() while True: retval, image = cap.read() # image is a numpy array containing the next frame # do something with image here if not retval: break
from __future__ import print_function from __future__ import division from skvideo.io import VideoCapture from skvideo.metrics import ssim, psnr, vifp import sys import json filename1, filename2 = sys.argv[1], sys.argv[2] cap1 = VideoCapture(filename1) cap1.open() print(str(cap1.get_info())) cap2 = VideoCapture(filename2) cap2.open() print(str(cap2.get_info())) def rgb_to_y(img): return 0.299 * img[:,:,0] + 0.587 * img[:,:,1] + 0.114 * img[:,:,2] frame_num = 0 while True: retval1, image1 = cap1.read() retval2, image2 = cap2.read() if not retval1 and not retval2: break elif not retval1 or not retval2: print("error: input files have different number of frames") break
# from https://stackoverflow.com/questions/44309437/python-store-video-as-hdf5-results-in-large-file-size ABANDONED import h5py from skvideo.io import VideoCapture frames = [] cap = VideoCapture( 'C:/Users/rldun/Videos/20180925_RLD/10fps about 3p2 aperture, upside down, autoexpos, uncompressed/tierpsy/002 light block on-09252018144815-0000.avi' ) cap.open() it = 0 while True: retval, image = cap.read() if image != None: frames.append(image) it += 1 if (it % 500 == 0): print('Processed %d frames so far' % (it)) if not retval: break with h5py.File('C:/Users/rldun/Desktop/test.hdf5', 'w') as h5File: h5File.create_dataset('camera1', data=frames, compression='gzip', compression_opts=9) # Initialize your dataset with the first image: myDataSet = myFile.create_dataset('someName',
from __future__ import print_function from __future__ import division from skvideo.io import VideoCapture import sys filename = sys.argv[1] cap = VideoCapture(filename) frame_num = 0 cap.open() while True: retval, image = cap.read() if not retval: break print("frame %d" % (frame_num)) frame_num += 1 cap.release() print("done")
# Define the memory graph mem = GraphMemory(128) # Open Video if validators.url(args.file): from pytube import YouTube print('Downloading...') yt = YouTube(args.file).streams.first() f = yt.default_filename if not os.path.exists(f): yt.download() print('f:', f) else: f = args.file cap = VideoCapture(f) cap.open() f1, ax1 = plt.subplots(1, 3) # f2, ax2 = plt.subplots(2, 1) f3, ax3 = plt.subplots(2, 1) plt.ion() image_buffer = [0] * args.buffsz buffer = None FPS = 0 t_buffer_start = timeit.default_timer() bufferidx = 0