Update documents

This commit is contained in:
Jerome Wu
2020-04-28 19:36:33 +08:00
parent b36360f16f
commit 55cbf63fb1
14 changed files with 202 additions and 244 deletions

View File

@@ -21,34 +21,30 @@
<p id="message"></p>
<a href="https://github.com/ffmpegjs/ffmpeg.js/tree/master/tests/assets/triangle">Data Set</a>
<script>
const { createWorker } = FFmpeg;
const worker = createWorker({
corePath: '../../node_modules/@ffmpeg/core/ffmpeg-core.js',
progress: (p) => console.log(p),
});
const { createFFmpeg } = FFmpeg;
const ffmpeg = createFFmpeg({ log: true });
const image2video = async () => {
const message = document.getElementById('message');
message.innerHTML = 'Loading ffmpeg-core.js';
await worker.load();
await ffmpeg.load();
message.innerHTML = 'Loading data';
await worker.write('audio.ogg', '../../tests/assets/triangle/audio.ogg');
await ffmpeg.write('audio.ogg', '../../tests/assets/triangle/audio.ogg');
for (let i = 0; i < 60; i += 1) {
const num = `00${i}`.slice(-3);
await worker.write(`tmp.${num}.png`, `../../tests/assets/triangle/tmp.${num}.png`);
await ffmpeg.write(`tmp.${num}.png`, `../../tests/assets/triangle/tmp.${num}.png`);
}
message.innerHTML = 'Start transcoding';
await worker.run('-framerate 30 -pattern_type glob -i /data/*.png -i /data/audio.ogg -c:a copy -shortest -c:v libx264 -pix_fmt yuv420p out.mp4', { output: 'out.mp4' });
const { data } = await worker.read('out.mp4');
await worker.remove('audio.ogg');
await ffmpeg.run('-framerate 30 -pattern_type glob -i *.png -i audio.ogg -c:a copy -shortest -c:v libx264 -pix_fmt yuv420p out.mp4', { output: 'out.mp4' });
const data = await ffmpeg.read('out.mp4');
await ffmpeg.remove('audio.ogg');
for (let i = 0; i < 60; i += 1) {
const num = `00${i}`.slice(-3);
await worker.remove(`tmp.${num}.png`);
await ffmpeg.remove(`tmp.${num}.png`);
}
const video = document.getElementById('output-video');
video.src = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' }));
await worker.terminate();
}
const elm = document.getElementById('start-btn');
elm.addEventListener('click', image2video);