Last active
October 29, 2015 06:14
-
-
Save kidapu/627b06debe76ce014527 to your computer and use it in GitHub Desktop.
動画からGIFアニ作る用Node.js
This file contains 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
// fffmpegが必要 | |
// さんこう:http://takuya-1st.hatenablog.jp/entry/2015/07/15/002701 | |
// require | |
var _exec = require('child_process').execSync; | |
// static const | |
var _moviePath = "./src/test.mp4"; | |
var _outPath ="./dest/out.gif" | |
var _rate = 0.5; | |
var _fps = 15; | |
// convert | |
convert(); | |
function convert() | |
{ | |
// width, height | |
var width = Math.floor(""+ _exec('ffmpeg -i ' + _moviePath + ' 2>&1 > /dev/null | grep Stream | grep -o "[1-9][0-9]\\+x[1-9][0-9]\\+" | cut -d x -f1')); | |
var height = Math.floor(""+ _exec('ffmpeg -i ' + _moviePath + ' 2>&1 > /dev/null | grep Stream | grep -o "[1-9][0-9]\\+x[1-9][0-9]\\+" | cut -d x -f2')); | |
// calc new width, height | |
var newWidth = width * _rate; | |
var newHeight = height * _rate; | |
console.log( "target w:" newWidth + " / h:" + newHeight); | |
// exec | |
var log = "" + _exec("ffmpeg -y -i " + _moviePath + " -vf scale=" + newWidth + ":" + newHeight + " -an -r " + _fps + " -pix_fmt rgb24 -f gif " + _outPath ); | |
console.log( log ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment