作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在上传到 ffmpeg 期间通过管道传输视频以实时创建缩略图。一切顺利,但没有创建 thumbnail.jpg 并且 ffmpeg stderr 在库版本显示后挂起。
更新:我更新了我的代码,但它也没有创建有效的缩略图。
var formidable = require('formidable'),
http = require('http'),
sys = require('sys'),
spawn = require('child_process').spawn;
function spawnFfmpeg(exitCallback) {
var args = ['-i', 'pipe:0', '-c:v', 'mjpeg', '-ss', '00:00:13', '-vframes', '1', '-s', '100x80', 'thumbnail.jpg']
var ffmpeg = spawn('ffmpeg', args);
console.log('Spawning ffmpeg ' + args.join(' '));
ffmpeg.on('exit', exitCallback);
ffmpeg.stderr.on('data', function(data) {
console.log('grep stderr: ' + data);
});
return ffmpeg;
}
http.createServer(function(req, res) {
if (req.url == '/' && req.method.toLowerCase() == 'get') {
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end
('<form action="/upload" enctype="multipart/form-data" method="post">'
+ '<input type="text" name="title"><br>'
+ '<input type="file" name="upload" multiple="multiple"><br>'
+ '<input type="submit" value="Upload">'
+ '</form>'
);
} else if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
form.maxFieldsSize = 29 * 1024 * 1024;
// Handle each part of the multi-part post
var ffmpeg = spawnFfmpeg(function(code) {
console.log('child process exited with code ' + code);
res.end();
});
var form = new formidable.IncomingForm();
// Handle each part of the multi-part post
form.onPart = function(part) {
// Handle each data chunk as data streams in
part.addListener('data', function(data) {
ffmpeg.stdout.pipe(res);
res.pipe(ffmpeg.stdin);
// Write each chunk to disk
//savedFile.write(data);
});
};
// Do it
form.parse(req);
return;
}
}).listen(80, "127.0.0.1");
process.on('uncaughtException', function(err) {
});
最佳答案
经过一些研究和数小时的测试,我找到了正确的解决方案^_p>
var formidable = require('formidable'),
http = require('http'),
sys = require('sys'),
spawn = require('child_process').spawn;
function spawnFfmpeg(exitCallback) {
var args = ['-i', 'pipe:0', '-c:v', 'mjpeg', '-ss', '00:00:13', '-vframes', '1', '-s', '100x80', 'thumbnail.jpg']
var ffmpeg = spawn('ffmpeg', args);
console.log('Spawning ffmpeg ' + args.join(' '));
ffmpeg.on('exit', exitCallback);
ffmpeg.stderr.on('data', function(data) {
console.log('grep stderr: ' + data);
});
return ffmpeg;
}
http.createServer(function(req, res) {
if (req.url == '/' && req.method.toLowerCase() == 'get') {
// show a file upload form
res.writeHead(200, {'content-type': 'text/html'});
res.end
('<form action="/upload" enctype="multipart/form-data" method="post">'
+ '<input type="text" name="title"><br>'
+ '<input type="file" name="upload" multiple="multiple"><br>'
+ '<input type="submit" value="Upload">'
+ '</form>'
);
} else if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
form.maxFieldsSize = 29 * 1024 * 1024;
// Handle each part of the multi-part post
var ffmpeg = spawnFfmpeg(function(code) {
console.log('child process exited with code ' + code);
res.end();
});
var form = new formidable.IncomingForm();
// Handle each part of the multi-part post
form.onPart = function(part) {
// Handle each data chunk as data streams in
part.addListener('data', function(data) {
/*
* This only one line was the solution of my problem now all works really fast !! 500mbit like transloadit it does
*/
ffmpeg.stdin.write(data);
});
};
// Do it
form.parse(req);
return;
}
}).listen(80, "127.0.0.1");
process.on('uncaughtException', function(err) {
});
关于javascript - Node.JS:FFmpeg 管道视频编码未创建缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15957986/
我是一名优秀的程序员,十分优秀!