title: How to record depth stream from realsense L515
body: <p>I have a depth camera (Intel Realsense <strong>L515</strong>) and I do like to record a video of the depth.</p>
  <p>I have seen this <a href="https://stackoverflow.com/a/66604533">answer</a> which is using <strong>FFMPEG</strong>, but I didn't know how to replicate it in my case!</p>
  <p>I'm using this code:</p>
  <pre class="lang-py prettyprint-override"><code>import cv2
  import numpy as np
  import pyrealsense2 as rs
  import time
  
  pipeline = rs.pipeline()
  config = rs.config()
  
  &quot;&quot;&quot;
  # Depth Mode
  &quot;&quot;&quot;
  # Resolution
  res = [(1024, 768), (640, 480), (320, 240)]
  resolution = res[0]
  print(&quot;RealSense Resolution:{}\n&quot;.format(resolution))
  
  # # initialize video writer
  fourcc = cv2.VideoWriter_fourcc('F','F','V','1')
  fps = 30
  video_filename = 'output.avi'
  out = cv2.VideoWriter(video_filename, fourcc, fps, resolution, False)
  
  
  config.enable_stream(rs.stream.depth, resolution[0], resolution[1], rs.format.z16, 30)
  profile = config.resolve(pipeline)
  # Start streaming
  pipeline.start(config)
  
  # Declare sensor object and set options
  depth_sensor = profile.get_device().first_depth_sensor()
  depth_sensor.set_option(rs.option.visual_preset, 5) # 5 is short range, 3 is low ambient light
  depth_sensor.set_option(rs.option.receiver_gain, 8)
  depth_sensor.set_option(rs.option.pre_processing_sharpening, 0.0)
  depth_sensor.set_option(rs.option.post_processing_sharpening, 3.0)
  depth_sensor.set_option(rs.option.laser_power, 100)
  depth_sensor.set_option(rs.option.confidence_threshold, 2)
  # Get the sensor once at the beginning. (Sensor index: 1)
  
  # # Filters
  threshold_filter = rs.threshold_filter(min_dist=1.2, max_dist=1.4)
  temporal_filter = rs.temporal_filter(smooth_alpha=0.1, smooth_delta = 9.0,persistence_control=7)
  
  try:
      # # Filters
      threshold_filter = rs.threshold_filter(min_dist=1.2, max_dist=1.4)
      temporal_filter = rs.temporal_filter(smooth_alpha=0.1, smooth_delta = 75.0,persistence_control=0)
  
      tic = time.time()
  
      while True:
          # Wait for depth frames:
          frames = pipeline.wait_for_frames()
          depth_frame = frames.get_depth_frame()
          if not depth_frame:
              continue
  
          #------------
          # # FILTERS |
          #------------
  
          depth_frame = threshold_filter.process(depth_frame)
          depth_frame = temporal_filter.process(depth_frame)
  
          # Convert images to numpy arrays
          depth_array = np.asanyarray(depth_frame.get_data())
          # depth_array = np.asanyarray(colorizer.colorize(depth_frame).get_data())
  
          out.write(depth_array)
          toc = time.time()
          if(round(toc  - tic) &gt; 30):
              break
  
  finally:
      out.release()
      pipeline.stop()
  </code></pre>
  <p>And getting this error:</p>
  <blockquote>
  <p>out.write(depth_array)
  cv2.error: OpenCV(4.5.4) /tmp/pip-req-build-kneyjnox/opencv/modules/videoio/src/cap_ffmpeg.cpp:186: error: (-215:Assertion failed) image.depth() == CV_8U in function 'write'</p>
  </blockquote>
  <p>Can you please tell me how can I record the depth from my camera? thanks in advance.</p>