node.js - 有没有办法在node.js中使用带有读取流的ffprobe(fluent-ffmpeg)输入?
问题描述
我在我的代码中使用 fluent-ffmpeg,我的主要目标是获取音频/视频持续时间,我需要使用流作为我的输入。
根据文件, https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#reading-video-metadata
ffmpeg('/path/to/file1.avi')
.input('/path/to/file2.avi')
.ffprobe(function(err, data) {
console.log('file2 metadata:');
console.dir(data);
});
ffmpeg('/path/to/file1.avi')
.input('/path/to/file2.avi')
.ffprobe(0, function(err, data) {
console.log('file1 metadata:');
console.dir(data);
});
我试过这些
const ffmpeg = require('fluent-ffmpeg')
const fs = require('fs')
filepath = './scratch_file/assets_audios_10000.wav'
stream = fs.createReadStream(filepath)
ffmpeg(stream)
.input(filepath) // have to put a file path here, possible path dependent
.ffprobe(function (err, metadata) {
if (err){throw err}
console.log(metadata.format.duration);
}) //success printing the duration
以上成功返回时长
ffmpeg(stream)
.input(stream) //
.ffprobe(function (err, metadata) {
if (err){throw err}
console.log(metadata.format.duration);
}) // failed
以上失败。
ffmpeg(stream)
.ffprobe(function (err, metadata) {
if (err){throw err}
console.log(metadata.format.duration);
}) //returned "N/A"
已退回 N/A
有人可以帮忙吗?我需要类似的东西
ffmpeg.ffprobe(stream, (metadata) => {console.log(metadata.format.duration)} )
谢谢你。
解决方案
以下代码对我有用。
let ffmpeg = require('fluent-ffmpeg')
// create a new readable stream from whatever buffer you have
let readStream = new Readable()
readStream._read = () => {}
readStream.push(imageBufferObject.buffer)
readStream.push(null)
// I used a call to a promise based function to await the response
let metadata = await get_video_meta_data(readStream)
console.log(metadata)
async function get_video_meta_data(stream){
return new Promise((resolve, reject)=>{
ffmpeg.ffprobe(stream, (err, meta)=>{
resolve(meta)
})
})
}
只需将可读流输入到 ffmpeg.ffprobe() 中,它期望文件路径似乎对我有用,因为我可以在不写入磁盘的情况下提取元数据。
推荐阅读
- python - 使用 statmorph 包计算多个星系的星系参数
- typescript - 如何在打字稿界面中使用多个键?
- networking - 如何测试我的电脑和谷歌云实例之间的连接?
- python - Django中的NoReverseMatch,我无法访问每个客户的订单详细信息
- hana - SQL计算查询
- swift - 在另一个窗口中更新数据
- r - 库问题(taskscheduleR)
- python - Discord.py:discord.utils 没有属性“format_dt”
- c - 奇怪的结构混乱
- python - 导入正在导入另一个模块的模块时出现 ModuleNotFoundError