kidapu
9/26/2016 - 7:43 AM

ffmpegで動画を繰り刻む君.txt

ffmpegで動画を繰り刻む君.txt

// require
var _exec = require('child_process').execSync;
var _util = require('util');

// static const
var _scale = 1.0;
var _fps = 30;
var _input_path = "./src/test.mov";
var _output_format ="./dest/test%d.mov"

// start , duration の順番で刻みたい順番を入れます
var _rec_datas = [
	[14.4, 1.8],
	[17.5, 1.5],
];


// convert
convert();
function convert()
{
	// width, height
	var width = Math.floor(""+ _exec('ffmpeg -i ' + _input_path + ' 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 ' + _input_path + ' 2>&1 > /dev/null | grep Stream  | grep -o "[1-9][0-9]\\+x[1-9][0-9]\\+" | cut -d x -f2'));
	var new_width = width * _scale;
	var new_height = height * _scale;

	// calc 
	console.log( "target w:" + new_width + " / h:" + new_height);

	for(var i = 0; i <_rec_datas.length; i++)
	{
		var output_path = _util.format(_output_format, i)
		var command = _util.format( "ffmpeg -ss %d -i %s -t %d -vcodec copy -acodec copy %s", _rec_datas[i][0], _input_path, _rec_datas[i][1], output_path );
		
		var log = _exec( command );

		
		console.log( "- - - - - - - - - - - - - ");
		console.log( "コマンド : " + command);
		console.log( "ログ:" + log );
	}
}