mcopy/app/lib/capture/index.js

222 lines
4.4 KiB
JavaScript
Raw Normal View History

capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
var capture = {},
eventEmitter,
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
fs = require('fs'),
exec = require('child_process').exec;
2016-06-29 16:01:17 +00:00
capture.active = false;
capture.store = {
events : [],
start : 0
};
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
capture.start = function (first) {
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
'use strict';
2016-06-21 19:25:29 +00:00
//reset storage
2016-06-29 16:01:17 +00:00
if (capture.active) {
capture.store.events = [];
capture.store.start = +new Date();
}
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
};
capture.end = function () {
'use strict';
2016-06-29 16:01:17 +00:00
if (capture.active) {
return capture.save();
} else {
return '';
}
};
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
capture.proj_start = function () {
'use strict';
var e = {
'start' : +new Date()
};
capture.store.events.push(e);
};
capture.proj_end = function () {
'use strict';
var e = {
'end' : +new Date()
};
capture.store.events.push(e);
};
//out-000001
capture.pad = function (frame, len) {
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
'use strict';
var pad = '',
ch = '0';
frame += '';
len = len - frame.length;
if (len <= 0) return frame;
while (true) {
if (len & 1) {
pad += ch;
}
len >>= 1;
if (len) {
ch += ch;
} else {
break;
}
}
return pad + frame;
};
capture.extract = function (input, output, good, real, neg) {
'use strict';
var tc = capture.report.timecode(good),
frame = capture.pad(real, 6),
neg_cmd = ' -vf lutrgb="r=negval:g=negval:b=negval" ',
cmd = 'ffmpeg -ss ' + tc + ' -i ' + input + '{{neg_cmd}}-vframes 1 ' + output + 'out-' + frame + '.tif';
if (neg) {
cmd = cmd.replace('{{neg_cmd}}', neg_cmd);
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
} else {
cmd = cmd.replace('{{neg_cmd}}', ' ');
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
}
console.log(cmd);
exec(cmd, function (err, std) {
console.log(err);
console.log(std);
});
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
};
capture.cp = function (input, output, good, real) {
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
'use strict';
var still = '';
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
};
capture.test = function () {
'use strict';
var i = -1,
len = 10,
intval,
next = function () {
i++
if (i === len) {
clearInterval(intval);
intval = null;
//console.dir(capture.store);
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
parse();
} else {
if (i % 2 === 0) {
capture.proj_start();
} else {
capture.proj_end();
}
}
},
parse = function () {
capture.report.parse(45, 0);
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
};
capture.start();
next();
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
intval = setInterval(next, 800);
};
capture.init = function () {
'use strict';
eventEmitter.on('arduino_send', function (cmd) {
if (capture.active
&& cmd.trim() === 'p') {
capture.proj_start();
}
});
eventEmitter.on('arduino_end', function (cmd) {
if (capture.active
&& cmd.trim() === 'p') {
capture.proj_end();
}
});
};
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00
capture.save = function () {
'use strict';
var file = './data/transfer-',
time = +new Date(),
json = JSON.stringify(capture.store);
fs.writeFileSync(file + time + '.json', json, 'utf8');
return file + time + '.json';
};
//ffmpeg -f image2 -framerate 24 -start_number 090000 -i input_file_%06d.ext -c:v v210 -an output_file
//'-%06d
capture.report = {};
capture.report.parse = function (inmark, first, report, fps) {
'use strict';
var all = [],
output = {
good : [],
real : []
},
good = [],
real,
f,
frame,
last = -1,
i;
if (typeof fps === 'undefined') {
fps = 24;
}
f = 1000 / fps;
if (typeof report === 'undefined') {
report = capture.store;
}
if (typeof first === 'undefined') {
first = 0;
}
if (typeof inmark === 'undefined') {
inmark = 0;
}
//first clean frame
for (i = 0; i < report.events.length; i++) {
if (typeof report.events[i].end !== 'undefined') {
frame = (report.events[i].end - report.start) / f;
frame = Math.round(frame);
last = frame;
} else if (typeof report.events[i].start !== 'undefined') {
frame = (report.events[i].start - report.start) / f;
frame = Math.round(frame);
if (last !== -1) {
//console.log(last + '-' + frame);
all.push(capture.report.arr(last, frame));
}
}
}
good = all.map(function (arr) {
var center = Math.round(arr.length / 2);
return arr[center] + inmark;
});
real = output.map(function (val, i) {
return first + i;
});
output.good = good;
output.real = real;
return output;
};
capture.report.arr = function (start, end) {
'use strict';
var arr = [],
i;
for (i = start; i < end + 1; i++) {
arr.push(i);
}
return arr;
};
capture.report.timecode = function (frame) {
'use strict';
//00:03:00 no dropframe
var a = capture.pad(Math.floor((frame / 60) / 60), 2),
b = capture.pad(Math.floor(frame / 60), 2),
c = capture.pad(frame % 24);
return a + ':' + b + ':' + c;
};
capture.report.render = function () {
'use strict';
};
module.exports = function (ee) {
eventEmitter = ee;
return capture;
};
capture-report library for creating a telecine method The purpose of this module will be to generate a report of the projector actions that can be translated into rendering instructions for a telecine. First tests will be done on a Blackmagic Pocket Cinema camera which will record a 4000 frame sequence (100ft of 16mm). The report will allow me to record the entire sequence of the projector advancing 4000 frames and will make a list of acceptable frames to pull out for stitching together into a sequence. It is amazingly inefficient in terms of disk space, but will make this setup much cheaper than one that requires purchasing hardware to capture images to disk during operation. Rubber ducking: The report will watch for projector start and end times in milliseconds, with a “start” value to be factored in later. On every projector start and end event, when capture is active, an event with the millisecond of the occurrence is logged to the report. At the end of the sequence, the report will be parsed to determine the acceptable frames to export into a new sequence. This will be determined by finding a period between proj_end and proj_start events and dividing that into frames and picking the central most frame. Acceptable frames, marked by frame numbers, get put into an render list that gets pegged to a first frame and adjusted via offset. The export list will be fed into a command that will go through either a video file or an image sequence and output the determined frames into an image sequence that will be stitched together with ffmpeg/libav.
2016-06-19 00:49:39 +00:00