Created
August 11, 2019 22:37
-
-
Save vi/5de17bb8d4ea91b8c28e79e0bac6c3cb to your computer and use it in GitHub Desktop.
Shell script to play Google Motion Photos with mpv from command line
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 | |
if [[ -z "$1" || "$1" == --help || "$1" == "-?" ]]; then | |
echo "Usage: mvimg_play MVIMG_20190806_183324.jpg [other files]" | |
echo "Plays Google's Motion Photo using mpv. Depends on exiftool, mktemp, bash and mpv." | |
exit 0 | |
fi | |
FOUND=0 | |
ARGS=() | |
TORM=() | |
TOKILL=() | |
function cleanup() { | |
for i in "${TORM[@]}"; do | |
rm -f "$i" | |
done | |
for p in ${TOKILL[@]}; do | |
wait $p | |
done | |
} | |
trap "cleanup" EXIT | |
for i in "$@"; do | |
O=$(exiftool -t $i | grep -F 'Micro Video Offset' | cut -f 2-2) | |
if [[ -z "$O" ]]; then | |
# wrong file? Just appending to playlist as is | |
ARGS+=($i) | |
else | |
FOUND=1 | |
S=$(find $i -printf '%s') | |
T=`mktemp` | |
ARGS+=("$T") | |
dd if="$i" skip=$((S-O)) iflag=skip_bytes of="$T" 2> /dev/null & | |
TOKILL+=($!) | |
TORM+=("$T") | |
fi | |
done | |
if [[ $FOUND == 0 ]]; then | |
echo "EXIF tag wasn't detected in specified files. Maybe exiftool does not work?" >&2 | |
fi | |
mpv "${ARGS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment