Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

What can i do for get the newest frame from stream media. #471

Closed
@summm

Description

@summm

Really strange, the decoding speed is ten times faster than the other, but with this code, the final video displayed in front of me is 50-100ms later than the other, probably a 3-6 frame delay. How can I get the latest frame of the streaming media as quickly as possible?

video_path = "http://192.168.0.5/test.flv"

nvDec = nvc.PyNvDecoder(video_path, 0,)#{'max_delay': '1', 'bufsize': '1k'}
# nvCvt = nvc.PySurfaceResizer(1080, 720, nvDec.Format(), 0)
x_width, x_height = nvDec.Width(), nvDec.Height()
to_rgb = cconverter(x_width, x_height, 0)
to_rgb.add(nvc.PixelFormat.NV12, nvc.PixelFormat.YUV420)
to_rgb.add(nvc.PixelFormat.YUV420, nvc.PixelFormat.RGB)
#to_rgb.add(nvc.PixelFormat.RGB, nvc.PixelFormat.RGB_PLANAR)
nvDwn = nvc.PySurfaceDownloader(x_width, x_height, nvc.PixelFormat.RGB, 0)
while True:
    #t1 = time.time()
    src_surface = nvDec.DecodeSingleSurface()
    if src_surface.Empty():
        break
    #t2=time.time()
    #print(t2-t1)

    rgb_pln = to_rgb.run(src_surface)
    if rgb_pln.Empty():
        break

    frameRGB = np.ndarray(shape=(rgb_pln.HostSize()), dtype=np.uint8)
    success = nvDwn.DownloadSingleSurface(rgb_pln, frameRGB)

    #cv2.imwrite("{}.jpg".format(count), frameRGB.reshape((x_height, x_width, 3)))
    cv2.imshow("PyNvCodec",frameRGB.reshape((x_height, x_width, 3)))
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions