<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Le mar. 26 nov. 2024 à 19:26, Mathieu Prevot <<a href="mailto:mathieu.prevot@gmail.com">mathieu.prevot@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 22 nov. 2024 à 13:55, Mathieu Prevot <<a href="mailto:mathieu.prevot@gmail.com" target="_blank">mathieu.prevot@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mer. 20 nov. 2024 à 18:03, Mathieu Prevot <<a href="mailto:mathieu.prevot@gmail.com" target="_blank">mathieu.prevot@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 19 nov. 2024 à 00:39, Mathieu Prevot <<a href="mailto:mathieu.prevot@gmail.com" target="_blank">mathieu.prevot@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 17 nov. 2024 à 20:57, Mathieu Prevot <<a href="mailto:mathieu.prevot@gmail.com" target="_blank">mathieu.prevot@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div>Hello,<br><br></div>I am using code, based on <a href="https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c" target="_blank">https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/hw_decode.c</a>, but I am not transferring the decoded data to the host, I keep it on the device for later use with cuda code (my goal will be to use RGB 8-12 bits per channel data).<br></div><br></div><div>I could not find a way to get the data format ((AVPixelFormat)frame->format translates to: "HW acceleration through CUDA. data[i] contain CUdeviceptr pointers exactly as for system memory frames.")<br><br></div><div>I understand that I have two arrays: frame->data[0] and frame->data[1].<br><br></div><div>I would like to translate the data into a cuda native structure like:<br><br>                   cudaPitchedPtr CUdeviceptr{};<br>                 CUdeviceptr.ptr = frame->data[0];<br>                  CUdeviceptr.ysize = frame->height;<br>                 CUdeviceptr.xsize = frame->width;<br><br></div><div>Which is probably wrong, since
width==1920 
height==1080 and should have colors or YUV data.<br><br></div><div>How to get to know the data format (RGB, BGR, YUV, 8/10/12bits per channel etc) and the size of the array ?<br></div><div>If it is not RGB8 (or 10-12), can I get that through some ffmpeg implementation, maybe with an nvdec based function ?<br></div><div>What is the correct cuda-native data ? 
cudaPitchedPtr or something else ?<br>
frame->data[0] is uint8_t, but the array is probably something else in the general case; so what is it (as redundancy or extension of "what is the data format") ?<br></div></div></blockquote><div><br></div><div>It seems that  
frame->data[0] is the Y component of YUV, if not, one of RGB channels, but 
I could not figure out what frame->data[1] is.<br></div><div>Can someone confirm ?<br></div></div></div></blockquote><div><br></div><div>I got no answer from libav-user@, maybe is it a question for ffmpeg-devel@ (not subscribed, please cc) ?</div></div></div></blockquote><div><br></div><div>There seems to be no other data except that of `frame->data[0]`.</div><div></div><div><br></div><div>I verified, there is nothing beyond 
 `frame->data[0]

+ frame->linesize[0]*frame->height`.</div><div><br></div><div>
frame->data[1] has another address but there is no data.

</div><div><br>
</div><div>frame->buf[0]->data and 
frame->extended_data 

both point to the same address as


frame->data[0].</div><div></div><div></div><div><br></div><div>no side_data or extended_buf,</div><div><br></div><div>opaque_ref is NULL</div><div><br></div><div>frame->ch_layout->order is AV_CHANNEL_ORDER_UNSPEC</div><div><br></div><div>In the end, it comes down to this questions:</div><div><br></div><div>1. where are UV data of YUV when decoded by cuda ? Y is at frame->data[0].</div><div>2. 
frame->linesize[1] is set too, what is this for ?</div></div></div></blockquote></div></div></blockquote><div><br></div><div>For those interested.<br><br>
<button class="gmail-js-accept-answer-btn gmail-flex--item gmail-s-btn gmail-s-btn__unset gmail-c-pointer gmail-fc-green-400" aria-label="Accept answer" aria-describedby="--stacks-s-tooltip-ibrylk6s">
            </button>

    
    <a class="gmail-js-post-issue gmail-flex--item gmail-s-btn gmail-s-btn__unset gmail-c-pointer gmail-py6 gmail-mx-auto" href="https://stackoverflow.com/posts/79242422/timeline" aria-label="Timeline" aria-describedby="--stacks-s-tooltip-vvjcofjv"></a><div class="gmail-votecell gmail-post-layout--left"><div class="gmail-js-voting-container gmail-d-flex gmail-jc-center gmail-fd-column gmail-ai-center gmail-gs4 gmail-fc-black-300">

</div>

        </div>

        

<div class="gmail-answercell gmail-post-layout--right">
    
    <div class="gmail-s-prose gmail-js-post-body">
<p>For a given frame of a video that can be decoded with nvdec in ffmpeg,</p>
<p><code>(AVPixelFormat)frame->format</code> will give:</p>
<blockquote>
<p>AV_PIX_FMT_CUDA: HW acceleration through CUDA. data[i] contain
CUdeviceptr pointers exactly as for system memory frames.</p>
</blockquote>
<p>which is not helpful, but <code>((AVHWFramesContext*)frame->hw_frames_ctx->data)->sw_format</code> will give:</p>
<blockquote>
<p>AV_PIX_FMT_NV12: planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane
for the UV components, which are interleaved (first byte U and the
following byte V)</p>
</blockquote>
<p>which is everything that is needed.<br><br>
Both are pitched arrays, which can be used directly as <code>cudaPitchedPtr.ptr</code>.
Their pitch is <code>frame->linesize[0]</code> and <code>frame->linesize[1]</code>.

</p></div></div>

</div><div>M<br></div><div> </div></div></div>