ffmpeg.wasm
ffmpeg.wasm copied to clipboard
How to get HLS stream format output files from ffmpeg?
I want to convert a input file into HLS stream format and then for each part of the file upload it to IPFS. The problem is I can't just call ffmpeg.FS('readFile', 'part_001.ts')
because I don't know how many part_xxx.ts
files there will be. So how to do in this case?
<script>
//navigator.serviceWorker.register('/ffmpeg.min.js');
//navigator.serviceWorker.register('/ffmpeg-core.js');
const { createFFmpeg, fetchFile } = FFmpeg;
const ffmpeg = createFFmpeg({
corePath: 'https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg-core.js',
log: true,
});
ffmpeg.setLogger(({ type, message }) => {
console.log(type, message);
});
const transcode = async ({ target: { files } }) => {
console.log('Running ffmpeg')
const { name } = files[0];
await ffmpeg.load();
ffmpeg.FS('writeFile', name, await fetchFile(files[0]));
await ffmpeg.run('-i', name, '-hls_time', '10', '-hls_playlist_type', 'vod', '-hls_segment_filename', 'part_%03d.ts', 'master.m3u8');
// ffmpeg -i name -hls_time 10 -hls_playlist_type vod -hls_segment_filename part_%03d.ts master.m3u8
}
document.getElementById('uploader').addEventListener('change', transcode);
</script>
for an HLS playlist i would just parse the segments from the index.m3u8 playlist
@sicksid is it possible to get each file content at the moment it is generated? For example, if I'm converting a 50mb file it will have a lot of part_xxx
files and until part_050 is generated I could be already have processed the others _049 meanwhile... inside the setLogger
callback, or any other place, is it possible to access the file using ffmpeg.wasm API?
yeah man if i understand correctly what you want, just save the references in a variable, also you can write files in a predictive way so you can also read them if you savd the reference
If anyone uses vite for development, this was really helpful: https://gist.github.com/mizchi/afcc5cf233c9e6943720fde4b4579a2b
If anyone uses vite for development, this was really helpful: https://gist.github.com/mizchi/afcc5cf233c9e6943720fde4b4579a2b
Can you explain what problem does this solve?
Hey sure, I think there was an issue with CORS/wasm on an older version of the vite development server. This meant Chrome refused to run it, and this gist helped fixing it.
I'm not sure if this is still a problem though.