rtsp icon indicating copy to clipboard operation
rtsp copied to clipboard

AttributeError: 'NoneType' object has no attribute 'shape' during write video output using ffmpegcv

Open sugizo opened this issue 1 year ago • 1 comments

objective write video output using ffmpegcv

steps pip install -U rtsp ffmpegcv

code

import rtsp
import ffmpegcv
url = 'http://clausenrc5.viewnetcam.com:50003/nphMotionJpeg?Resolution=320x240' # aspect ratio = 4:3
client = rtsp.Client(rtsp_server_uri = url, verbose = False)
output_file = 'rtsp_ffmpegcv_time.mp4'
vidout = ffmpegcv.VideoWriter(output_file, None, pix_fmt = 'bgr24')
i = 0
while i <= 9:
    frame = client.read(raw = True)
    vidout.write(frame)
    i += 1
client.close()
vidout.release()

result

AttributeError                            Traceback (most recent call last)
[<ipython-input-29-fc5430a80232>](https://localhost:8080/#) in <cell line: 11>()
     12     frame = client.read(raw = True)
     13 
---> 14     vidout.write(frame)
     15 
     16     i += 1

[/usr/local/lib/python3.10/dist-packages/ffmpegcv/ffmpeg_writer.py](https://localhost:8080/#) in write(self, img)
     65                 height = int(height_15 / 1.5)
     66             else:
---> 67                 height, width = img.shape[:2]
     68             self.width, self.height = width, height
     69             self.in_numpy_shape = img.shape

AttributeError: 'NoneType' object has no attribute 'shape'

best regards

sugizo avatar Mar 17 '24 13:03 sugizo

code

import rtsp
client = rtsp.Client(rtsp_server_uri = url, verbose = True)
i = 0
while i <= 9:
    frame = client.read(raw = True)
    print(frame)
    i += 1
client.close()

result sometime return numpy array sometime None but the same code on first post is work well when using vidgear to write the output video

best regards

sugizo avatar Mar 18 '24 06:03 sugizo