Extracting videos from Android Motion Photos

A MP4 video file follows the JPEG image file in a Android Phone ‘Motion photo’ with a filename starting MVIMG

EXIFTool can extract the video files with a single command, from Phil Harvey EXIFTool Developer:

Here is a command that will extract the video from all jpg images in a directory and store the videos with the same file name as the jpg but with extension .mp4:

exiftool -b -p “${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}” -ext jpg -w mp4 DIR

– Phil

 …where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (‘) instead of double quotes (“) around arguments containing a dollar sign ($).
Wow, thanks, that works. I would never have been able to figure that out myself. Would you be so kind as to explain the “-p” parameter to me, please?

-b
Output metadata in binary format. That’s what I’ve tried.

-p “${trailer;s/.*(\0\0\0\x1cftypisom)/$1/s}”
What the hell are you doing here? I found this link but it doesn’t help me:
https://exiftool.org/exiftool_pod.html#Advanced-formatting-feature

-ext jpg
Process files with the specified extension

-w mp4
New filename extension

DIR
Directory or filename

This uses the advanced formatting feature as you surmised to remove everything before the MP4 header.  The “\0\0\0\x1cftypisom” string is the binary MP4 header.  “.*” is everything before that.  The s/// is the Perl substitution operator (ie. search and replace), and it replaces everything up to and including the header with just the header (“$1” is everything inside the brackets in the search pattern of the substitution operator).  Read about “regular expressions” if you want to know more about the syntax.

– Phil

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *