-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
converting image buffer to png #12
Comments
Hi @yyy898 You can try using the following library 'Sharp': https://github.com/lovell/sharp Best regards |
when i try |
Did someone managed to get this working ? I tried to pass the raw data to sharp because the frame data doesn't seems to contains any sort of png or jpeg formatted data. await sharp(image.data, {
raw: {
width: frame.xres,
height: frame.yres,
channels: 3,
},
}).toFile("test.jpeg"); But this still isn't working. I get the following error:
My image should be a perfectly white blank image. This is what my frame looks like when I log it: {
type: 'video',
xres: 1920,
yres: 1080,
frameRateN: 30000,
frameRateD: 1200,
pictureAspectRatio: 1.7777777910232544,
timestamp: [ 1637271127, 56764100 ],
frameFormatType: 1,
timecode: [ -41, 117500000 ],
lineStrideBytes: 3840,
data: <Buffer 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb 80 eb 7f eb ... 4147150 more bytes>
} The buffer seems to have a pattern that makes me think I'm on the right path. But I can't figure out how to get this working. Any help would be really appreciated. |
What options are you using on the grandiose receiver? const receiverOptions = {
// Ensure RGB frames are received
colorFormat: grandiose.COLOR_FORMAT_RGBX_RGBA,
// Ensure progressive frames are received
allowVideoFields: false
} |
Thank you for your help! I managed to get this working with your options. Here is my working code: const { writeFileSync } = require("fs");
const sharp = require("sharp");
const bmp = require("bmp-js");
const grandiose = require("./index");
const buffer = require("buffer");
async function saveScreenshot(receiver, name) {
const image = await receiver.video(10000);
try {
await sharp(image.data, {
raw: {
width: image.xres,
height: image.yres,
channels: 4,
},
}).toFile(name);
} catch (error) {
console.log(error);
}
}
async function bootstrap() {
const sources = await grandiose.find();
const obsLink = sources[0];
const receiver = await grandiose.receive({
source: obsLink,
colorFormat: grandiose.COLOR_FORMAT_RGBX_RGBA,
allowVideoFields: false,
});
await receiver.data();
saveScreenshot(receiver, "screenshot.jpeg");
}
bootstrap().catch(console.log); |
i can receive my ndi stream now and i can see the buffer from the image
how can i convert this buffer to a png or other image to view ?
The text was updated successfully, but these errors were encountered: