Created
April 9, 2018 11:57
-
-
Save tribut/fc9ddf2e89bd726f54dbcf1c8878aa5e to your computer and use it in GitHub Desktop.
Split Samsung Motion Photo from files and strip video from original file / Samsung Bewegungsaufnahme aus Datei extrahieren und Video aus Originalbild entfernen
This file contains hidden or 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
#!/bin/bash | |
set -e | |
info() { | |
echo "$*" >&2 | |
} | |
warn() { | |
info "WARNING: $*" | |
} | |
BACKUP="_withmotion" | |
for file in "$@"; do | |
[ -f "$file" ] || { info ">>> $file is not a file"; continue; } | |
[[ "$file" == *${BACKUP}.* ]] && { info ">>> Skipping $file"; continue; } | |
video_type="$(exiftool -p '$EmbeddedVideoType' -EmbeddedVideoType "$file" 2>/dev/null)" | |
if [ "$video_type" = "MotionPhoto_Data" ]; then | |
info ">>> Processing $file" | |
basename="${file%.*}" | |
moviefile="${basename}.mp4" | |
backupfile="${basename}${BACKUP}.jpg" | |
[ -f "$moviefile" ] && { warn "$moviefile already exists"; continue; } | |
[ -f "$backupfile" ] && { warn "$backupfile already exists"; continue; } | |
# sometimes exiftool "extracts" a zero-byte movie? | |
try=0 | |
while ! [ -s "$moviefile" ]; do | |
if [ $((++try)) -ge 5 ]; then | |
warn "Could not extract movie from $file after $try tries" | |
rm -f "$moviefile" | |
continue 2 | |
fi | |
exiftool -b -EmbeddedVideoFile "$file" > "$moviefile" | |
done | |
cp "$file" "$backupfile" | |
exiftool -overwrite_original_in_place -trailer:all= -if "\$EmbeddedVideoType eq 'MotionPhoto_Data'" "$file" | |
else | |
info ">>> $file has no embedded video" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment