From 7f70bf75bce7f8e9f9e9c7d92c1e639a09ed9fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?= <50486086+DarkCat09@users.noreply.github.com> Date: Tue, 8 Jun 2021 09:08:51 +0400 Subject: [PATCH] The most useful script for removing StartOfImage --- soi.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 soi.py diff --git a/soi.py b/soi.py new file mode 100644 index 0000000..f5e02f9 --- /dev/null +++ b/soi.py @@ -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('')