Skip to content

Instantly share code, notes, and snippets.

@aivus
Created April 10, 2023 20:08
Show Gist options
  • Save aivus/dec3aaa0b1a9175d340ffb7b1294c9e4 to your computer and use it in GitHub Desktop.
Save aivus/dec3aaa0b1a9175d340ffb7b1294c9e4 to your computer and use it in GitHub Desktop.
Remove video from Google Pixel MP (Motion Photos) files
#!/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