Skip to content

Instantly share code, notes, and snippets.

@seadog007
Last active April 21, 2018 09:21
Show Gist options
  • Save seadog007/ee45230147be13c8dd0aa066006f6fb3 to your computer and use it in GitHub Desktop.
Save seadog007/ee45230147be13c8dd0aa066006f6fb3 to your computer and use it in GitHub Desktop.
Google Live Photo extractor - Extracts static photo and video from the live photo taken by Google Camera.
#!/usr/bin/env python3
#
# Google Live Photo extractor
# Extracts static photo and video from the live photo taken by Google Camera
#
# Usage:
# $ googlelive_extract.py <image.jpg>
#
# Creates two new files - image_static.jpg and image_video.mp4
#
# License: MIT
# Copyright (c) 2018 Jasper Li-Heng Yu
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import sys
import os
try:
filename = sys.argv[1]
except:
print("Usage: googlelive_extract.py <image.jpg>")
exit(0)
statinfo = os.stat(filename)
filesize = statinfo.st_size
with open(filename, 'rb') as f:
s = f.read()
video_start = s.find(b'\xff\xd9\x00\x00\x00\x18') + 2
video_length = filesize - video_start
print("Photo Size: %d bytes" % video_start)
print("Video Size: %d bytes" % video_length)
with open(os.path.splitext(filename)[0] + '_static.jpg', 'wb') as f:
f.write(s[0:video_start])
f.close()
with open(os.path.splitext(filename)[0] + '_video.mp4', 'wb') as f:
f.write(s[video_start:filesize])
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment