我挥动了一个正常工作的NodeJS应用程序,它正确地使用FFMPEG进行视频转换。我没有运气使用socket.io所以相反我想要Node中的本机套接字类。这是我的节点应用程序到目前为止。
具体来说,我需要在'上发送套接字事件或消息('结束',函数()'
var ffmpeg = require('./lib/fluent-ffmpeg');
var express = require('express'),
multer = require('multer');
var app = express();
//auto save file to uploads folder
app.use(multer({ dest: './uploads/'}))
var temp;
app.post('/', function (req, res) {
console.log(req.body); //contains the variables
console.log("req.files ="+ req.files); //contains the file references
console.log("req.files.Filedata.path ="+ req.files.Filedata.path );
temp=req.files.Filedata.path;
console.log("temp ="+temp);
// make sure you set the correct path to your video file
var proc = ffmpeg('./'+temp)
// set audio bitrate
.audioBitrate('128k')
// set audio codec
.audioCodec('libmp3lame')
// set output format to force
.format('avi')
// setup event handlers
.on('end', function() {
console.log('file has been converted succesfully');
})
.on('error', function(err) {
console.log('an error happened: ' + err.message);
})
// save to file
.save('./converted/converted.avi');
res.send('Thank you for uploading!');
});
app.listen(8080);