Skip to content

Instantly share code, notes, and snippets.

@thequbit
Created May 2, 2014 18:31
Show Gist options
  • Save thequbit/a139f64d5cde952771f5 to your computer and use it in GitHub Desktop.
Save thequbit/a139f64d5cde952771f5 to your computer and use it in GitHub Desktop.
Pull single frame from mjpeg file
#!/usr/bin/env python
import socket
import sys
if len(sys.argv) != 3:
print "Usage: %s video.mjpeg destfile.jpg" % sys.argv[0]
sys.exit(1)
fh = open(sys.argv[1],'r')
print "Reading from file ..."
boundry = fh.readline().strip()
content_type = fh.readline().split(':')[1].strip()
length = int(fh.readline().split(':')[1].strip())
print "Pulling out image ..."
# i think we need to do this ...
fh.readline()
# read image contents
image = fh.read(length)
print "Writing out image file ..."
with open(sys.argv[2], 'w') as out_fh:
out_fh.write(image)
print "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment