Created
September 14, 2022 14:26
-
-
Save JakeTrock/5b984bf9d519b371e7f31a8f689c198b to your computer and use it in GitHub Desktop.
Revisions
-
JakeTrock created this gist
Sep 14, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ #!/usr/bin/env python """ This utility will search *any* file and look for what *appears* to be a DV video frames and copy them into a new Raw DV file. Written by Dan Dennedy <[email protected]> """ import sys def is_dv_1(s):\ return ord(s[0]) == 0x1f and ord(s[1]) == 0x07 and ord(s[2]) == 0x00 def is_dv_2(s): return ord(s[1]) == 0x07 and ord(s[2]) == 0x00 and ord(s[3]) == 0xff def is_pal(s): return (ord(s[3]) & 0x80) if len(sys.argv) < 3 or sys.argv[1][0] == '-': print 'Usage', sys.argv[0], '<input-file> <output-file>' sys.exit(0) inputFilename = sys.argv[1] outputFilename = sys.argv[2] print 'Salvaging from', inputFilename, 'into', outputFilename pos = 0 count = 0 input = open(inputFilename, 'rb') output = open(outputFilename, 'wb') while True: input.seek(pos) dif1 = input.read(480) if not dif1: break if is_dv_1(dif1): dif2 = input.read(480) if not dif2: break if is_dv_2(dif2): size = (is_pal(dif1) and (480 * 300) or (480 * 250)) frame = input.read(size - 480 * 2) if frame: output.write(dif1) output.write(dif2) output.write(frame) count += 1 if count % (size/4800) == 0: print '\rSalvaging frame', count, sys.stdout.flush() pos += size else: break else: pos += 1 else: pos += 1 input.close() output.close() print '\nSalvaging frame %d. Done.' % (count,) sys.exit(0)