Skip to content

Instantly share code, notes, and snippets.

@mkassner
Last active November 29, 2016 15:21
Show Gist options
  • Save mkassner/8d60b3b26dbad956a4ad676ad2499b90 to your computer and use it in GitHub Desktop.
Save mkassner/8d60b3b26dbad956a4ad676ad2499b90 to your computer and use it in GitHub Desktop.
extract jpegs from raw mjpeg dumps
import os,sys
def main():
video_path = os.path.expanduser(sys.argv[1])
out_path = os.path.join(os.path.splitext(video_path)[0]+"_out")
fh = open(os.path.expanduser(video_path), 'rb')
payload = fh.read()
start_marker = chr(0xFF)+chr(0xD8)
images = payload.split(start_marker)[1:]
os.mkdir(out_path)
for index,image in enumerate(images):
fh = open(os.path.join(out_path,'%07d'%index+'.jpeg'),'wb')
fh.write(start_marker+image)
if __name__ == '__main__':
# sys.argv.append('~/Desktop/test.mjpeg')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment