<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX ProcessorsのトピックRe: 1080p h264 encoding error</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931110#M139652</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, the issue is the alignment and offsets of the y and uv channels.&amp;nbsp; I switched the libimxvpuapi2 library for this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the encode-example.c code there is a call to&amp;nbsp;&lt;STRONG&gt;fb_metrics = &amp;amp;(ctx-&amp;gt;stream_info.frame_encoding_framebuffer_metrics);&amp;nbsp;&lt;/STRONG&gt;which returns the y offset, u offset, and v offset that the encoder wants.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My YUV buffer is straight from the IPU, so I assume all of the bytes in the frame are sequential, but the&amp;nbsp;&lt;STRONG&gt;fb_metrics&lt;/STRONG&gt; struct is telling me that the VPU needs padding between them...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, with a 1080p YUV420 8bit frame...&lt;/P&gt;&lt;P&gt;y_offset = 0; y_size = 1920x1080 =&amp;nbsp;2073600.&amp;nbsp; Since the u bytes start right after the y bytes&amp;nbsp;u_offset = 2073600&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;According to the fb_metrics struct, the encoder &lt;STRONG&gt;*wants*&lt;/STRONG&gt; the u offset to be 2088960.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The encoder-example in libimxvpuapi2 uses the y, u, and v offsets in fb_metrics to populate the input dma buffer, but it's just encoding a file, not a live camera feed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now...these conversions all work fine at 720p, and when I run the encode-example at 720p, the u_offset/v_offset are exactly as I would expect them to be...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Aug 2019 22:26:07 GMT</pubDate>
    <dc:creator>chrisroed</dc:creator>
    <dc:date>2019-08-02T22:26:07Z</dc:date>
    <item>
      <title>1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931107#M139649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've had a real tough time trying to push my camera up from 720p to 1080p...&amp;nbsp; See earlier (&lt;A _jive_internal="true" href="https://community.nxp.com/thread/508198"&gt;https://community.nxp.com/thread/508198&lt;/A&gt;).&amp;nbsp; Long story short, converting UYVY to YUV420 frames resulted in a green bar on the right side of the screen.&amp;nbsp; Using gstreamer is a guide, I discovered that the NV12 format resulted in a perfect output from the IPU.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now... on to the video encoding.&amp;nbsp; I've changed all my code to use NV12, and I'm trying to do h264 encoding.&amp;nbsp; I modified the encode-example in libimxvpuapi (&lt;A href="https://github.com/Freescale/libimxvpuapi/blob/v1/example/encode-example.c"&gt;https://github.com/Freescale/libimxvpuapi/blob/v1/example/encode-example.c&lt;/A&gt;) to encode 1080p video, and use the raw NV12 stream recorded previously.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made sure to set the vpu_open_param.chroma_interleave=1 so that the VPU knows it is an NV12 stream.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also modified the call to imx_vpu_calc_framebuffer_sizes so that chroma_interleave is 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 frame from input:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/73141i3E86048F3B19771F/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.jpg" alt="pastedImage_1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 frame from output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/73228i4E3298A750547FCA/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.jpg" alt="pastedImage_2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'll notice there's another green bar at the bottom of the screen this time, and something is messed up in the overlay text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As with my color conversion problems, I tried using gstreamer to convert the raw video file and gstreamer worked perfectly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$gst-launch-1.0 filesrc location="1080_overlay.nv12" ! rawvideoparse use-sink-caps=false width=1920 height=1080 format=nv12 ! vpuenc_h264 ! queue ! flvmux ! filesink&amp;nbsp; location="gst_overlay_1080.mp4"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jul 2019 22:00:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931107#M139649</guid>
      <dc:creator>chrisroed</dc:creator>
      <dc:date>2019-07-30T22:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: 1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931108#M139650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A _jive_internal="true" class="" data-content-finding="Community" data-userid="265267" data-username="chrisroed" href="https://community.nxp.com/people/chrisroed"&gt;Chris Roed&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please provide us below information:&lt;/P&gt;&lt;P&gt;1. Which NXP board/SoC are you using?&lt;/P&gt;&lt;P&gt;2. Which is the yocto/linux verion you are using?&lt;/P&gt;&lt;P&gt;3. What is your gstreamer version?&lt;/P&gt;&lt;P&gt;4. Steps to reproduce the issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Karan Gajjar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jul 2019 10:14:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931108#M139650</guid>
      <dc:creator>karangajjar</dc:creator>
      <dc:date>2019-07-31T10:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: 1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931109#M139651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using a custom board with an IMX6DL processor.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm on Yocto rocko with kernel 4.9.88&lt;/P&gt;&lt;P&gt;Gstreamer (which encodes correctly) is 1.12.2&lt;/P&gt;&lt;P&gt;libimxvpuapi from rocko is v0.10.3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To reproduce this issue...&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Capture Raw Frames and convert to NV12&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I captured raw camera frames at 1080p UYVY, then added an overlay and converted the color to NV12 format.&amp;nbsp; I can't share the project I used that added the overlay, but capturing raw camera frames can be done with gstreamer to the same effect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;$gst-launch-1.0 imxv4l2src num-buffers=30 !&amp;nbsp;&lt;SPAN&gt;video/x-raw,width=1920,height=1080,format=UYVY !&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;imxvideoconvert_ipu ! video/x-raw,width=1920,height=1080,format=NV12 ! filesink location="gst_1080p.NV12"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Modify example in libimxvpuapi&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;$git clone&amp;nbsp;git://github.com/Freescale/libimxvpuapi.git&amp;nbsp;&lt;/P&gt;&lt;P&gt;$git checkout v0.10.3&lt;/P&gt;&lt;P&gt;copy in the attached encode-example.c&amp;nbsp; (just changed resolution to 1920x1080, added chroma_interleave=1 to open_params and to imx_vpu_calc_framebuffer_sizes)&lt;/P&gt;&lt;P&gt;followed README.md instructions to compile code, installed on my iMX device&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Convert the video&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;$encode-example -i gst_1080p.NV12 -o convert_test.h264&lt;/P&gt;&lt;P&gt;I copied the convert_test.h264 back to my PC for viewing with ffplay&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What DOES work&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;*encode-example works great with 720p, just not the 1080p videos.&lt;/P&gt;&lt;P&gt;*gstreamer can convert 1080p videos&lt;/P&gt;&lt;P&gt;$gst-launch-1.0 filesrc location="1080_overlay.nv12" ! rawvideoparse use-sink-caps=false width=1920 height=1080 format=nv12 ! vpuenc_h264 ! queue ! flvmux ! filesink&amp;nbsp; location="gst_overlay_1080.mp4"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I took the liberty of sharing my 1080_overlay.nv12 and 720_overlay.nv12 files if you don't want to capture your own raw frames&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://drive.google.com/drive/folders/14Bcnl0mqenfxGPW4GcSXyOIrzfRqs2Je?usp=sharing" title="https://drive.google.com/drive/folders/14Bcnl0mqenfxGPW4GcSXyOIrzfRqs2Je?usp=sharing"&gt;ConvertTest - Google Drive&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jul 2019 16:08:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931109#M139651</guid>
      <dc:creator>chrisroed</dc:creator>
      <dc:date>2019-07-31T16:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: 1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931110#M139652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, the issue is the alignment and offsets of the y and uv channels.&amp;nbsp; I switched the libimxvpuapi2 library for this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the encode-example.c code there is a call to&amp;nbsp;&lt;STRONG&gt;fb_metrics = &amp;amp;(ctx-&amp;gt;stream_info.frame_encoding_framebuffer_metrics);&amp;nbsp;&lt;/STRONG&gt;which returns the y offset, u offset, and v offset that the encoder wants.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My YUV buffer is straight from the IPU, so I assume all of the bytes in the frame are sequential, but the&amp;nbsp;&lt;STRONG&gt;fb_metrics&lt;/STRONG&gt; struct is telling me that the VPU needs padding between them...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, with a 1080p YUV420 8bit frame...&lt;/P&gt;&lt;P&gt;y_offset = 0; y_size = 1920x1080 =&amp;nbsp;2073600.&amp;nbsp; Since the u bytes start right after the y bytes&amp;nbsp;u_offset = 2073600&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;According to the fb_metrics struct, the encoder &lt;STRONG&gt;*wants*&lt;/STRONG&gt; the u offset to be 2088960.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The encoder-example in libimxvpuapi2 uses the y, u, and v offsets in fb_metrics to populate the input dma buffer, but it's just encoding a file, not a live camera feed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now...these conversions all work fine at 720p, and when I run the encode-example at 720p, the u_offset/v_offset are exactly as I would expect them to be...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2019 22:26:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931110#M139652</guid>
      <dc:creator>chrisroed</dc:creator>
      <dc:date>2019-08-02T22:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: 1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931111#M139653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Turns out libimxvpuai calculates the offsets and strides based on *aligned* frame width/height, not actual frame width/height.&amp;nbsp; After some searching, I found out according to the alignments, 720p aligns perfectly but 1080p aligns to 1920x1088.&amp;nbsp; This is the root of the problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Aug 2019 00:49:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931111#M139653</guid>
      <dc:creator>chrisroed</dc:creator>
      <dc:date>2019-08-03T00:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: 1080p h264 encoding error</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931112#M139654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured out how to get this working!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I stole a few macros from libimxvpuapi2...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define VPU_FRAME_LENGTH_ALIGNMENT (16)&lt;BR /&gt;#define IMX_VPU_API_ALIGN_VAL_TO(LENGTH, ALIGN_SIZE) ( ((uintptr_t)(((uint8_t*)(LENGTH)) + (ALIGN_SIZE) - 1) / (ALIGN_SIZE)) * (ALIGN_SIZE) )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then when I set up my ipu output task...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ipu_task.output.width = IMX_VPU_API_ALIGN_VAL_TO(out_format-&amp;gt;fmt.pix.width, VPU_FRAME_LENGTH_ALIGNMENT);&lt;BR /&gt; ipu_task.output.height = IMX_VPU_API_ALIGN_VAL_TO(out_format-&amp;gt;fmt.pix.height, VPU_FRAME_LENGTH_ALIGNMENT);&lt;BR /&gt; ipu_task.output.crop.pos.x = 0;&lt;BR /&gt; ipu_task.output.crop.pos.y = 0;&lt;BR /&gt; ipu_task.output.crop.w = out_format-&amp;gt;fmt.pix.width;&lt;BR /&gt; ipu_task.output.crop.h = out_format-&amp;gt;fmt.pix.height;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'll lose a few pixels on the edge, but this aligns the IPU buffers in such a way that it's compatible with the VPU.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you allocate your IPU output buffer, you need to make sure you compute the size based on the *actual* output width/height instead of the cropped width/height.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Aug 2019 17:34:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/1080p-h264-encoding-error/m-p/931112#M139654</guid>
      <dc:creator>chrisroed</dc:creator>
      <dc:date>2019-08-03T17:34:17Z</dc:date>
    </item>
  </channel>
</rss>

