title: Writing to ffpmeg stdin freezes program
body: <p>I'm trying to convert a file in memory using ffmpeg to another format by using stdin and stdout, but everytime I try to write to stdin, of my ffmpeg command, it just freezes there.</p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;bufio&quot;
      &quot;fmt&quot;
      &quot;io&quot;
      &quot;os&quot;
      &quot;os/exec&quot;
  )
  
  func test(bytes []byte) ([]byte, error) {
  
      cmd := exec.Command(
          &quot;ffmpeg&quot;,
          &quot;-i&quot;, &quot;pipe:0&quot;, // read from stdin
          &quot;-vcodec&quot;, &quot;copy&quot;,
          &quot;-acodec&quot;, &quot;copy&quot;,
          &quot;-f&quot;, &quot;matroska&quot;,
          &quot;pipe:1&quot;,
      )
  
      in, err := cmd.StdinPipe()
      if err != nil {
          panic(err)
      }
      out, err := cmd.StdoutPipe()
      if err != nil {
          panic(err)
      }
  
      fmt.Println(&quot;starting&quot;)
      err = cmd.Start()
      if err != nil {
          panic(err)
      }
  
      fmt.Println(&quot;writing&quot;)
      w := bufio.NewWriter(in)
      _, err = w.Write(bytes)
      if err != nil {
          panic(err)
      }
  
      err = w.Flush()
      if err != nil {
          panic(err)
      }
  
      err = in.Close()
      if err != nil {
          panic(err)
      }
  
      fmt.Println(&quot;reading&quot;)
      outBytes, err := io.ReadAll(out)
      if err != nil {
          panic(err)
      }
  
      fmt.Println(&quot;waiting&quot;)
      err = cmd.Wait()
      if err != nil {
          panic(err)
      }
  
      return outBytes, nil
  }
  
  func main() {
      dat, err := os.ReadFile(&quot;speech.mp4&quot;)
      if err != nil {
          panic(err)
      }
  
      out, err := test(dat)
      if err != nil {
          panic(err)
      }
  
      err = os.WriteFile(&quot;test.m4v&quot;, out, 0644)
      if err != nil {
          panic(err)
      }
  }
  
  
  </code></pre>
  <p>It prints</p>
  <pre><code>starting
  writing
  
  </code></pre>
  <p>and gets stuck there. I tried similar code with grep, and the everything worked fine, so this seems to be some ffmpeg specific problem.</p>
  <p>I tried running</p>
  <p><code>cat speech.mp4 | ffmpeg -i pipe:0 -vcodec copy -acodec copy -f matroska pipe:1 | cat &gt;  test.mkv</code></p>
  <p>and that works fine, so it's not an ffmpeg problem, but some problem with how I'm piping/reading/writing my data.</p>
  <p>My speech.mp4 file is around 2MB.</p>