title: Get frame from video bytes
body: <p>I'm extracting a frame from a video using ffmpeg and golang. If I have a video in bytes instead of saved on disk as an .mp4, how do I tell ffmpeg to read from those bytes without having to write the file to disk, as that is much slower?</p>
  
  <p>I have this working reading from a file, but I'm not sure how to read from bytes.</p>
  
  <p>I've looked at the <code>ffmpeg</code> documentation <a href="https://www.ffmpeg.org/ffmpeg.html#toc-Stream-selection" rel="nofollow noreferrer">here</a> but only see output examples instead of input examples.</p>
  
  <pre class="lang-golang prettyprint-override"><code>func ExtractImage(fileBytes []byte){
  
      // command line args, path, and command
      command = "ffmpeg"
      frameExtractionTime := "0:00:05.000"
      vframes := "1"
      qv := "2"
      output := "/home/ubuntu/media/video-to-image/output-" + time.Now().Format(time.Kitchen) + ".jpg"
  
      // TODO: use fileBytes instead of videoPath
      // create the command
      cmd := exec.Command(command,
          "-ss", frameExtractionTime,
          "-i", videoPath,
          "-vframes", vframes,
          "-q:v", qv,
          output)
  
      // run the command and don't wait for it to finish. waiting exec is run
      // ignore errors for examples-sake
      _ = cmd.Start()
      _ = cmd.Wait()
  }
  </code></pre>