Skip to content

Instantly share code, notes, and snippets.

@steveway
Last active May 16, 2017 09:48
Show Gist options
  • Select an option

  • Save steveway/536e2b5a18523f6de72011ee22a6bbc2 to your computer and use it in GitHub Desktop.

Select an option

Save steveway/536e2b5a18523f6de72011ee22a6bbc2 to your computer and use it in GitHub Desktop.
A videoplayer able to play back gmv and gzipped gmv files
import numpy as np
import cv2
import gzip
import sys, os
from time import sleep, time
def main():
width = 600
height = 800
if len(sys.argv) > 1:
filepath = sys.argv[1]
else:
filepath = os.path.join(os.getcwd(),'gmvid.gmv')
print(filepath)
if filepath != "stdin":
if filepath.endswith(".gz"):
inputfile = gzip.open(filepath, "rb")
else:
inputfile = open(filepath, "rb")
else:
inputfile = sys.stdin.buffer
while True:
lastframetime = time()
singleframe = inputfile.read(int((width*height)/8))
if not singleframe:
break
nparr = np.frombuffer(singleframe,np.uint8)
nparr = np.unpackbits(nparr)
nparr = nparr.reshape(-1,8)
nparr = np.fliplr(nparr)
nparr = nparr * 255
try:
nparr = np.fromstring(nparr,dtype=np.uint8).reshape(height,width,1)
except ValueError:
pass
cv2.imshow("image",nparr)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if (time()-lastframetime) < (1/7.7):
sleep((1/7.7)-(time()-lastframetime))
print(1.0/(time()-lastframetime))
cv2.destroyAllWindows()
inputfile.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment