增加網址:
文章備註、標題(會記錄下來,但是暫時不會顯示):
[綜合]無題 無名 ID:sIgxMwsY 2025/12/10(三) 18:36:14.525 No.29327235
評分:0, 年:0, 月:0, 週:0, 日:0, [+1 / -1] 最後更新:2025-12-19 12:03:56
附圖
一個簡單把影片轉成5MB大小以內的webm影片ffmpeg腳本

把代碼用記事本存成名稱為mp4towebm_to_5MB.bat

點擊這個檔案執行一遍自動生成Video跟webm資夾

再把影片丟進Video資料夾 再次點擊這個bat檔

輸入影片最大寬度按enter確認

就能自動把Video資料夾內的所有檔案轉5MB內最佳畫質的webm影片到webm資料夾了

ffmpeg安裝教學

https://www.youtube.com/watch?v=ERee4DY2LQ8
無題 無名 ID:sIgxMwsY 2025/12/10(三) 18:36:47.252 No.29327238
回覆: >>29328260
執行檔代碼↓
[aa]
chcp 65001
@echo off
setlocal EnableDelayedExpansion

:: GLOBAL SETTINGS
set "inputDir=%~dp0Video"
set "outputDir=%~dp0webm"
:: 設置目標大小為 5120 KB (5MB)
set "targetSizeMB=5120"
:: 設置安全邊際為 100 KB (约为 0.1 MB)
set "safetyMarginKB=100"
:: 實際用於計算的編碼目標大小: 5120 KB - 100 KB = 5020 KB
set /a "targetSizeForCalc=%targetSizeMB% - %safetyMarginKB%"
set "audioBitrate=32"

:: CHECK TOOLS
where ffmpeg >nul 2>nul
if %errorlevel% neq 0 ( echo ERROR: ffmpeg not found. & pause & exit /b )
where ffprobe >nul 2>nul
if %errorlevel% neq 0 ( echo ERROR: ffprobe not found. & pause & exit /b )

:: DIRECTORY SETUP
if not exist "%inputDir%" (
mkdir "%inputDir%"
echo [!] Video folder created. Place videos and run again.
pause
goto :EOF
)
if not exist "%outputDir%" mkdir "%outputDir%"

:: INITIALIZATION & USER INPUT
cls
echo ==========================================
echo Video 5MB Compression Tool (Stable)
echo ==========================================
echo.
echo Enter maximum video width (e.g., 1280, leave empty for original):
set /p "width="

set "scaleFilter="
if not "%width%"=="" set "scaleFilter=-vf scale=%width%:-2"

:: COUNT FILES
echo.
echo Scanning files...
set "totalFiles=0"
for %%i in ("%inputDir%\*.*") do set /a totalFiles+=1

if %totalFiles%==0 (
echo [!] No files found in Video folder.
pause
goto :EOF
)

:: RECORD GLOBAL START TIME (using PowerShell for accurate timestamp)
for /f %%a in ('powershell -Command "Get-Date -UFormat %%s"') do set "globalStart=%%a"

:: MAIN LOOP
set "currentCount=0"

for %%i in ("%inputDir%\*.*") do (
set /a currentCount+=1
call :ProcessFile "%%i"
)

:: FINAL SUMMARY
for /f %%a in ('powershell -Command "Get-Date -UFormat %%s"') do set "globalEnd=%%a"
call :CalcDuration %globalStart% %globalEnd%

echo.
echo ==========================================
echo ALL TASKS COMPLETE!
echo Total files processed: %totalFiles%
echo Total duration: !formattedDuration!
echo ==========================================
powershell -Command "[console]::beep(1000,500)"
title Conversion Complete
pause
goto :EOF

:: ==========================================
:: SUBROUTINE: PROCESS SINGLE FILE
:: ==========================================
:ProcessFile
set "inputFile=%~1"
set "fileName=%~n1"

:: 1. Draw Progress Bar
set /a "percent=(currentCount*100)/totalFiles"
call :DrawProgressBar %percent%

:: Update Title Bar
title [%percent%%%] Processing (%currentCount%/%totalFiles%): %fileName%

echo.
echo Processing: %fileName%

:: Record File Start Time
for /f %%a in ('powershell -Command "Get-Date -UFormat %%s"') do set "fileStart=%%a"

:: 2. Get Duration
set "duration="
for /f "tokens=*" %%a in ('ffprobe -v error -show_entries format^=duration -of default^=noprint_wrapp
[/aa]
無題 無名 ID:kqGgFFtc 2025/12/10(三) 19:02:35.793 No.29327383
回覆: >>29328051
>>29327235
你怎麼不把這個影片也轉了
無題 無名 ID:iouvUEdo 2025/12/10(三) 19:41:46.622 No.29327615
>>29327235
這是要騙人去下載加料過的FFmpeg主程式嗎?
無題 無名 ID:sIgxMwsY 2025/12/10(三) 20:47:28.483 No.29328051
回覆: >>29329032
附圖
>>29327383
我12年前的爛筆電要轉35分鐘才能把兩分多鐘的影片轉好

要是有人贊助我一台新電腦我就加上支援顯卡加速轉檔功能
無題 無名 ID:gvGnU5I. 2025/12/10(三) 21:11:17.265 No.29328260
回覆: >>29328266
>>29327238
不能用 小黑窗閃退
無題 無名 ID:sIgxMwsY 2025/12/10(三) 21:12:47.095 No.29328266
>>29328260
你有裝ffmpeg嗎?
無題 無名 ID:gvGnU5I. 2025/12/10(三) 21:13:16.471 No.29328273
無題 無名 ID:gvGnU5I. 2025/12/10(三) 21:15:22.904 No.29328289
回覆: >>29328350
附圖
>>29328266
窩用AI幫我對症下藥 修正了一下可以ㄌ

40M壓到1M 還不錯ㄛ
無題 無名 ID:f/dQm3SA 2025/12/10(三) 21:22:05.157 No.29328324
>>29327235
我自己用handbrake轉就好了
用5mb*1024*8減去音軌的碼率再除以秒數就是平均碼率了
無題 無名 ID:nyvNxfUU 2025/12/10(三) 21:26:46.038 No.29328350
>>29328289
要修正哪裡 我也是閃退
無題 無名 ID:w383PqwA 2025/12/10(三) 21:27:58.783 No.29328357
ffmpeg不是一行就可以轉擋了嗎...
沒h264或265硬體支援, 就會很慢
無題 無名 ID:w383PqwA 2025/12/10(三) 21:29:49.829 No.29328367
喔喔 懂了
要能在這裡上傳
無題 無名 ID:Md2LbQLw 2025/12/10(三) 23:00:55.858 No.29329032
附圖
>>29328051
之前都用i5-3340轉1分30幾秒的OP跟你耗的時間差不多
上個月買了i5-12400+美光p310的套裝機 轉檔只要5分多鐘