当FFMPEG完成时,NodeJS + FFMPEG发送响应 [英] NodeJS + FFMPEG -sending response when FFMPEG is completed
问题描述
https://github.com / fluent-ffmpeg / node-fluent-ffmpeg
当工作完成后,我在服务器上收到一条消息,但如何通知客户端? ?在这种情况下一个简单的AIR应用程序现在我只能在上传成功后才能听到初始响应。
初始视频文件是通过http POST请求上传的。
我没有依赖关系的主节点应用程序如下
var ffmpeg = require('./ LIB /流利-的ffmpeg');
var express = require('express'),
multer = require('multer');
var app = express();
//自动保存文件上传文件夹
app.use(multer({dest:'./uploads/'}))
var temp;
app.post('/',function(req,res){
console.log(req.body); //包含变量
console.log( req.files =+ req.files); //包含文件引用
console.log(req.files.Filedata.path =+ req.files.Filedata.path);
temp = req.files.Filedata.path;
//确保为视频文件设置正确的路径
var proc = ffmpeg('./'+ temp)
//设置视频比特率
.videoBitrate(1024)
//设置音频编解码器
.audioCodec('libmp3lame')
//设置输出格式强制
.format('avi')
//设置事件处理程序
.on('end',function(){
console.log '文件已成功转换');
})
.on('error',function(err){
console.log('发生错误:'+ err.message) ;
})
//保存到文件
.save('./ converted / converted.avi');
res.send 谢谢上传!);
});
app.listen(8080);
有两种方法可以使用。第一个是每x秒从客户端以AJAX GET请求轮询服务器。第二种方法是使用WebSockets并通过直接向其发送消息来通知客户。
I have a working NodeJS+FFMPEG application. I am able to upload video files and have them converted on the server. I am using this NodeJS FFMPEG library
https://github.com/fluent-ffmpeg/node-fluent-ffmpeg
I get a message on the server when the job is complete, but how do I notify the client?? In this case a simple AIR application. Right now I can only 'hear' the initial response after a successful upload.
The initial video file was uploaded via a http POST request.
My primary node application without the dependencies is as follows
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;
// make sure you set the correct path to your video file
var proc = ffmpeg('./'+temp)
// set video bitrate
.videoBitrate(1024)
// 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);
There are two approaches you can use. The first is to poll the server from the client with AJAX GET requests every x seconds. The second approach is to use WebSockets and notify the client by sending a message to them directly.
这篇关于当FFMPEG完成时,NodeJS + FFMPEG发送响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!