# Extract JPEG images from a Quicktime slideshow (or, in fact, from any random # data -- or filesystem image). # Adam Sampson # # This script works reasonably well for recovering JPEGs from a corrupt flash # memory card. If you're after a somewhat more polished implementation of # the same idea you should have a look at recoverjpeg: # http://www.rfc1149.net/devel/recoverjpeg import sys def extract(f, count): data = f.read() pos = 0 while 1: # Locate JPEG start- and end-of-image markers. start = data.find("\xff\xd8", pos) if start == -1: break end = data.find("\xff\xd9", start) if end == -1: break of = open("image" + str(count) + ".jpg", "w") of.write(data[start:end]) of.close() count += 1 pos = end + 2 return count if __name__ == "__main__": args = sys.argv[1:] count = 0 if args == []: count = extract(sys.stdin, count) else: for arg in args: f = open(arg) count = extract(f, count) f.close()