title: How to pipe rawvideo to v4l2loopback using ffmpeg?
body: <p>I am trying to process a video by OpenCV in Python and then send each frame to a virtual camera (i.e., v4l2loopback). I have seen questions asked where OpenCV output is piped to ffmpeg and saved into a file, and other questions where a video file is piped to v4l2 using ffmpeg, but no question where these two are combined. I can do either of the above two things on their own, but not combined.</p>
  
  <p>My Python code uses a subprocess to pipe each frame to ffmpeg. The ffmpeg command for piping the output of OpenCV to an .mp4 file is </p>
  
  <pre><code>ffmpeg -y -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt bgr24 -i - -vcodec libx264 -crf 0 -preset fast output.mp4
  </code></pre>
  
  <p>This works and I have tested it.</p>
  
  <p>The ffmpeg command to pipe a video file to the v4l2 virtual camera is</p>
  
  <pre><code>ffmpeg -re -i input.mp4 -map 0:v -f v4l2 /dev/video0
  </code></pre>
  
  <p>This also works and I have tested it.</p>
  
  <p>I tried combining the above two commands and came up with</p>
  
  <pre><code>ffmpeg -y -f rawvideo -vcodec rawvideo -s 1280x720 -pix_fmt bgr24 -i - -vcodec libx264 -crf 0 -preset fast -map 0:v -f v4l2 /dev/video0
  </code></pre>
  
  <p>but I get the following error</p>
  
  <blockquote>
    <p>[NULL @ 0x55a12fcc60] Unable to find a suitable output format for ''
    : Invalid argument</p>
  </blockquote>
  
  <p>I would be glad if anyone could help me figure this out.</p>
  
  <p>Thanks.</p>