Created
April 10, 2023 20:08
-
-
Save aivus/dec3aaa0b1a9175d340ffb7b1294c9e4 to your computer and use it in GitHub Desktop.
Remove video from Google Pixel MP (Motion Photos) files
This file contains 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 characters
#!/usr/bin/env bash | |
# Based on: | |
# https://mjanja.ch/2021/10/stripping-embedded-mp4s-out-of-android-12-motion-photos/ | |
# https://gist.github.com/alanorth/371696685ebf65ac5e04536870916e82 | |
shopt -s globstar | |
for file in ./**/PXL_*.MP.jpg ./**/MVIMG_*.jpg; do | |
# Don't crash when there are no files matching the glob | |
[ -f "$file" ] || continue | |
echo $file | |
# Check MP4 header, newer versions first | |
unset ofs | |
for header in 'ftypisom' 'ftypmp4' 'ftypmp42' 'ftypiso6'; do | |
ofs=$(grep -F --byte-offset --only-matching --text "$header" "$file") | |
if [[ $ofs ]]; then | |
ofs=${ofs%:*} | |
truncate -s $((ofs-4)) "$file" | |
# Go to next image | |
break | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment