python使用pydub实现视频转音频,nodejs使用ffmpeg
python
pip i pydub
from pydub import AudioSegment
sound = AudioSegment.from_file("your_video_file.mp4", format="mp4")
file_handle = sound.export("pydub_output.wav", format="wav")
nodejs
npm i fluent-ffmpeg
// 引入fluent-ffmpeg库
const ffmpeg = require('fluent-ffmpeg');
// 定义视频文件路径和输出音频文件路径
const videoPath = './your_video_file.mp4';
const audioPath = './output.mp3';
// 使用fluent-ffmpeg从视频中提取音频
ffmpeg(videoPath)
.outputOptions('-vn') // 只保留音频,不包含视频
.output(audioPath)
.on('end', () => {
console.log('音频文件已成功保存到本地');
})
.on('error', (err) => {
console.error('音频提取过程中出现错误:', err);
})
.run();