Я использую FFMPEG. js для преобразования изображений PNG в MP4 в браузере с этим кодом:
const { createWorker } = FFmpeg;
const worker = createWorker({
corePath: 'ffmpeg-core.min.js',
progress: (p) => console.log(p),
logger: ({ message }) => console.log(message),
});
const image2video = async (frames) => {
console.log('Loading ffmpeg-core.min.js');
await worker.load();
console.log('Loading data');
const d = new Date();
const timestamp = d.getTime();
for(let i = 0; i < frames.length; i += 1) {
const num = `00${i}`.slice(-3);
const fileName = `tmp.${timestamp}.${num}.png`;
console.log(fileName);
await worker.write(fileName, frames[i]); // base64 'image/png'
const { file } = await worker.read(fileName);
// throws -> Uncaught (in promise) TypeError: Cannot read property 'buffer' of undefined
const testFile = URL.createObjectURL(new Blob([file.buffer], { type: 'image/png' }));
console.log(testFile);
}
await worker.run('-framerate 30 -pattern_type glob -i /data/*.png -c:a copy -shortest -c:v libx264 -pix_fmt yuv420p out.mp4', { output: 'out.mp4' });
const { data } = await worker.read('out.mp4');
const outputURL = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' }));
console.log(outputURL);
}
Однако выдает:
[png @ 0x1175980] Warning: not compiled with thread support, using thread emulation
[image2 @ 0x1177180] Could not open file : /data/*.png
[image2 @ 0x1177180] Could not find codec parameters for stream 0 (Video: png, none(pc)): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, image2, from '/data/*.png':
Duration: 00:00:00.03, start: 0.000000, bitrate: N/A
Stream #0:0: Video: png, none(pc), 30 tbr, 30 tbn, 30 tbc
Output #0, mp4, to 'out.mp4':
Output file #0 does not contain any stream
Что здесь может отсутствовать?