title: How do I add a delay to a live stream sourced from webcam (v4l2) with FFMPEG?
body: <p>How can I use FFMPEG to add a delay to a stream being sent from a (v4l2) webcam to a media server?</p>
  
  <p>The use case here is something like a security camera where I want to be able to stream video to a server when something is detected in the video. The easiest way to ensure the event of interest is captured on the video is to use FFMPEG to stream from the camera to a virtual loopback device with an added delay. That loopback device can then be used to initiate live streaming when an even of interest occurs.</p>
  
  <p>In GStreamer, I would accomplish a delay of this sort with the <code>queue</code> element's <code>min-threshold-time</code> parameter. For example the following (much-simplified) example pipeline adds a 2 second delay to the output coming from a v4l2 webcam before displaying it:</p>
  
  <p><code>gst-launch-1.0 v4l2src device=/dev/video1 ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 min-threshold-time=2000000000 ! xvimagesink</code></p>
  
  <p>How do I accomplish the same thing with FFMPEG? There are some technical challenges that prevent us from using GStreamer for this.</p>
  
  <p>I have investigated the <code>itsoffset</code> option for this, but as far as I can tell it is only usable for already-recorded files, and it is not clear what a good alternative would be.</p>