我正尝试使用FFmpeg将帧直接提取到内存中,以节省时间,因为我不需要将帧写到磁盘上
我一开始尝试使用this代码运行,但是没有用
const ffmpeg = require('fluent-ffmpeg')
const tf = require('@tensorflow/tfjs-node')
const RVF = (path,HW)=>{
//HW is hxw string of each frame
const command = ffmpeg(path,{stdoutLines:0}).size(HW)
.addOutputOption(['-f image2'])
.on('error',(err)=>{
console.log(err)
})
const ffstream = command.pipe()
let numOfFrames = 0
ffstream.on('data',(chunck)=>{
// to check if the data is right frame of no
// first frame passes this correctly
console.log(tf.node.decodeImage(chunck).shape)
console.log(chunck.length)
console.log(`frames ${++numOfFrames}`)
})
}
第一帧已正确提取,但第二帧出现此错误
Error: ffmpeg exited with code 1: av_interleaved_write_frame(): Invalid argument
frame= 2 fps=0.0 q=3.9 Lsize=N/A time=00:00:00.08 bitrate=N/A speed=1.71x
video:101kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!