http://www.mobile01.com/topicdetail.php?f=510&t=3734550
FFmpeg 範例:
http://www.mobile01.com/topicdetail.php?f=510&t=4487462
---------------
簡介
雖然網路上免費的圖片轉檔的工具很多,
但某些時候還是使用 FFmpeg 來處理會比較方便。
批次轉換
將 D:\Comics 下的圖片檔 (*.jpg *.jpeg *.jp2 *.j2k *.bmp *.png) 轉換為 webp 格式
BAT:
@echo off
set path=%~dp0;%path%
for /r "D:\Comics" %%i in (*.jpg *.jpeg *.jp2 *.j2k) do (
echo.Input: %%~i
ffmpeg -hide_banner -loglevel error -f image2pipe -i "%%~i" -c:v libwebp -q:v 80 "%%~dpni.webp"
if not errorlevel 1 (
del /q "%%~i"
echo.Saved: %%~dpni.webp
) else (
del /q "%%~dpni.webp"
goto :Complete
)
echo.
)
:Complete
批次檢查
檢查 D:\Images 下的圖片檔 (*.webp *.jpg *.jpeg *.jp2 *.j2k *.bmp *.png) 是否損壞
BAT:
@echo off
set path=%~dp0;%path%
chcp 65001
echo.List: > "%~dp0errorfiles.txt"
for /r "D:\Images" %%i in (*.webp *.jpg *.jpeg *.jp2 *.j2k *.bmp *.png) do (
echo.Input: %%~i
ffmpeg -hide_banner -loglevel error -f image2pipe -i "%%~i" -f null -
if errorlevel 1 (
echo.Decode fail.
echo."%%~i" >> errorfiles.txt
)
echo.
)
執行此 BAT 會在工作目錄下建立 errorfiles.txt,
裡面包含無法正常開啟/解碼的圖片擋路路徑清單。
Unicode 檔案路徑
FFmpeg 的 demuxer/muxer 絕大多數都有支援 Unicode 路徑。
命令:
ffmpeg -i infile -c:v jpeg outfile
若無指定 demuxer 則會依輸入檔案副檔名自動選擇。
若 ffmpeg 呼叫 image2 demuxer 來讀取圖則可能會發生錯誤,
因為目前版本的 image2 demuxer 不支援 Unicode 路徑。
為了可以正常讀取 Unicode 路徑的輸入圖片,
可以使用 image2pipe demuxer 來替代 image2 demuxer。
命令:
ffmpeg -f image2pipe -i infile outfile
或者,可以使用管道 (pipe) 來讀取/輸出檔案來避免讓 FFmpeg 直接存取 Unicode 路徑。
命令:
type outfile | ffmpeg -f image2pipe -i pipe:infilext -f image2pipe - > outfile
※ infilext 為輸入檔案副檔名,例如輸入為 "input.jpg" 則 "pipe:infilext" 即 "pipe:.jpg"。
※ 此方法只適用 image2 檔案格式 (例如 jpg png bmp webp......)。




























































































