I am using fluent-ffmpeg in my code, my main goal is to get the audio/video duration, I need to use stream as my input.
According the document, 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);
});
I have tried these
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
Above successfully returned the duration
ffmpeg(stream)
.input(stream) //
.ffprobe(function (err, metadata) {
if (err){throw err}
console.log(metadata.format.duration);
}) // failed
Above failed.
ffmpeg(stream)
.ffprobe(function (err, metadata) {
if (err){throw err}
console.log(metadata.format.duration);
}) //returned "N/A"
Returned N/A
Can nyone help? I would need something like
ffmpeg.ffprobe(stream, (metadata) => {console.log(metadata.format.duration)} )
Thank you.
The following code worked for me.
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)
})
})
}
Simply feeding in the readable stream into ffmpeg.ffprobe() where it expects the file path seems to have worked for me, as I can extract the meta data without writing to disk.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.