RomanArzumanyan / VALI

Video processing in Python
Apache License 2.0
21 stars 1 forks source link

P10 to NV12 Surface conversion crashes in 3.0.0 #40

Closed geheiligt closed 1 month ago

geheiligt commented 1 month ago

Hello, since version 3.0.0 the P10 to NV12 Surface conversion seems broken. The code below crashes in to_nv12.Execute(source, nv12, cc_ctx) (segmentation fault) for P10 videos, while working fine for NV12 videos.

import numpy as np
import PyNvCodec as nvc

gpu_id = 0
nvDec = nvc.PyNvDecoder("video.MP4", gpu_id)
width = nvDec.Width()
height = nvDec.Height()
target_w = 1920
target_h = 1080
if nvDec.Format() == nvc.PixelFormat.P10:
    to_nv12 = nvc.PySurfaceConverter(width, height, nvc.PixelFormat.P10, nvc.PixelFormat.NV12, gpu_id)
to_yuv = nvc.PySurfaceConverter(width, height, nvc.PixelFormat.NV12, nvc.PixelFormat.YUV420, gpu_id)
to_dim = nvc.PySurfaceResizer(target_w, target_h, nvc.PixelFormat.YUV420, gpu_id)
res_to_rgb = nvc.PySurfaceConverter(target_w, target_h, nvc.PixelFormat.YUV420, nvc.PixelFormat.RGB, gpu_id)
res_nvDwn = nvc.PySurfaceDownloader(target_w, target_h, nvc.PixelFormat.RGB, gpu_id)
cc_ctx = nvc.ColorspaceConversionContext(nvc.ColorSpace.BT_601, nvc.ColorRange.MPEG)

source, _ = nvDec.DecodeSingleSurface()
yuv = nvc.Surface.Make(nvc.PixelFormat.YUV420, width, height, gpu_id)
if nvDec.Format() == nvc.PixelFormat.P10:
    nv12 = nvc.Surface.Make(nvc.PixelFormat.NV12, width, height, gpu_id)
    to_nv12.Execute(source, nv12, cc_ctx)
    to_yuv.Execute(nv12, yuv, cc_ctx)
else:
    to_yuv.Execute(source, yuv, cc_ctx)
yuv_small = to_dim.Execute(yuv)
rgb_small = nvc.Surface.Make(nvc.PixelFormat.RGB, target_w, target_h, gpu_id)
res_to_rgb.Execute(yuv_small, rgb_small, cc_ctx)
res_rawFrame = np.ndarray(shape=(target_h, target_w, 3), dtype=np.uint8)
res_nvDwn.DownloadSingleSurface(rgb_small, res_rawFrame)
RomanArzumanyan commented 1 month ago

Hi @geheiligt

I'll repro on my machine and will come back shortly.

RomanArzumanyan commented 1 month ago

@geheiligt

I was able to repro the issue on my machine, thanks for brining it up! The fix is pushed to PyClasses_refactoring branch which I'm currently working on. You may just use PyClasses_refactoring branch (BTW it has better test coverage) now or wait till the fix is merged to main.

RomanArzumanyan commented 1 month ago

Fix was merged to main branch, closing issue as fixed.