[FFmpeg-devel] [PATCH] avutil/log: in colored_fputs, convert string from utf8 to CP_ACP charset on Windows

周泽华 zhouzehua at gmail.com
Fri Feb 21 09:46:03 CET 2014


2014-02-21 0:45 GMT+08:00 Derek Buitenhuis <derek.buitenhuis at gmail.com>:
> On 2/20/2014 4:33 PM, Anshul wrote:
>> I do write callback for avlog in such conditions, but it would be good if someone make an option that only use ascii, it would be better if there would be function like avset_log_ch_fmt().
>> It would also benifit when we redirect log in text file. In text file all the character that are used for color look like garbage.
>
> Currently, as it stands, colors are not written when redirected to a text
> file in any sane environment.
>
> I am with Jan on this one. It is a *bad* idea. We shouldn't hack around cmd.exe's
> legacy crap (that will never change btw, according to MS) by mucking with the encoding
> like this. It violates the principle of least astonishment[1] -- everyone expects output
> to be unicode, including our own FATE scripts. Also, this would probably break output
> in the MSYS terminal, which handles unicode fine.
>
> More over, even for what this patch wants to do, it does it wrong. The correct way can
> would be to use _setmode() with _O_U8TEXT, as seen here:
>
> https://web.archive.org/web/20130215014133/http://blogs.msdn.com/b/michkap/archive/2008/03/18/8306597.aspx
>
> (MS move his blog so I can't find the current page.)

The str parameter of colored_fputs() is not necessarily in utf8. If the str
parameter is not in utf8, then it is in local code page with high probability.
For these strings, MultiByteToWideChar() will fail with high probability and
send the original string (the correct one) to console. With _setmode(), the
strings in local code page are forcedly sent to console, resulting a messy
output.

>
> - Derek
>
> [1] http://en.wikipedia.org/wiki/Principle_of_least_astonishment
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


More information about the ffmpeg-devel mailing list