ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
14.57k stars 858 forks source link

ffmpeg.run() never completes/resolves when passed '-' for output file name #191

Open jmdevy opened 3 years ago

jmdevy commented 3 years ago

As the title says, if '-' is passed so that 'stdout' is sent through 'ffout' in the logger, then code afterwards will never be reached. The below example shows this. I am using 0.9.5 since versions above this gives the #124 error.

<html>
  <head>
    <style>
      html, body {
        margin: 0;
        width: 100%;
        height: 100%
      }
      body {
        display: flex;
        flex-direction: column;
        align-items: center;
      }
    </style>
  </head>

  <body>
    <video id="player" controls></video>
    <input type="file" id="uploader">
    <a href="link" id="link">link</a>
  </body>

  <script src="https://unpkg.com/@ffmpeg/ffmpeg@0.9.5/dist/ffmpeg.min.js"></script>
  <script>
    // NOTE: Version 0.9.6+ of ffmpeg.wasm does not like to work, using 0.9.5
    const { createFFmpeg, fetchFile } = FFmpeg;
    const ffmpeg = createFFmpeg({ log: false});

    ffmpeg.setLogger(({ type, message }) => {
      if(type != "ffout"){
        console.log("[" + type + "]", message);
      }
    });

    // Do the ffmpeg conversion using ffmpeg.wasm
    const transcode = async ({ target: { files } }) => {
      var input_file = files[0];
      const { name } = input_file;
      await ffmpeg.load();
      ffmpeg.FS('writeFile', name, await fetchFile(input_file)); 

      console.log("Running ffmpeg for VIDEO data..."); 
      await ffmpeg.run('-i', name, '-f', 'image2pipe', '-vsync', '-1', '-vcodec', 'rawvideo', '-pix_fmt', 'bgr565be', '-f', 'rawvideo', '-'); 

      console.log("DONE!");
  </script>
</html>

In the above code, 'console.log("DONE!");' is never reached. However, if '-' is replaced with an actual output file name, like "output.mp4" then code after run() will be reached.

brunoais commented 1 year ago

Did you try preparing the virtual filesystem as explained here? https://stackoverflow.com/a/33119868/551625