Last active
June 7, 2026 06:36
-
-
Save JySzE/0d6417c84deceda8326e38804d31015b to your computer and use it in GitHub Desktop.
SoM MPV BUILDER
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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 4.1 (06/07/26) ==================%ESC%[0m | |
| echo. | |
| set /a num=%random% %%100 | |
| set "MPV_old_RandomNumber=MPV_old_%random%" | |
| IF EXIST "%CD%\MPV" ( | |
| <nul set /p ="[36mRenaming[0m existing "MPV" folder. " | |
| ren "%CD%\MPV" "%MPV_old_RandomNumber%" >nul 2>&1 | |
| if ERRORLEVEL 1 ( | |
| echo [31mError![0m | |
| echo. | |
| echo [31mFailed to rename MPV folder. Check permissions.[0m | |
| echo [31mOr file or folder is open in another program.[0m | |
| echo. | |
| pause | |
| exit /b 1 | |
| ) | |
| echo [33mDone![0m | |
| echo ========================================================== | |
| ) | |
| if exist "%CD%\SoM_Temp" rd /s /q "%CD%\SoM_Temp" | |
| mkdir "%CD%\SoM_Temp" | |
| set "REPO_BRANCH=main" | |
| set "VRAM_MB=0" | |
| for /f "usebackq delims=" %%A in ( | |
| `powershell -Command "[math]::Floor((Get-CimInstance Win32_VideoController | Sort-Object AdapterRAM -Descending | Select-Object -First 1).AdapterRAM / 1MB)"` | |
| ) do set /a "VRAM_MB=%%A" | |
| if %VRAM_MB% LSS 4000 set "REPO_BRANCH=main-low-end" | |
| <nul set /p ="[93mParsing[0m 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 ="[34mDownloading[0m 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 ="[34mDownloading[0m Coreinfo and [93mParsing[0m 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. [31mWarning: Failed to extract Coreinfo.zip. | |
| echo. Check if antivirus or other software is interfering.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| ) else ( | |
| echo. | |
| echo. [31mWarning: Coreinfo.zip not found. | |
| echo. Check if antivirus or other software is interfering.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| set "AVX2Support=false" | |
| "%CD%\SoM_Temp\Coreinfo\Coreinfo64.exe" /accepteula -f > "%CD%\SoM_Temp\coreinfo_out.txt" 2>nul | |
| find "AVX2" "%CD%\SoM_Temp\coreinfo_out.txt" > "%CD%\SoM_Temp\avx2_line.txt" 2>nul | |
| for /f "usebackq delims=" %%L in ("%CD%\SoM_Temp\avx2_line.txt") do ( | |
| set "AVX2Line=%%L" | |
| ) | |
| echo %AVX2Line% | find "*" >nul 2>&1 | |
| if %errorlevel%==0 ( | |
| set "AVX2Support=true" | |
| ) | |
| echo ========================================================== | |
| if "%AVX2Support%"=="true" ( | |
| <nul set /p ="[34mDownloading[0m 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 ="[34mDownloading[0m 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 ="[93mParsing[0m 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 [31mError![0m | |
| echo. | |
| echo [31mCould not detect GPU vendor.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| if "%GPU_VENDOR%"=="UNKNOWN" ( | |
| echo [31mError![0m | |
| echo. | |
| echo [31mGPU detected but vendor unknown.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| echo. [33mDone![0m | |
| echo ========================================================== | |
| if "%REPO_BRANCH%"=="main" ( | |
| <nul set /p ="[34mDownloading[0m SoM MPV Config. [Main] " | |
| ) else ( | |
| <nul set /p ="[34mDownloading[0m SoM MPV Config. [Main-low-end] " | |
| ) | |
| curl --noproxy "*" -sL "https://github.com/JySzE/SoM-MPV-Config/archive/refs/heads/%REPO_BRANCH%.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. [31mWarning: Failed to extract SoM MPV Config.. | |
| echo. Check if antivirus or other software is interfering.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| ) else ( | |
| echo. | |
| echo. [31mWarning: SoM MPV Config zip not found. | |
| echo. Check if antivirus or other software is interfering.[0m | |
| echo. | |
| call :cleanupAndExit | |
| pause | |
| call :end | |
| exit /b 1 | |
| ) | |
| ren "%CD%\SoM_Temp\SoM-MPV-Config-%REPO_BRANCH%" "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 ="[36mDeleting[0m temp files. " | |
| echo [33mDone![0m | |
| 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.[36mRenaming[0m APPDATA "mpv" folder to "mpv_bak" [33mDone![0m | |
| :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 [33m===================== Build Complete =====================[0m | |
| echo. | |
| pause | |
| goto :end | |
| :checkStatus | |
| if %ERRORLEVEL%==0 ( | |
| echo. [33mDone![0m | |
| exit /b 0 | |
| ) else ( | |
| echo. [31mError![0m | |
| echo. | |
| echo. [31mCheck if antivirus or other software is interfering.[0m | |
| 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.