Skip to content

Instantly share code, notes, and snippets.

@kmark
Last active November 3, 2020 14:38
Show Gist options
  • Save kmark/67cf6c03753ccab155a5da31b3ccd93e to your computer and use it in GitHub Desktop.
Save kmark/67cf6c03753ccab155a5da31b3ccd93e to your computer and use it in GitHub Desktop.
Samsung Galaxy Motion Photo extraction tool
#!/bin/bash
# Copyright 2017 Kevin Mark
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------
# Extracts the MP4 video component of Motion Photos introduced on the
# Samsung Galaxy S7. Uses exiftool to get the job done. Ignores files
# that do not contain motion photo data. Unfortunately, exiftool does
# not yet support removing this embedded data from images.
# See http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Samsung.html
#
# Example usage: extractMultiPhotos.sh /my/photos/*.jpg
hash exiftool 2>/dev/null
if [ $? -ne 0 ]; then
echo "exiftool is not available"
exit 1
fi
for file in "${@}"; do
video_type=$(exiftool -p '$EmbeddedVideoType' -EmbeddedVideoType "${file}" 2>/dev/null)
if [ "${video_type}" != "MotionPhoto_Data" ]; then
continue
fi
echo "Extracting motion photo from ${file}..."
exiftool -b -EmbeddedVideoFile "${file}" > "${file%.*}_MotionPhoto.mp4"
done
@wss7932
Copy link

wss7932 commented Aug 28, 2019

This is what I've been looking for. I just need to figure a couple of extra things out. Is there a way to have this script also keep the original file modify and file create dates, and also to bring over the original files exif data such as location and any other info?

@kmark
Copy link
Author

kmark commented Sep 8, 2019

Hi Wesley, you could definitely set the file’s filesystem timestamps with the touch command. I don’t know of a way off the top of my head to directly copy over all the EXIF data but if I had to guess exiftool would be capable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment