批处理文件中的颜色代码遇到麻烦

发布于 2025-02-10 09:00:05 字数 1238 浏览 0 评论 0原文

我正在尝试将FFMPEG的进度进行颜色,但是由于某种原因,当我终止或全屏时,这种怪兽会发生: 问题

@echo off
@echo off
title Stream Recorder
cls
:start
set message=Stream Recorder
echo %message%
echo(
echo [32m1. Chrome [0m
echo [34m2. Edge [0m
echo [33m3. Firefox [0m
echo [31m4. Opera [0m
echo [1;31m5. Vivaldi [0m
:choice
set choice=
set /p "choice=* Pick your browser (between 1-5): "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto chrome
echo "%choice%" is not valid, try again.
ECHO.
goto choice

:chrome
:url
echo(
set /p "address=* M3U8 Url: "
For /F %%G In ('%__AppDir__%curl.exe -s -o NUL "%address%" -w "%%{http_code}\n"') Do Set "response=%%G"
echo %response%
IF %response% == 200 (
    ECHO [32mURL check was successful.[m &goto :username
) ELSE (
    ECHO [31mURL is not valid, try again.[m &goto :url
)
:username
set /p "filename=* Streamer Name: "
echo(
set message=* Recording:
echo [0m%message%[42;1m
ffmpeg -v warning -hide_banner -stats -user_agent "" -i "%address%" -c copy "%~dp0/%filename%_%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%time:~-11,2%-%time:~-8,2%-%time:~-5,2%.mp4"
pause

另外,如果我的代码需要进行一些清理,将会有所帮助。

I'm trying to only have ffmpeg progress to be colored, but for some reason when I terminate or go full-screen this monstrosity occurs:
Issue

@echo off
@echo off
title Stream Recorder
cls
:start
set message=Stream Recorder
echo %message%
echo(
echo [32m1. Chrome [0m
echo [34m2. Edge [0m
echo [33m3. Firefox [0m
echo [31m4. Opera [0m
echo [1;31m5. Vivaldi [0m
:choice
set choice=
set /p "choice=* Pick your browser (between 1-5): "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto chrome
echo "%choice%" is not valid, try again.
ECHO.
goto choice

:chrome
:url
echo(
set /p "address=* M3U8 Url: "
For /F %%G In ('%__AppDir__%curl.exe -s -o NUL "%address%" -w "%%{http_code}\n"') Do Set "response=%%G"
echo %response%
IF %response% == 200 (
    ECHO [32mURL check was successful.[m &goto :username
) ELSE (
    ECHO [31mURL is not valid, try again.[m &goto :url
)
:username
set /p "filename=* Streamer Name: "
echo(
set message=* Recording:
echo [0m%message%[42;1m
ffmpeg -v warning -hide_banner -stats -user_agent "" -i "%address%" -c copy "%~dp0/%filename%_%DATE:~7,2%-%DATE:~4,2%-%DATE:~-4%_%time:~-11,2%-%time:~-8,2%-%time:~-5,2%.mp4"
pause

Also, would be helpful if my code needs some cleaning up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千柳 2025-02-17 09:00:05

最后一个回声是问题:

echo 逃脱 [0m%消息% easse < /kbd> [42; 1M

第一个 逃脱 块转弯 off color and Bold,第二个将颜色和粗体 上的 上。

要解决问题,您需要(至少)

echo 逃脱 [0M

pause>暂停。但这可能还不够,因为ffmpeg在不修改颜色的情况下(大概是)打印到终端。如果碰巧清除了当前行或显示显示末端,大多数终端(支持 背面颜色擦除 )将用当前的颜色填充清除的区域。

也许您不希望ffmpeg有这个机会。

That last echo is the problem:

echo Escape[0m%message%Escape[42;1m

The first Escape chunk turns off color and bold, while the second turns color and bold on.

To fix the problem, you need (at least)

echo Escape[0m

before the pause. But that may not be enough, because ffmpeg is printing to the terminal (presumably) without modifying colors. If it happens to clear the current line or to the end of the display, most terminals (supporting back color erase) will fill the cleared area with the current color.

Perhaps you don't want ffmpeg to have that opportunity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文