Node.JS:FFmpegpipe道video编码没有创build缩略图
我想在上传到ffmpeg的过程中将video传输到实时缩略图创build。 一切正常,但没有thumbnail.jpg创build,ffmpeg stderr挂起库版本显示后。
更新:我更新了我的代码,但它也没有创build一个有效的缩略图。
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) { });
经过一番研究和许多小时的testing后,我find了正确的解决办法^ _ ^
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) { });
您的代码看起来像在pipe道安装之前启动ffmpeg。
以下是没有validation,但听起来像你需要:
http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
child_process.spawn()的“stdio”选项是一个数组,其中每个索引都对应于孩子中的一个fd。 值是以下值之一:
'pipe' – 在subprocess和父进程之间创build一个pipe道。 pipe道的父端作为ChildProcess.stdio [fd]作为child_process对象的属性公开。 为fds 0 – 2创build的pipe道也分别以ChildProcess.stdin,ChildProcess.stdout和ChildProcess.stderr的forms提供。
- 将HTML Canvas / WebGLanimation服务器端录制到video中的最佳方法?
- Node.js Webm直播stream服务器:与<video>标记的问题
- video到audio文件通过FFMPEG节点js转换和保存
- 浏览器MediaRecorder API – video控制不工作/标头设置不正确?
- 使用FFMPEG实时stream式传输到networkingaudioAPI
- Node.js:从jpeg图像到video文件的实时转换
- 如何使用getSignedUrl()将Node.js fluent-ffmpeg屏幕截图的目标文件夹设置为您的AWS S3存储桶?
- NodeJs:如何pipe两个stream到一个产生的进程stdin(即ffmpeg)导致一个单一的输出
- 如何通过Node JS&Angular JS实时显示ffmpeg的水印