<div dir="auto"><div>Well,Hendrik is right. The decoder knows to detect that the YUV is NV12. I do get the decoded YUV correct now,but not for the first frame.For some reason the first frame has completely green color. I do tell the NVENC to set SPSPPS at the beginning, but still the first frame gets corrupted. Also, how do I flip the frame vertically on decoding ? <br><div class="gmail_extra"><br><div class="gmail_quote">On Jul 31, 2017 2:07 PM, "jing zhang" <<a href="mailto:zhangjing.lm@gmail.com">zhangjing.lm@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>You should use decoded AVFrame->format to check decoded yuv format.<br></div>Maybe H.264 bitstream encoded by NVENC is corrupted?<br></div><div class="elided-text"><div class="gmail_extra"><br><div class="gmail_quote">2017-07-31 16:27 GMT+08:00 Michael IV <span dir="ltr"><<a href="mailto:explomaster@gmail.com" target="_blank">explomaster@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So you basically say that the decoder 'knows' to detect interleaved UV in NV12 UV plane and decode it correctly to yuv420p without any hints from the application? <div>Then why my YUV frame is corrupted? How can I detect where is the problem? I also found this SO answer regarding h264 streaming from NVENC.</div><div><a href="https://stackoverflow.com/questions/33185966/how-to-stream-h-264-video-over-udp-using-the-nvidia-nvenc-hardware-encoder" target="_blank">https://stackoverflow.com/ques<wbr>tions/33185966/how-to-stream-<wbr>h-264-video-over-udp-using-<wbr>the-nvidia-nvenc-hardware-<wbr>encoder</a></div><div><br></div><div>And I currently don't set those params for encoder.Do I have to? <br><div> </div></div></div><div class="m_1142934329492838784HOEnZb"><div class="m_1142934329492838784h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 11:04 AM, Hendrik Leppkes <span dir="ltr"><<a href="mailto:h.leppkes@gmail.com" target="_blank">h.leppkes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_1142934329492838784m_1247962130900393039HOEnZb"><div class="m_1142934329492838784m_1247962130900393039h5">On Mon, Jul 31, 2017 at 10:00 AM, Michael IV <<a href="mailto:explomaster@gmail.com" target="_blank">explomaster@gmail.com</a>> wrote:<br>
> Hi! I am using NVENC encoder to create h264 stream.The YUV format is NV12.<br>
> Now, I need also to decode that stream back to YUV.I wrote a module for<br>
> that,based on<br>
> this example:<br>
><br>
> <a href="https://gist.github.com/roxlu/9329339" rel="noreferrer" target="_blank">https://gist.github.com/roxlu/<wbr>9329339</a><br>
><br>
> But, because my YUV format is not 420P, but NV12 I am trying to force it on<br>
> AVCodecContext when initializing it with this line:<br>
><br>
>         avcodec_register_all();<br>
>         mCodec = avcodec_find_decoder(AV_CODEC_<wbr>ID_H264);<br>
>         mCodecContext = avcodec_alloc_context3(mCodec)<wbr>;<br>
>         mCodecContext->pix_fmt = AVPixelFormat::AV_PIX_FMT_NV12<wbr>;<br>
><br>
><br>
> But when I am receiving the decoded AVFrame, I see that the AVFrame->format<br>
> property is<br>
> set to zero, which is enum for 420P. Also inspecting the planes and other<br>
> props of this struct I see that the decoder tried to decode it as 420P. (3<br>
> planes , 3 line sizes etc.) .And of course,when trying to play the output of<br>
> such a YUV frame , there is just a green screen.<br>
> I am trying to understand where is my error.Is there some data that decoder<br>
> misses from the h264 stream and it doesn't allow it to guess the pixel<br>
> format?Or maybe I need to set pixel format for the codec context in a some<br>
> different way?<br>
><br>
<br>
</div></div>You can't control the output pixel format of the H264 decoder. A video<br>
is not encoded as "NV12", its encoded as 4:2:0 YUV, NV12 is just one<br>
representation of this format.<br>
As such, our decoder will always decode 4:2:0 YUV content to yuv420p,<br>
not nv12. If you require NV12 in your application, you can convert<br>
from yuv420p to nv12 using swscale (a lossless conversion).<br>
<br>
- Hendrik<br>
______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
<br></blockquote></div><br></div>
</div><br>______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/<wbr>listinfo/libav-user</a><br>
<br></blockquote></div><br></div></div></div>