1.首先在電腦上安裝node / ffmpeg (怎么安裝百度叭 案例挺多不做介紹)
2.確認安裝完成之后:
//注意!!!! 方法可以直接復制,前幾行這個我就是標注一下以下方法用到了這些插件
const ffmpeg = require('fluent-ffmpeg')
const path = require('path')
let cp = require('child_process');
console.log('主要內容:',"-------下邊-------")
//提取視頻第一幀 保存為圖片
//pathFile:原檔案地址/原檔案名.jpg
//saveFilePath:要保存到哪/檔案名.jpg
//let cp = require('child_process'); 用到了這個奧 百度去 我不解釋了哇 哈哈哈哈
const execJpg = (pathFile , saveFilePath)=>{
cp.exec(`ffmpeg -i ${path.join(__dirname, pathFile)} -y -f image2 -frames 1 ${path.join(__dirname, saveFilePath)}`, function(res) {
console.log(`${saveFilePath} success...`)
})
}
// 利用ffmpeg swf轉mp4 還可以轉別的格式,詳細請看ffmpeg官網(百度能查到)
//pathFile:原檔案地址/原檔案名.jpg
//saveFilePath:要保存到哪/檔案名.jpg
const commandMp4 = (pathFile , saveFilePath)=>{
return new Promise((resolve, reject)=>{
ffmpeg(path.join(__dirname, pathFile))
// 設定視頻位元率
.videoBitrate(1024)
//以百分比設定大小
.size('50%')
//設定fps
.fps(1)
.format('mp4')
.on('error', (err)=> {
reject({msg:"err" , data:err})
})
.on('end', ()=> {
resolve({msg:"success",data:{file:saveFilePath}})
})
.save(path.join(__dirname, saveFilePath))
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/296688.html
標籤:其他
