Skip to content

Instantly share code, notes, and snippets.

@vi

vi/mvimg_mpv

Created Aug 11, 2019
Embed
What would you like to do?
Shell script to play Google Motion Photos with mpv from command line
#!/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
You can’t perform that action at this time.