UNPKG

@gpeng/macadam

Version:

Async node.js interface to Blackmagic Design capture and playback devices.

97 lines (91 loc) 3.17 kB
const macadam = require("../index.js"); //console.log(macadam); //console.log(macadam.convertBGRAToYUV422); // let deviceInfo = macadam.getDeviceInfo(); // let config = macadam.getDeviceConfig(0); // let status = macadam.getDeviceStatus(0); // console.log(status); // for (let key in status) { // console.log(key, macadam.intToBMCode(status[key])); // } //console.log(config); const width = 1920; const height = 1080; const pixel = Buffer.from([0, 0, 255, 255]); // B,G,R,A const buffer = Buffer.allocUnsafe(width * height * 4); for (let i = 0; i < buffer.length; i += 4) { pixel.copy(buffer, i); } async function play() { try { let playback = await macadam.playback({ deviceIndex: 0, // Index relative to the 'macadam.getDeviceInfo()' array displayMode: macadam.bmdModeHD1080p50, pixelFormat: macadam.bmdFormat8BitYUV, }); function timer(t) { return new Promise((f, r) => { setTimeout(f, t); }); } for (let x = 0; x < 15; x++) { // Get hold of frame data as a Node.JS buffer console.log("Frame " + x); let yuvBuffer = await macadam.convertBGRAToYUV422_BT709(buffer); await playback.displayFrame(yuvBuffer); await timer(500); // Replace frame data around every half second } playback.stop(); return; } catch (e) { console.log(JSON.stringify(e, null, 2)); } } async function capture() { try { let capture = await macadam.capture({ deviceIndex: 0, // Index relative to the 'macadam.getDeviceInfo()' array displayMode: macadam.bmdModeHD1080p30, pixelFormat: macadam.bmdFormat8BitARGB, // channels: 2, // sampleRate: macadam.bmdAudioSampleRate48kHz, // sampleType: macadam.bmdAudioSampleType16bitInteger, }); // for (let x = 0; x < 1000; x++) { // let frame = await capture.frame(); // console.log(frame); // } let frame = await capture.frame(); capture.stop(); } catch (e) { console.log(JSON.stringify(e, null, 2)); } } async function CaptureAndPlayback() { let status = macadam.getDeviceStatus(0); console.log(status); console.log(macadam.bmdModeHD1080p50); console.log(macadam.bmdFormat8BitYUV); let capture = await macadam.capture({ deviceIndex: 0, // Index relative to the 'macadam.getDeviceInfo()' array displayMode: status.currentVideoInputMode, pixelFormat: status.currentVideoInputPixelFormat, // channels: 2, // sampleRate: macadam.bmdAudioSampleRate48kHz, // sampleType: macadam.bmdAudioSampleType16bitInteger, }); let playback = await macadam.playback({ deviceIndex: 0, // Index relative to the 'macadam.getDeviceInfo()' array displayMode: status.currentVideoInputMode, pixelFormat: status.currentVideoInputPixelFormat, }); for (let x = 0; x < 1500; x++) { // Get hold of frame data as a Node.JS buffer //console.log("Frame " + x); const buffer = await capture.frame(); //console.log(buffer); await playback.displayFrame(buffer.video.data); } } CaptureAndPlayback(); //play().then(play);