You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
Race conditions occur when using PySurfaceConverter in multiple processes. #506 suggests cloning the output surface, which reduces the problem a lot but does not solve it.
As the following code shows, we convert the same surface twice, but the results are not equal when using multiple processing.
#! /usr/bin/env python# coding: utf-8# pylint: disable=allimportmultiprocessingimportnumpyasnpimportPyNvCodecasnvcimportPytorchNvCodecaspnvcclassNvColorConverter:
"Color converter using PySurfaceConverter."def__init__(self, width, height, gpuid=0):
# yapf: disableself.width, self.height=width, heightself.context=nvc.ColorspaceConversionContext(
nvc.ColorSpace.BT_601, nvc.ColorRange.MPEG)
self.to_yuv=nvc.PySurfaceConverter(
width, height, nvc.PixelFormat.NV12,
nvc.PixelFormat.YUV420, gpuid)
self.to_rgb=nvc.PySurfaceConverter(
width, height, nvc.PixelFormat.YUV420,
nvc.PixelFormat.RGB, gpuid)
self.to_planar=nvc.PySurfaceConverter(
width, height, nvc.PixelFormat.RGB,
nvc.PixelFormat.RGB_PLANAR, gpuid)
self.downloader=nvc.PySurfaceDownloader(
width, height, nvc.PixelFormat.RGB_PLANAR, gpuid)
# yapf: enabledefconvert_color(self, surface):
surface=self.to_yuv.Execute(surface, self.context)
surface=self.to_rgb.Execute(surface, self.context)
surface=self.to_planar.Execute(surface, self.context)
# We clone the surface as suggested.surface=surface.Clone()
frame=np.ndarray(shape=(0, ), dtype=np.uint8)
self.downloader.DownloadSingleSurface(surface, frame)
returnframe# arg is a placeholderdeftest_decode_video(arg):
path, gpuid="./test.mp4", 0dec=nvc.PyNvDecoder(path, gpuid)
converter=NvColorConverter(dec.Width(), dec.Height(), gpuid)
foriinrange(dec.Numframes()):
surface=dec.DecodeSingleSurface()
ifsurface.Empty(): break# We use the same converter to convert the same surface twice,# When processes = 1, both arrays have the same value,# When processes > 1, two arrays are not equal.array1=converter.convert_color(surface)
array2=converter.convert_color(surface)
ifnotnp.array_equal(array1, array2):
print("frame not match")
defmain():
withmultiprocessing.Pool(processes=8) aspool:
pool.map(test_decode_video, [None] *16)
if__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
Apologies for big delay in response.
Please consider checking out https://github.com/RomanArzumanyan/VALI repository.
It's a VPF spin-off which is actively developed and maintained. It has compatible API and package naming.
Just clone your issue there. Thanks!
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Race conditions occur when using PySurfaceConverter in multiple processes. #506 suggests cloning the output surface, which reduces the problem a lot but does not solve it.
As the following code shows, we convert the same surface twice, but the results are not equal when using multiple processing.
The text was updated successfully, but these errors were encountered: