BufferHow to get STDIN line color with JAVA using BufferedReader

114 views Asked by At

Im run FFplay process in my JAVA application and read his logs with BufferedReader. I want to parse the logs to determine errors. So I want to read the color for each line. red for errors.. bufferedReader.readline() return the content, no any color code.

Please advise.

1

There are 1 answers

2
RealSkeptic On BEST ANSWER

Ffmpeg and its associated tools emits color codes only when it detects that stderr goes to a terminal that supports color codes. Although this can be overridden by an environment variable, parsing arcane escape codes is not recommended.

Instead, according to the FFMpeg documentation, you may prefix the log level as a string to the output, by using a flag in the -loglevel parameter. There are several documented flags, and the applicable one is level.

So if you had a log level set with -loglevel info, you can change this to -loglevel level+info. If you didn't have a log level at all, you can use -loglevel +level.

Now the output log messages will be prefixed with [error] when the level is error. This works in all ffmpeg tools, including ffplay.