Search code examples
pythonffmpegv4l2

How can I output to a v4l2 driver using FFMPEG's avformat_write_header?


I'm trying to use PyAV to output video to a V4l2 loopback device (/dev/video1), but I can't figure out how to do it. It uses the avformat_write_header() from libav* (ffmpeg bindings).

I've been able to get ffmpeg to output to the v4l2 device from the CLI but not from python.


Solution

  • Found the solution. The way to do this is:

    1. Set the container format to v4l2
    2. Set the stream format as "rawvideo"
    3. Set the framerate (if it's a live stream, set the framerate to 1 fps higher than the stream is so that you don't get an error)
    4. Set pixel format to either RGB24 or YUV420