Skip to content

Instantly share code, notes, and snippets.

@JySzE
Last active October 7, 2025 09:46
Show Gist options
  • Select an option

  • Save JySzE/0d6417c84deceda8326e38804d31015b to your computer and use it in GitHub Desktop.

Select an option

Save JySzE/0d6417c84deceda8326e38804d31015b to your computer and use it in GitHub Desktop.
SoM MPV BUILDER
@echo off
net session >nul 2>&1
if %errorlevel% neq 0 (
powershell -Command "Start-Process '%~f0' -Verb RunAs"
exit /b
)
title SoM MPV Builder
cd /d "%~dp0"
if exist "%CD%\MPV" (
if exist "%APPDATA%\mpv" (
mode con: cols=58 lines=30
) else (
mode con: cols=58 lines=28
)
) else (
if exist "%APPDATA%\mpv" (
mode con: cols=58 lines=28
) else (
mode con: cols=58 lines=26
)
)
set PATH=%SystemRoot%\System32;%PATH%
for /f "delims=" %%A in ('echo prompt $E^| cmd') do set "ESC=%%A"
echo %ESC%[33m==========================================================
echo %ESC%[33m _____ __ ___ __ ___ ____ _ __
echo %ESC%[33m / ___/ ____ / ^|/ / / ^|/ // __ \^| ^| / /
echo %ESC%[33m \__ \ / __ \ / /^|_/ / / /^|_/ // /_/ /^| ^| / /
echo %ESC%[33m ___/ // /_/ // / / / / / / // ____/ ^| ^|/ /
echo %ESC%[33m /____/ \____//_/ /_/ /_/ /_//_/ ^|___/
echo(
echo %ESC%[33m================== Build 3.9 (10/07/25) ==================%ESC%[0m
echo.
set /a num=%random% %%100
set "MPV_old_RandomNumber=MPV_old_%random%"
IF EXIST "%CD%\MPV" (
<nul set /p ="Renaming existing "MPV" folder. "
ren "%CD%\MPV" "%MPV_old_RandomNumber%" >nul 2>&1
if ERRORLEVEL 1 (
echo Error!
echo.
echo Failed to rename MPV folder. Check permissions.
echo Or file or folder is open in another program.
echo.
pause
exit /b 1
)
echo Done!
echo ==========================================================
)
if exist "%CD%\SoM_Temp" rd /s /q "%CD%\SoM_Temp"
mkdir "%CD%\SoM_Temp"
<nul set /p ="Parsing MPV RSS feed. "
set "MPVRSSFeedURL=https://api.github.com/repos/zhongfly/mpv-winbuild/releases"
powershell -Command "$ErrorActionPreference='Stop'; try { $r=irm '%MPVRSSFeedURL%' -ErrorAction Stop; $v3=($r.assets|?{$_.browser_download_url -match 'mpv-x86_64-v3-.*-git-.*\.7z$'}|select -First 1).browser_download_url; $nv3=($r.assets|?{$_.browser_download_url -match 'mpv-x86_64-.*-git-.*\.7z$' -and $_.browser_download_url -notmatch '-v3-'}|select -First 1).browser_download_url; if(-not $v3 -or -not $nv3){exit 1}; sc '%CD%\SoM_Temp\mpv_temp_v3.txt' $v3; sc '%CD%\SoM_Temp\mpv_temp.txt' $nv3 } catch { exit 1 }" >nul 2>&1
call :checkStatus
if ERRORLEVEL 1 exit /b
set /p LatestV3BuildLink=<"%CD%\SoM_Temp\mpv_temp_v3.txt"
set /p LatestNonV3BuildLink=<"%CD%\SoM_Temp\mpv_temp.txt"
echo ==========================================================
<nul set /p ="Downloading 7zr. "
curl --noproxy "*" -s "https://www.7-zip.org/a/7zr.exe" -o "%CD%\SoM_Temp\7zr.exe" >nul
call :checkStatus
if ERRORLEVEL 1 exit /b
echo ==========================================================
<nul set /p ="Downloading Coreinfo and Parsing CPU instructions. "
curl --noproxy "*" -s https://download.sysinternals.com/files/Coreinfo.zip -o "%CD%\SoM_Temp\Coreinfo.zip"
call :checkStatus
if ERRORLEVEL 1 exit /b
if exist "%CD%\SoM_Temp\Coreinfo.zip" (
powershell -Command "try { $ProgressPreference='SilentlyContinue'; Expand-Archive -Path '%CD%\SoM_Temp\Coreinfo.zip' -DestinationPath '%CD%\SoM_Temp\Coreinfo' -Force } catch { exit 1 }"
if ERRORLEVEL 1 (
echo.
echo. Warning: Failed to extract Coreinfo.zip.
echo. Check if antivirus or other software is interfering.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
) else (
echo.
echo. Warning: Coreinfo.zip not found.
echo. Check if antivirus or other software is interfering.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
set "AVX2Support=false"
for /f "tokens=2*" %%a in ('"".\SoM_Temp\Coreinfo\Coreinfo.exe" /accepteula | findstr /C:"AVX2""') do (
if "%%a"=="*" (
set "AVX2Support=true"
) else if "%%a"=="-" (
set "AVX2Support=false"
)
)
echo ==========================================================
if "%AVX2Support%"=="true" (
<nul set /p ="Downloading latest x86_64-v3 MPV build... "
curl -s --noproxy "*" -L "%LatestV3BuildLink%" -o "%CD%\SoM_Temp\mpv_v3.7z"
call :checkStatus
if ERRORLEVEL 1 exit /b
mkdir "%CD%\MPV"
"%CD%\SoM_Temp\7zr.exe" x "%CD%\SoM_Temp\mpv_v3.7z" -o"%CD%\MPV" >nul
) else (
<nul set /p ="Downloading latest non-v3 MPV build... "
curl -s --noproxy "*" -L "%LatestNonV3BuildLink%" -o "%CD%\SoM_Temp\mpv_non_v3.7z"
call :checkStatus
if ERRORLEVEL 1 exit /b
mkdir "%CD%\MPV"
"%CD%\SoM_Temp\7zr.exe" x "%CD%\SoM_Temp\mpv_non_v3.7z" -o"%CD%\MPV" >nul
)
echo ==========================================================
<nul set /p ="Parsing GPU vendor. "
for /f "delims=" %%i in ('powershell -Command "$gpus = Get-CimInstance -ClassName Win32_VideoController | Where-Object { $_.Name -match 'NVIDIA|AMD|Radeon|GeForce|Intel\(R\)' }; $nvidia = $gpus | Where-Object { $_.Name -match 'NVIDIA' } | Select-Object -First 1; $amd = $gpus | Where-Object { $_.Name -match 'AMD|Radeon' } | Select-Object -First 1; $intel = $gpus | Where-Object { $_.Name -match 'Intel\(R\)' } | Select-Object -First 1; if ($nvidia) { 'NVIDIA' } elseif ($amd) { 'AMD' } elseif ($intel) { 'INTEL' } else { 'UNKNOWN' }"') do set "GPU_VENDOR=%%i"
if not defined GPU_VENDOR (
echo Error!
echo.
echo Could not detect GPU vendor.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
if "%GPU_VENDOR%"=="UNKNOWN" (
echo Error!
echo.
echo GPU detected but vendor unknown.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
echo. Done!
echo ==========================================================
<nul set /p ="Downloading SoM MPV Config. "
curl --noproxy "*" -sL "https://github.com/JySzE/SoM-MPV-Config/archive/refs/heads/main.zip" -o "%CD%\SoM_Temp\main.zip"
call :checkStatus
if ERRORLEVEL 1 exit /b
if exist "%CD%\SoM_Temp\main.zip" (
powershell -Command "try { $ProgressPreference='SilentlyContinue'; Expand-Archive -Path '%CD%\SoM_Temp\main.zip' -DestinationPath '%CD%\SoM_Temp' -Force } catch { exit 1 }"
if ERRORLEVEL 1 (
echo.
echo. Warning: Failed to extract SoM MPV Config..
echo. Check if antivirus or other software is interfering.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
) else (
echo.
echo. Warning: SoM MPV Config zip not found.
echo. Check if antivirus or other software is interfering.
echo.
call :cleanupAndExit
pause
call :end
exit /b 1
)
ren "%CD%\SoM_Temp\SoM-MPV-Config-main" "portable_config" >nul 2>&1
move "%CD%\SoM_Temp\portable_config" "%CD%\MPV" >nul 2>&1
powershell -Command "(Get-Content '%CD%\MPV\portable_config\mpv.conf') -replace '^d3d11-adapter\s*=.*', 'd3d11-adapter = %GPU_VENDOR%' | Set-Content -Encoding utf8 '%CD%\MPV\portable_config\mpv.conf'" >nul 2>&1
echo ==========================================================
<nul set /p ="Deleting temp files. "
echo Done!
for %%D in (
"%CD%\MPV\mpv"
"%CD%\MPV\doc"
"%CD%\SoM_Temp"
"%CD%\MPV\installer"
"%CD%\MPV\portable_config\installer"
) do rd /S /Q "%%~D"
del "%CD%\MPV\mpv-register.bat" >nul 2>&1
del "%CD%\MPV\mpv-unregister.bat" >nul 2>&1
del "%CD%\MPV\portable_config\.gitattributes" >nul 2>&1
del "%CD%\MPV\portable_config\README.md" >nul 2>&1
del "%CD%\MPV\updater.bat" >nul 2>&1
set "folder=%APPDATA%\mpv"
set "backup_folder=mpv_bak"
set "backup_suffix=1"
IF EXIST "%folder%\" (
echo ==========================================================
echo.Renaming APPDATA "mpv" folder to "mpv_bak" Done!
:check_backup_folder
if exist "%APPDATA%\%backup_folder%_%backup_suffix%" (
set /a "backup_suffix+=1"
goto :check_backup_folder
)
move "%APPDATA%\mpv" "%APPDATA%\%backup_folder%_%backup_suffix%" >nul
) ELSE (
goto :continue2
)
:continue2
echo.
echo ===================== Build Complete =====================
echo.
pause
goto :end
:checkStatus
if %ERRORLEVEL%==0 (
echo. Done!
exit /b 0
) else (
echo. Error!
echo.
echo. Check if antivirus or other software is interfering.
echo.
call :cleanupAndExit
pause
call :end
)
:cleanupAndExit
for %%D in (
"%CD%\SoM_Temp"
"%CD%\MPV"
) do rd /S /Q "%%~D" >nul 2>&1
exit /b 1
:end
(goto) 2>nul & del "%~f0"

Comments are disabled for this gist.