Methods
(async) WFfmpeg(args, optopt) → {Promise}
- Description:
調用ffmpeg,傳入參數交由套件自帶的ffmpeg.exe執行,只能用於Windows作業系統
ffmpeg.exe由安裝時(postinstall)自GitHub下載切割zip分片合併解壓而來,位於套件src/目錄
若因npm封鎖scripts致postinstall未執行,則於首次調用時自動重新下載
ffmpeg: https://ffmpeg.org/
- Source:
Example
import WFfmpeg from './src/WFfmpeg.mjs'
async function test() {
//args, 轉檔範例: 將input.mp4轉為output.avi
let args = ['-i', './input.mp4', './output.avi']
//cbStderr, ffmpeg的進度與資訊預設輸出至stderr
let cbStderr = (msg) => {
console.log(msg)
}
//WFfmpeg
await WFfmpeg(args, { cbStderr })
console.log('done')
}
test()
.catch((err) => {
console.log('catch', err)
})
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Array | String | 輸入ffmpeg參數,可為陣列(例如['-i','./input.mp4','./output.avi'])或字串 |
||||||||||||||||||||||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
(async) autoDownloadFiles() → {Promise}
- Description:
自動定位ffmpeg.exe,若無檔案則自動下載,回傳ffmpeg.exe的絕對路徑
依序偵測當前工作路徑的src/與node_modules/w-ffmpeg/src/,皆無ffmpeg.exe時, 代表安裝時npm封鎖scripts致postinstall未執行,故自動調用downloadFiles重新下載
供w-ffmpeg自身與其他依賴w-ffmpeg的套件(例如w-dwload-dlp)調用,無須各自實作偵測與下載邏輯
因ffmpeg.exe只能用於Windows作業系統,故調用前須自行檢核作業系統
- Source:
Example
import autoDownloadFiles from 'w-ffmpeg/src/autoDownloadFiles.mjs'
async function test() {
//autoDownloadFiles, 無ffmpeg.exe時自動下載, 下載失敗則reject
let { fpExe } = await autoDownloadFiles()
console.log('fpExe', fpExe)
// fpExe D:\xxx\node_modules\w-ffmpeg\src\ffmpeg.exe
}
test()
.catch((err) => {
console.log('catch', err)
})
Returns:
回傳Promise,resolve回傳執行檔路徑物件,內含fpExe為ffmpeg.exe的絕對路徑字串,reject回傳錯誤訊息
- Type
- Promise