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.
as far as i know, yuv420p means Y colors are going to be stored in the first plane, and U colors in the second plane, and V colors in
the third plane.
so in a contiguous memory space, it's going to look like the following, assume we have a 1920x1080 image, then the first 1920x1080
space is going to hold Y plane, and the next 960x540 space contains U colors, and followed by V colors stored in the last 960X540.
and actually 960x540 == 1920x270
Y Y Y Y Y Y
Y Y Y Y Y Y
Y Y Y Y Y Y plane 1
Y Y Y Y Y Y
U U U U U U plane2
V V V V V V plane3
--------------- -------------- -----------
y:1920x1080 u:1920x270 v:1920x270
so to construct a yuv420P surface, just copy Y plane , U plane, and V plane seperately. the key is to calculate the pointer
addresses for Y, U, and V planes.
we can obtain those three pointers by splitting the tensor like this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
somthing weird happended when i tried to copy an image from device to device.
first, i decoded a yuv420 image using pyav, and saved it into a npy file
and then loaded that npy file to gpu using torch
as far as i know, yuv420p means Y colors are going to be stored in the first plane, and U colors in the second plane, and V colors in
the third plane.
so in a contiguous memory space, it's going to look like the following, assume we have a 1920x1080 image, then the first 1920x1080
space is going to hold Y plane, and the next 960x540 space contains U colors, and followed by V colors stored in the last 960X540.
and actually 960x540 == 1920x270
so to construct a yuv420P surface, just copy Y plane , U plane, and V plane seperately. the key is to calculate the pointer
addresses for Y, U, and V planes.
we can obtain those three pointers by splitting the tensor like this
the statement
u_tensor, v_tensor = uv_tensor.split(h//4, 0)
is splitting the tensor like thisand to copy the image, we just exposed cudaMemcpy2DAsync to Python interface.
and the copied those three pointers setting pitches
and finally, combined all of them into one function
and it worked perfectly.
BUT, the problem is that when i changed the statement
u_tensor, v_tensor = uv_tensor.split(h//4, 0)
tou_tensor, v_tensor = uv_tensor.split(w//2, 1)
, it worked as well, but it shouldn't.the statement
u_tensor, v_tensor = uv_tensor.split(w//2, 1)
was splitting the u and v plane at the middle into two parts,.it was assuming that the left of size 960x540 contains U colors, and the right part of size 960x540 contains V colors
and according to the Nvidia's document, cudaMemcpy2DAsync is going to copy a block of contiguous memory space as
cuMemcpyHtoDAsync does except taking pitch into account.
so what did i miss?
this is the pyav_yuv420p.pt, because github doesn't support attaching .pt files, so please download and rename.
pyav_yuv420p.txt
Beta Was this translation helpful? Give feedback.
All reactions