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.

surface.Crop Error: Segmentation fault #489

@AlexanderSlav

Description

@AlexanderSlav

Describe the bug
While trying to use the surface.Crop function in docker container (not original one), I encountered a segmentation fault error.
The program crashes when trying to crop a decoded surface.
In original docker container, the function call results in the program freezing indefinitely.

To Reproduce

Run the following code snippet that reproduces the error:

import PyNvCodec as nvc

def main():
    video_path = "rtmp://video.osai.ai/vod/big_buck_bunny.mp4"

    decoder = nvc.PyNvDecoder(input=video_path, gpu_id=0)
    surface = decoder.DecodeSingleSurface()

    if surface.Empty():
        print("Can't decode frame. End of frames.")
        return

    print("Decoded surface:", surface)
    
    crop_coords = (0.0, 0.1, 0.5, 0.8)

    
    crop_coords_abs = (
        int(crop_coords[0] * surface.Width()),
        int(crop_coords[1] * surface.Height()),
        int(crop_coords[2] * surface.Width()),
        int(crop_coords[3] * surface.Height()),
    )
    
    print("Calculated coordinates:", crop_coords_abs)
    print("Video HxW",  surface.Height(), surface.Width())
    print("Trying to make a crop....")
    cropped_surface = surface.Crop(
        x=crop_coords_abs[0],
        y=crop_coords_abs[1],
        w=crop_coords_abs[2] - crop_coords_abs[0],
        h=crop_coords_abs[3] - crop_coords_abs[1],
        gpu_id=0,
    )
    print("Cropping finished....")

    print("Cropped surface:", cropped_surface)

if __name__ == "__main__":
    main()

in my work dokai container i got following log:

Decoded surface: Width: 1280
Height:           720
Format:           NV12
Pitch:            1536
Elem size(bytes): 1
Plane 0
  Owns mem:  0
  Width:     1280
  Height:    1080
  Pitch:     1536
  Elem size: 1
  Cuda ctx:  0x564276ca8990
  CUDA ptr:  77594624


Calculated coordinates: (0, 72, 640, 576)
Video HxW 720 1280
Trying to make a crop....
Segmentation fault (core dumped)

Expected behavior
The surface.Crop function is expected to create and return a new surface that is a cropped version of the original decoded surface without causing a crash or freeze.

Desktop

  • OS: Ubuntu 22.04.2 LTS, Kernel 5.15.0-60-generic
  • Nvidia driver version: 525.89.02
  • Nvidia GPU model: NVIDIA A30
  • CUDA Version: 12.0
  • Python Version: Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux (in dokai image)

Additional context
I initially encountered this problem in a container based on the dokai image - https://github.com/osai-ai/dokai/tree/master#vpf.
I also attempted to reproduce the error in the original VPF docker container. While I couldn't fully reproduce the segmentation fault, the call to surface.Crop resulted in the program freezing indefinitely with following log:

Decoded surface: Width: 1280
Height:           720
Format:           NV12
Pitch:            1536
Elem size(bytes): 1
Plane 0
  Owns mem:  0
  Width:     1280
  Height:    1080
  Pitch:     1536
  Elem size: 1
  Cuda ctx:  0x556699893600
  CUDA ptr:  54525952


Calculated coordinates: (0, 72, 640, 576)
Video HxW 720 1280
Trying to make a crop....

Metadata

Metadata

Assignees

No one assigned

    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