ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

How to get HLS stream format output files from ffmpeg?

Open FabioNevesRezende opened this issue 3 years ago • 4 comments

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>

FabioNevesRezende avatar Jun 16 '21 20:06 FabioNevesRezende

for an HLS playlist i would just parse the segments from the index.m3u8 playlist

abdul-hamid-achik avatar Jun 16 '21 20:06 abdul-hamid-achik

@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?

FabioNevesRezende avatar Jun 17 '21 18:06 FabioNevesRezende

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

abdul-hamid-achik avatar Jun 22 '21 16:06 abdul-hamid-achik

If anyone uses vite for development, this was really helpful: https://gist.github.com/mizchi/afcc5cf233c9e6943720fde4b4579a2b

shlomiatar avatar Jan 22 '22 13:01 shlomiatar

If anyone uses vite for development, this was really helpful: https://gist.github.com/mizchi/afcc5cf233c9e6943720fde4b4579a2b

Can you explain what problem does this solve?

cyango avatar Mar 01 '23 14:03 cyango

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.

shlomiatar avatar Mar 02 '23 06:03 shlomiatar