Last active
August 29, 2015 14:13
-
-
Save gabrielstuff/0297e62d5820a4ec0334 to your computer and use it in GitHub Desktop.
ffmeg nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fs = require('fs'), | |
| videoName = './record_10.mp4', | |
| child_process = require("child_process"), | |
| exec = child_process.exec; | |
| /*This works like a charm*/ | |
| var ffmpeg = child_process.spawn("ffmpeg", [ | |
| '-i', videoName, // path | |
| '-vf', 'thumbnail,scale=640:360', | |
| '-r', '1', | |
| '-frames:v', '1', | |
| '-f', 'mjpeg', | |
| 'pipe:1' | |
| ]); | |
| ffmpeg.on('error', function(err) { | |
| console.log(err); | |
| }) | |
| ffmpeg.stderr.on('data', function(data) { | |
| console.log('stderr: ' + data); | |
| }) | |
| ffmpeg.on('close', function(code) { | |
| console.log('child process exited with code ' + code); | |
| }); | |
| var ws = fs.createWriteStream('./thumb_out.jpg'); | |
| ws.on('error', function(err) { console.log('stream err: ',err); }); | |
| ffmpeg.stdout.pipe(ws); | |
| /*This return error: | |
| stderr: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffbb1020800] stream 0, offset 0x30: partial file | |
| [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffbb1020800] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1920x1080, 15873 kb/s): unspecified pixel format | |
| Consider increasing the value for the 'analyzeduration' and 'probesize' options | |
| */ | |
| var readStream = fs.createReadStream(videoName); | |
| readStream | |
| .on('data', function(chunk) { | |
| //console.log(chunk) | |
| }) | |
| .on('end', function() { | |
| console.log('finished...'); | |
| }); | |
| var writeStream = fs.createWriteStream('woop.jpg'); | |
| writeStream.on('error', function(err) { | |
| console.log('stream err: ', err); | |
| }); | |
| var ffmpeg = child_process.spawn("ffmpeg", [ | |
| '-i', 'pipe:0', // path | |
| '-f', 'yuyv422', | |
| '-vf', 'thumbnail,scale=640:360', // bitrate to 64k | |
| '-r', '1', | |
| '-frames:v', '1', | |
| '-f', 'mjpeg', | |
| '-pix_fmt', 'yuyv422', | |
| 'pipe:1' | |
| ]); | |
| ffmpeg.on('error', function(err) { | |
| console.log(err); | |
| }) | |
| ffmpeg.stderr.on('data', function(data) { | |
| console.log('stderr: ' + data); | |
| }) | |
| ffmpeg.on('close', function(code) { | |
| console.log('child process exited with code ' + code); | |
| }); | |
| writeStream.on('error', function(err) { | |
| console.log('stream err: ', err); | |
| }); | |
| readStream.pipe(ffmpeg.stdin) | |
| ffmpeg.stdout.pipe(writeStream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment