title: OpenCV - How do I log RSTP error from OpenCV?
body: <p>I have a RTSP link and use opencv videocapture to read frame.
  But sometime there are an error mainly because of the internet connection.</p>
  <pre><code>import cv2
  import os
  import time
   
  cap = cv2.VideoCapture(r'C:\Users\Asus\Downloads\NOVA_VSM\Test_case\ChoThongNhat-Cam2\2022-02-23-13-13-33_0000000630.ts')
  
  dir = r'Images'
  
  count = 0 
  while(cap.isOpened()):
      start_time = time.time()
      ret, frame = cap.read()
      print(&quot;Read time: &quot;, time.time() - start_time)
  
  
      if ret == True:
          cv2.imshow('Frame', cv2.resize(frame, (480, 640)))
          # path = os.path.join(dir, str(count) + &quot;.png&quot;)
          # #cv2.imwrite(path, frame)
          # count += 1
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              break
  
      else:
          break
  
  cap.release()
  
  cv2.destroyAllWindows()
  </code></pre>
  <p>This is an error.</p>
  <pre><code>[hevc @ 000001f2f9978940] Could not find ref with POC 22
  </code></pre>
  <p>I want to get this error and convert to string or just log to logfile.
  I redirected log from stdout like this</p>
  <pre><code>import sys
   
  path = 'path/to/some/dir/file.txt'
  sys.stdout = open(path, 'w')
  print('Hello, World')
  </code></pre>
  <p>Everything from print command is redirected to stdout but the above error still appeared. Can anybody help me to log the error?</p>