title: Obtaining frames from IP Camera with low latency
body: <p>I am currently using this command to get frames from my RTSP stream and reading frames from stdout:</p>
  <pre><code>ffmpeg -nostdin -rtsp_transport tcp -i &lt;rtsp_stream&gt; -pix_fmt bgr24 -an -vcodec rawvideo -f rawvideo -
  </code></pre>
  <p>However, I would like to get the same latency as when I see it via ffplay:</p>
  <pre><code>ffplay -fflags nobuffer -flags low_delay -tune zerolatency -framedrop -rtsp_transport tcp &lt;rtsp_stream&gt;
  </code></pre>
  <p>or when I play it via VLC Media &gt; Open Network Stream with :network_caching=300ms.</p>
  <p>I would like to know what other parameters I can use with my ffmpeg command to get an equivalent (or better) result compared to the ffplay command.</p>
  <p>I have made references from: <a href="https://stackoverflow.com/questions/16259588/how-to-dump-raw-rtsp-stream-to-file">How to dump raw RTSP stream to file?</a>,  <a href="https://stackoverflow.com/questions/60816436/open-cv-rtsp-camera-buffer-lag">Open CV RTSP camera buffer lag</a>, <a href="https://stackoverflow.com/questions/55001241/how-to-pipe-output-from-ffmpeg-using-python">How to pipe output from ffmpeg using python?</a>, <a href="https://stackoverflow.com/questions/68824225/bad-ffmpeg-performace-compared-to-ffplay-and-vlc">bad ffmpeg performace compared to ffplay and VLC</a>, <a href="https://stackoverflow.com/questions/16658873/how-to-minimize-the-delay-in-a-live-streaming-with-ffmpeg">How to minimize the delay in a live streaming with ffmpeg</a></p>
  <p>My current implmentation:</p>
  <pre><code>FFMPEG_CMD = &quot;ffmpeg -nostdin -rtsp_transport tcp -i &lt;rtsp_stream&gt; -pix_fmt bgr24 -an -vcodec rawvideo -f rawvideo -&quot;.split(&quot; &quot;)
  WIDTH = 2560
  HEIGHT = 1440
  
  process = subprocess.Popen(FFMPEG_CMD, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
  
  while True:
      raw_frame = process.stdout.read(WIDTH*HEIGHT*3)
      frame = np.frombuffer(raw_frame, np.uint8) 
      frame = frame.reshape((HEIGHT, WIDTH, 3))
  
      &lt;do stuff with frame/ show frame etc.&gt;
  </code></pre>
  <p>Thanks for reading.</p>
  <hr />
  <p><code>ffmpeg</code> command I am now using for &lt; 1s latency.</p>
  <pre><code>ffmpeg -nostdin -flags low_delay -rtsp_transport tcp -i &lt;rtsp_stream&gt; -pix_fmt bgr24 -an -vcodec rawvideo -f rawvideo -
  </code></pre>
  <hr />
  <p>Implementation with suggestion(s) from Answers:</p>
  <pre><code>import subprocess
  import numpy as np
  
  FFMPEG_CMD = &quot;ffmpeg -nostdin -flags low_delay -rtsp_transport tcp -i &lt;rtsp_stream&gt; -pix_fmt bgr24 -an -vcodec rawvideo -f rawvideo -&quot;.split(&quot; &quot;)
  WIDTH = 2560
  HEIGHT = 1440
  
  process = subprocess.Popen(FFMPEG_CMD, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
  
  raw_frame = np.empty((HEIGHT, WIDTH, 3), np.uint8) 
  frame_bytes = memoryview(raw_frame).cast(&quot;B&quot;)
  
  while process.poll() is None:
      process.stdout.readinto(frame_bytes)
      frame = raw_frame.reshape((HEIGHT, WIDTH, 3))
  
      &lt;do stuff with frame/ show frame etc.&gt;
  </code></pre>