-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathset_fps.py
40 lines (34 loc) · 1.09 KB
/
set_fps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import mp4
import sys, struct, shutil, os
outname = os.path.basename(sys.argv[1])
name, ext = os.path.splitext(outname)
outname = name + '_fps' + ext
print(outname)
f = open(sys.argv[1], 'rb')
mp4.find_atom(f, b'moov')
moov_offset = f.tell()
moov = mp4.parse_atom(f)
for trak in moov.find(b'trak'):
if trak.find(b'vmhd'):
video_trak = trak
break
else:
sys.exit(1)
#stsz = video_trak.find(b'stsz')[0]
stts = video_trak.find(b'stts')[0]
mdhd = video_trak.find(b'mdhd')[0]
#num_samples = struct.unpack('>I', stsz.data[8:8+4])[0]
#stts.data[4:] = struct.pack('>III', 1, num_samples, 1001)
stts_entries = struct.unpack('>I', stts.data[4:4+4])[0]
num_samples = 0
for i in range(stts_entries):
offset = 8 + i*8
num_samples += struct.unpack('>I', stts.data[offset:offset+4])[0]
stts.data[offset+4:offset+8] = struct.pack('>I', 1001)
mdhd.data[12:12+8] = struct.pack('>II', 60000, num_samples*1001)
f.close()
#os.unlink(outname)
shutil.copyfile(sys.argv[1], outname)
fout = open(outname, 'r+b')
fout.seek(moov_offset)
fout.write(moov.flatten())