1
0
mirror of https://github.com/danog/plotframes.git synced 2024-12-02 09:17:52 +01:00

adding avg, min and max in plot.

This commit is contained in:
Rodrigo Polo MPW 2015-10-14 02:57:53 -06:00
parent e3991671d4
commit 8fd063561f

51
cli.js
View File

@ -134,10 +134,14 @@ function getDuration(input, cb){
// Get frame bitrate // Get frame bitrate
function getBitrate(input, time, cb){ function getBitrate(input, time, cb){
var frame_count = 0; var frame_count = 0,
var streams = []; kbps_count = 0,
var r; peak = 0,
var r_frame = /(?:media_type\=(\w+)\r?\n)(?:stream_index\=(\w+)\r?\n)(?:pkt_pts_time\=(\d*.?\d*)\r?\n)(?:pkt_size\=(\d+)\r?\n)(?:pict_type\=(\w+))?/; min = 0,
start= true,
streams = [],
r,
r_frame = /(?:media_type\=(\w+)\r?\n)(?:stream_index\=(\w+)\r?\n)(?:pkt_pts_time\=(\d*.?\d*)\r?\n)(?:pkt_size\=(\d+)\r?\n)(?:pict_type\=(\w+))?/;
var cli = child.spawn( var cli = child.spawn(
'ffprobe', [ 'ffprobe', [
@ -151,14 +155,20 @@ function getBitrate(input, time, cb){
cli.stdout.pipe(split(/\[\/FRAME\]\r?\n/)).on('data', function (data){ cli.stdout.pipe(split(/\[\/FRAME\]\r?\n/)).on('data', function (data){
if(r = r_frame.exec(data)){ if(r = r_frame.exec(data)){
frame_count++;
r[4] = (r[4]*8)/1000; r[4] = (r[4]*8)/1000;
r[3] = parseFloat(r[3]);
r[5] = r[5]?r[5]:'A'; frame_count++;
kbps_count += r[4];
if(start){min = r[4]; start=null;}
peak = peak < r[4] ? r[4] : peak;
min = min > r[4] ? r[4] : min;
r[5] = r[5]?r[5]:'A';
if(!streams[r[5]]){streams[r[5]] = temp.createWriteStream();}
r[3] = parseFloat(r[3]);
if(!streams[r[5]]){
streams[r[5]] = temp.createWriteStream();
}
streams[r[5]].write(frame_count+' '+r[4]+'\n'); streams[r[5]].write(frame_count+' '+r[4]+'\n');
cutelog('Analyzing '+toHHMMSS(r[3])+' / '+time.duration+' '+((r[3]/time.seconds)*100).toFixed(2)+'%',true); cutelog('Analyzing '+toHHMMSS(r[3])+' / '+time.duration+' '+((r[3]/time.seconds)*100).toFixed(2)+'%',true);
} }
@ -169,7 +179,12 @@ function getBitrate(input, time, cb){
cutelog('Error trying to get the file bitrate.',false); cutelog('Error trying to get the file bitrate.',false);
} }
cutelog('Analysis complete.',false); cutelog('Analysis complete.',false);
cb(streams); cb({
streams: streams,
avg: kbps_count/frame_count,
peak: peak,
min: min
});
}); });
@ -184,7 +199,7 @@ function getBitrate(input, time, cb){
} }
// Get file duration // Get file duration
function createPlot(streams, cb){ function createPlot(data, cb){
var cm = { var cm = {
P: 'green', P: 'green',
@ -194,16 +209,16 @@ function createPlot(streams, cb){
}; };
var sep=''; var sep='';
var scr='set title "Frames Sizes"\nset xlabel "Frames"\nset ylabel "Kbits"\nset grid\nset terminal "'+opts.terminal+'"\n'; var scr='set title "Frames Sizes in Kbits"\nset xlabel "Average: '+parseInt(data.avg)+', Peak: '+parseInt(data.peak)+', Min: '+parseInt(data.min)+'."\nset ylabel "Kbits"\nset grid\nset terminal "'+opts.terminal+'"\n';
if(opts.output){ if(opts.output){
scr += 'set output "'+opts.output+'"\n'; scr += 'set output "'+opts.output+'"\n';
} }
scr += 'plot'; scr += 'plot';
for(var k in cm){ for(var k in cm){
if(streams[k]){ if(data.streams[k]){
streams[k].end(); data.streams[k].end();
scr += sep+'"'+(streams[k].path).replace(/\\/g,'\\\\')+'" title "'+k+' frames" with impulses linecolor rgb "'+cm[k]+'"'; scr += sep+'"'+(data.streams[k].path).replace(/\\/g,'\\\\')+'" title "'+k+' frames" with impulses linecolor rgb "'+cm[k]+'"';
sep = ', '; sep = ', ';
} }
} }
@ -244,8 +259,8 @@ function createPlot(streams, cb){
// Run // Run
getDuration(opts.input, function(time){ getDuration(opts.input, function(time){
getBitrate(opts.input, time, function(streams){ getBitrate(opts.input, time, function(data){
createPlot(streams, function(){ createPlot(data, function(){
}); });
}); });
}); });