The most useful script for removing StartOfImage

This commit is contained in:
Андрей 2021-06-08 09:08:51 +04:00 committed by GitHub
parent 7a5ef418a6
commit 7f70bf75bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

26
soi.py Normal file
View file

@ -0,0 +1,26 @@
import os
import mmap
def remove_twice_soi(imgdata):
first_soi_index = imgdata.find(b'\xff\xd8') + 2
main_data = imgdata[first_soi_index:]
return imgdata[:first_soi_index] + main_data.replace(b'\xff\xd8', b'\x00\x00')
if __name__ == '__main__':
for root, dirs, files in os.walk(os.curdir):
for file in files:
if (file.startswith('FJIMG_')):
print(os.path.join(root, file))
print('read')
readbytes = b''
soi = False
img = open(os.path.join(root, file), 'rb')
readbytes = img.read()
corrected = remove_twice_soi(readbytes)
img.close()
print('write')
newimg = open(os.path.join(root, file.replace('FJIMG_', 'corrected_')), 'wb')
newimg.write(corrected)
newimg.close()
print('OK')
print('')