Skip to content

Instantly share code, notes, and snippets.

@abakum
Last active April 27, 2021 11:15
Show Gist options
  • Save abakum/59dde95d69781c770279864a3118a557 to your computer and use it in GitHub Desktop.
Save abakum/59dde95d69781c770279864a3118a557 to your computer and use it in GitHub Desktop.
Convert 3D photos from MPO files to VR.JPG files for cardboard and photos.google.com
SetLocal EnableExtensions EnableDelayedExpansion
:forfiles
if "%~1"=="nul" (
call :doit "%~2"
goto :EOF
)
:main
if "%~1"=="" (
if not exist "%UserProfile%\SendTo\%~n0.lnk" (
if defined ChocolateyInstall (
"%ChocolateyInstall%\tools\shimgen.exe" -o "%UserProfile%\SendTo\%~n0.exe" -p "%~f0"
) else (
copy /b "%~f0" "%UserProfile%\SendTo\%~nx0"
)
echo "%~f0" is placed in "%UserProfile%\SendTo"
)
)
echo Convert 3D photos from .mpo files to .vr.jpg files for cardboard and photos.google.com
echo Run "MPO2VR.bat" without parameters to place it in "%UserProfile%\SendTo"
echo Send files or dirs: "c:\d\e.mpo" "c:\e" ... to "MPO2VR"
echo or drop it to "MPO2VR.bat"
echo Then look at "c:\VR"
rem choco install exiftool
rem choco install msys2
rem pacman -S $MINGW_PACKAGE_PREFIX-exiv2
set cmd="cmd /c "%~f0" nul "@path""
:loop
if "%~1"=="" (
pause
goto :EOF
)
forfiles /s /p "%~1" /m *.mpo /c %cmd% 2>nul||call :doit "%~1"
shift
goto :loop
:doit
if not exist "%~f1" goto :EOF
if /i not ".mpo"=="%~x1" goto :EOF
set out="%~dp1..\VR\%~n1.vr.jpg"
if exist %out% goto :EOF
set O="%temp%\%~n1.vr.jpg"
set L="%temp%\%~n1.jpg"
set R=%temp%\%~n1.jpeg
set M=%temp%\%~n1.bin
call :end
exiftool -MPImage2 -b "%~f1">"%R%"
if not exist "%R%" goto :EOF
for /f "tokens=1,2 usebackq delims=: " %%i in (`exiftool -s2 -ImageWidth -ImageHeight %R%`) do set %%iR=%%j
if not defined ImageWidthR goto :end
if not defined ImageHeightR goto :end
exiftool -makernotes -b %R%>"%M%"||del "%M%"
set makernotes="-makernotes<=%M%"
if not exist "%M%" set makernotes=-makernotes:all=
exiftool -overwrite_original -all= "%R%"
exiftool -ThumbnailImage= -ifd1:all= -PreviewImage= -FlashPix:all= -FlashpixVersion= -mpf:all= -trailer:all= "%~f1" -o %L%
if not exist %L% goto :end
for /f "tokens=1,2 usebackq delims=: " %%i in (`exiftool -s2 -ImageWidth -ImageHeight -FOV %L%`) do set %%i=%%j
if not "%ImageWidthR%"=="%ImageWidth%" goto :end
if not "%ImageHeightR%"=="%ImageHeight%" goto :end
if not defined FOV set FOV=49.8
set xmp="%temp%\%ImageWidth%x%ImageHeight%.xmp"
if exist %xmp% goto :lr
:xmp
set /a FullPanoWidthPixels=ImageWidth*4
set /a FullPanoHeightPixels=FullPanoWidthPixels/2
set /a CroppedAreaImageHeightPixels=ImageHeight
set /a CroppedAreaTopPixels=(FullPanoHeightPixels-CroppedAreaImageHeightPixels)/2
set /a FullPanoWidthPixels=FullPanoHeightPixels*2
set /a CroppedAreaImageWidthPixels=ImageWidth
set /a CroppedAreaLeftPixels=(FullPanoWidthPixels-CroppedAreaImageWidthPixels)/2
echo 1|exiftool -tagsfromfile - -XMP-GPano:all^
-XMP-GPano:CroppedAreaLeftPixels="%CroppedAreaLeftPixels%"^
-XMP-GPano:CroppedAreaTopPixels="%CroppedAreaTopPixels%"^
-XMP-GPano:CroppedAreaImageWidthPixels="%CroppedAreaImageWidthPixels%"^
-XMP-GPano:CroppedAreaImageHeightPixels="%CroppedAreaImageHeightPixels%"^
-XMP-GPano:FullPanoWidthPixels="%FullPanoWidthPixels%"^
-XMP-GPano:FullPanoHeightPixels="%FullPanoHeightPixels%"^
%xmp%
if not exist %xmp% goto :end
:lr
if not exist "%~dp1..\VR" md "%~dp1..\VR"
exiftool -tagsFromFile %xmp% %L% %makernotes% "-XMP-GPano:InitialHorizontalFOVDegrees=%FOV%" "-XMP-GImage:ImageMimeType=image/jpeg" "-XMP-GImage:ImageData<=%R%" -o %O%
rem Any of -api Compact= or use -z or do not use -z breaks compatibility with https://arvr.google.com/vr180/apps/
exiv2 -M"set Xmp.GPano.InitialHorizontalFOVDegrees %FOV%" %O%
exiftool "-FileCreateDate<CreateDate" "-FileModifyDate<ModifyDate" %O% -o %out%
:exiftool -X %out% -w! .xml
:end
del %L% "%R%" "%M%" %O%
@abakum
Copy link
Author

abakum commented Mar 20, 2021

Run "MPO2VR.bat" without parameters to place it in "%UserProfile%\SendTo"
Send files or dirs: "c:\d\e.mpo" "c:\e" ... to "MPO2VR"
or drop it to "MPO2VR.bat"
Then look at "c:\VR"

Thanks:
https://wikipedia.org/wiki/Fujifilm_FinePix_W_Series_Real_3D
https://developers.google.com/vr/reference/cardboard-camera-vr-photo-format
https://chocolatey.org/
https://exiftool.org/ choco install exiftool
https://www.msys2.org/ choco install msys2
https://www.exiv2.org/ pacman -S $MINGW_PACKAGE_PREFIX-exiv2

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