Search code examples
videoffmpegsdlrgb

How to fix the problem of wrong colors shown in the local video window of MicroSIP?


I'm developing a project which is a customization based on MicroSIP in Windows. The local video window performs the video stream from Screen Capture Recorder, which is as a virtual camera and captures the screen. And the problem is the colors of the picture of the local video window are not correct. The picture I uploaded is the example of the problem, it seems like that the red and the blue are exchanged.

I'd tried to upgrade the FFmpeg to 5.0.1 and the SDL to 2.0.22, both are probably the latest versions, but it doesn't fix the color problem.

This problem also occurs when using the latest official version of MicroSIP(3.21.2).
source code of MicroSIP
source code of PJSIP (the low-level module which provides interfaces for video, audio, etc. Maybe it's the origin of the color problem)
And while using some of the other software which can display pictures of the virtual camera, they can show pictures fine with the correct colors, e.g. MyCam.

How to fix this problem? Or which parts can I do some research on about this problem? Any help would be appreciated.


Solution

  • Okay, I've resolved this problem. In the dshow_dev.c of pjsip project, there is a static variable.

    static dshow_fmt_info dshow_fmts[] =
    {
        {PJMEDIA_FORMAT_YUY2, &MEDIASUBTYPE_YUY2, PJ_FALSE} ,
        {PJMEDIA_FORMAT_RGB24, &MEDIASUBTYPE_RGB24, PJ_FALSE} ,
        {PJMEDIA_FORMAT_RGB32, &MEDIASUBTYPE_RGB32, PJ_FALSE} ,
        {PJMEDIA_FORMAT_IYUV, &MEDIASUBTYPE_IYUV, PJ_FALSE} ,
        {PJMEDIA_FORMAT_I420, &WMMEDIASUBTYPE_I420, PJ_FALSE}
    };
    

    In function enum_dev_cap(), first, it enumerates the pins and tries to match a UUID in dshow_fmts, and then, in function pjmedia_format_init_video(), it tries to match the format id in dshow_fmts. In the second step, it can't find the correct format id(BGRA), so the red and blue color swapped problem occurred.

    So the solution is, to add {PJMEDIA_FORMAT_BGRA, &MEDIASUBTYPE_RGB32, PJ_FALSE}, to the dshow_fmts array. Then the colors are now correct.