{"id":909,"date":"2022-11-28T16:23:59","date_gmt":"2022-11-28T08:23:59","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=909"},"modified":"2025-10-09T13:55:34","modified_gmt":"2025-10-09T05:55:34","slug":"linux-media-02","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2022\/11\/28\/linux-media-02\/","title":{"rendered":"Linux Media 02 Convert YUV to RGB"},"content":{"rendered":"<p>&emsp;&emsp;Here is an example code that convert YUV format to RGB format via FFmpeg.<\/p>\n<pre><code class=\"language-c\">int VIDEOWRP_YUYV422_to_RGB24(int imgWidth, int imgHeight, \n                            uint8_t* inputData, uint8_t* outputData, \n                            int inputLength)\n{\n    struct SwsContext* ctx = sws_getContext(imgWidth, imgHeight, AV_PIX_FMT_YUYV422,\n                                            imgWidth, imgHeight, AV_PIX_FMT_RGB24,\n                                            SWS_BICUBIC, NULL, NULL, NULL);\n\n    struct AVFrame* input_pFrame = av_frame_alloc();\n    struct AVFrame* output_pFrame = av_frame_alloc();\n\n    av_image_fill_arrays(input_pFrame-&gt;data, input_pFrame-&gt;linesize, \n                        inputData, AV_PIX_FMT_YUYV422, imgWidth, imgHeight, 1);\n    av_image_fill_arrays(output_pFrame-&gt;data, output_pFrame-&gt;linesize, \n                        outputData, AV_PIX_FMT_RGB24, imgWidth, imgHeight, 1);\n\n    sws_scale(ctx, \n            (const uint8_t**)input_pFrame-&gt;data, \n            input_pFrame-&gt;linesize, 0, imgHeight, \n            output_pFrame-&gt;data, output_pFrame-&gt;linesize);\n\n#if 0\n    FILE *fl;\n    fl = fopen(&quot;img.rgb&quot;, &quot;w&quot;);\n    if (NULL == fl)\n    {\n        fprintf(stderr, &quot;open write file failed.&quot;);\n    }\n    fwrite(outputData, inputLength * 1.5, 1, fl);\n    fclose(fl);\n#endif\n\n    \/\/ end\n    if (input_pFrame) av_free(input_pFrame);\n    if (output_pFrame) av_free(output_pFrame);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;Here is an example code that convert YUV format to RG &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/909"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=909"}],"version-history":[{"count":3,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/909\/revisions"}],"predecessor-version":[{"id":912,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/909\/revisions\/912"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}