Skip to content

Instantly share code, notes, and snippets.

@ZXYFrank
Created June 26, 2022 07:55
Show Gist options
  • Save ZXYFrank/3922cdb6f4eaa2caaf5ed1c27944fe29 to your computer and use it in GitHub Desktop.
Save ZXYFrank/3922cdb6f4eaa2caaf5ed1c27944fe29 to your computer and use it in GitHub Desktop.
Python script to convert Android MVIMG to mp4 and jpg
import re
import os
def split_file(original_path, out_folder):
os.makedirs(out_folder, exist_ok=True)
name = os.path.split(original_path)[-1]
# https://stackoverflow.com/questions/3217334/searching-reading-binary-data-in-python
content = None
with open(original_path, 'rb') as f:
content = f.read()
pos = content.find(b'ftypmp4')
if pos == -1:
raise ValueError("NOT MVIMG")
else:
with open(os.path.join(out_folder, "{}.jpg".format(name)), "wb") as f:
f.write(content[:pos - 4])
with open(os.path.join(out_folder, "{}.mp4".format(name)), "wb") as f:
f.write(content[pos - 4:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment