set drmfilename=%1
set drmoutfnm=%2
set drmmetafnm=%3
del out.mp4
del xaa.mp4
del xab.bin
del xac.bin
del kmvd.bin
del aesfile.key
del content.key
del drm.bin
del xaa-kmvs-uuid.bin
del xaa_track2.amr
del xaa_track1.h264
del tmp_out.mp4
del tmp.mp4
del out-tmp.kmv
del xaa-kmvd-uuid.bin
if not exist SplitKMV.exe goto END
SplitKMV.exe %drmfilename%
Yamb\MP4Box.exe -raw 1 xaa.mp4
Yamb\MP4Box.exe -raw 2 xaa.mp4
AtomicParsley.exe xaa.mp4 --extract1uuid kmvd
if exist xaa-kmvd-uuid.bin goto DRM
AtomicParsley.exe xaa.mp4 --extract1uuid kmvs
AtomicParsley.exe xaa.mp4 --extract1uuid kmhq
AtomicParsley.exe xaa.mp4 --extract1uuid km4v
AtomicParsley.exe xaa.mp4 --extract1uuid khvg
if not exist xab.bin goto END
if not exist xaa-kmvs-uuid.bin move /Y xab.bin xaa-kmvs-uuid.bin
if exist xaa-kmhq-uuid.bin move /Y xaa-kmhq-uuid.bin xaa-kmvs-uuid.bin
if exist xaa-km4v-uuid.bin move /Y xaa-km4v-uuid.bin xaa-kmvs-uuid.bin
if exist xaa-khvg-uuid.bin move /Y xaa-khvg-uuid.bin xaa-kmvs-uuid.bin
if not exist e2p.key goto END
genkey.exe e2p.key

if not exist aesfile.key goto END
if not exist xaa_track1.h264 goto END
if not exist xaa_track2.amr goto END
if not exist %drmmetafnm% goto END
if not exist Yamb\MP4BoxAES.exe goto END
call_mp4box.exe Yamb\MP4BoxAES.exe xaa_track1.h264 xaa_track2.amr tmp_out.mp4 %drmmetafnm%
 
if not exist tmp_out.mp4 goto END
if not exist content.key goto END
copy /b content.key+xaa-kmvs-uuid.bin kmvd.bin
AtomicParsley.exe tmp_out.mp4 --meta-uuid "kmvd" file kmvd.bin
move /Y tmp_out-temp*.* out-tmp.kmv
copy /b out-tmp.kmv+fake.fst tmp3.kmv

:DRM
if not exist tmp3.kmv copy %drmfilename% tmp3.kmv
move /Y tmp3.kmv %drmoutfnm%

:END
del out.mp4
del xaa.mp4
del xab.bin
del xac.bin
del kmvd.bin
del aesfile.key
del content.key
del drm.bin
del xaa-kmvs-uuid.bin
del xaa_track2.amr
del xaa_track1.h264
del tmp_out.mp4
del tmp.mp4
del out-tmp.kmv
del xaa-kmvd-uuid.bin