Jump to content

Samsung Motion Photo Extractor

Recommended Posts

Hello guys,

Recently decided to figure out how to extract MotionPhoto part from photos I do with my Galaxy Note 10+.

Research shown that all data is kept inside single jpg and can be extracted by simple splitting file on specific marker - string "MotionPhoto_Data".

Working proof of concept code is here:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <String.au3>

$searchdata = StringTrimLeft(StringToBinary("MotionPhoto_Data"),2)
$title = 'Samsung Motion Photo Converter by AntidotE'
$version = ''

Func Split()
    if $CmdLine[0] = 0 Then
        MsgBox($MB_SYSTEMMODAL,$title,'You need to specify input jpg file')
    Local $sFilePath = $CmdLine[1]
    if StringRight($sFilePath,4) <> '.jpg' Then
        MsgBox($MB_SYSTEMMODAL, $title, "Only jpg files supported.")
        Return False
    Local $sFilemp4 = StringLeft($sFilePath,StringLen($sFilePath)-4) & "_cut.mp4"
    Local $sFilejpg = StringLeft($sFilePath,StringLen($sFilePath)-4) & "_cut.jpg"

    ; Open the file for reading and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_READ + $FO_BINARY + $FO_ANSI)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, $title, "An error occurred when reading the file.")
        Return False

    ; Read the contents of the file using the handle returned by FileOpen.
    Local $sFileRead = FileRead($hFileOpen)
    $sData = StringTrimLeft($sFileRead,2)
    Local $pos = StringInStr($sData,$searchdata)
    if $pos = 0 Then
        MsgBox($MB_SYSTEMMODAL, $title, "File does not contain required marker.")
        Return False
    Local $bData = Binary("")

    $bData = BinaryToString("0x" & StringMid($sData,1,$pos - 1))
    Local $hFilejpg = FileOpen($sFilejpg, $FO_CREATEPATH + $FO_OVERWRITE + $FO_BINARY + $FO_ANSI)
    $bData = BinaryToString("0x" & StringMid($sData,$pos + StringLen($searchdata)))
    Local $hFilemp4 = FileOpen($sFilemp4, $FO_CREATEPATH + $FO_OVERWRITE + $FO_BINARY + $FO_ANSI)

EndFunc   ;==>Split

Running script expects <originalfilename>.jpg file as single parameter and result is two additional files - <originalfilename>_cut.jpg and <originalfilename>_cut.mp4.

Actual code can be found on my Github, there is a chance I will expand it some day to be more fancy or user friendly.

If you have any comments or suggestions - feel free to write here, contact me or create pull requests 🙂.

Link to post
Share on other sites
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...