From ebbeb97bed0d6789d203ad9d1dbe0bad8284f0ec Mon Sep 17 00:00:00 2001 From: TheRealOrange Date: Tue, 22 Feb 2022 16:13:17 +0800 Subject: [PATCH] print background colour black, edited readme slightly --- README.md | 7 ++++--- src/main.cpp | 6 +++--- tvp | Bin 38792 -> 38792 bytes 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 348d564..8948e46 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,19 @@ Mileage may vary depending on how fast your terminal is. In my testing, I've fou .\tvp filename [threshold] ``` -The threshold has to be an integer from 0 to 255, and defaults to 10. The threshold affects how much the colour of a certain pixel has to change before it will be redrawn. A lower threshold results in more redraws in most cases, and leads to choppy video. +The threshold has to be an integer from 0 to 255, and defaults to 10. The threshold affects how much the colour of a certain pixel has to change before it will be redrawn. A lower threshold results in more redraws in most cases, and leads to choppy video. Unfortunately I can't be bothered to rewrite this to decode video using FFmpeg so you'll have to build it with OpenCV. Built on Manjaro with this command: ```sh -g++ src/main.cpp -O3 -o ./bin/tvp `pkg-config --cflags --libs opencv4` +g++ src/main.cpp -O3 -o tvp `pkg-config --cflags --libs opencv4` ``` Below is a preview of how it looks: ![video playing in terminal](./imgs/video.gif) -## how it works +## How it works This is not a new concept. But most terminal video players I have seen use two pixels per character. The unicode character ▄ (U+2584 lower half block) as the bottom half of the pixel, which can be coloured using the ANSI code for font colour, and the background colour, as the other pixel. @@ -47,3 +47,4 @@ Other optimisations include - only changing pixels whose colour have changed a certain value - only inputting the ANSI code for cursor move when the next pixel isnt contiguous - only inputting the ANSI code for background colour change when the background colour differs significantly (set as a compile option) + diff --git a/src/main.cpp b/src/main.cpp index cf9a1d4..74e6339 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,8 +168,8 @@ int main(int argc, char *argv[]) { start = std::chrono::high_resolution_clock::now(); videostart = std::chrono::high_resolution_clock::now(); } - printf("\u001b[0;0H"); - for (int i = 0; i < w * (msg_y + 1); i++) printf(" "); + printf("\u001b[0;0H\u001b[48;2;0;0;0m"); + for (int i = 0; i < curr_w * curr_h; i++) printf(" "); } stop = std::chrono::high_resolution_clock::now(); @@ -197,7 +197,7 @@ int main(int argc, char *argv[]) { std::this_thread::sleep_until(std::chrono::microseconds(curr_frame * period - frame10_time/frametimes.size()) + videostart); } - printf("\u001b[0m\u001b[%d;%dH fps: %5.2f | avg_fps: %5.2f | print: %6.2fms | dropped: %5d | curr_frame: %5d ", + printf("\u001b[%d;%dH\u001b[48;2;0;0;0;38;2;255;255;255m fps: %5.2f | avg_fps: %5.2f | print: %6.2fms | dropped: %5d | curr_frame: %5d ", msg_y, 0, (double) frametimes.size() * 1000000.0 / frame10_time, avg_fps, (double) printing_time / 1000.0, dropped, curr_frame); prevpixelbg[0] = 1000; diff --git a/tvp b/tvp index f300679b34f0fd52530101534164940cb2ac60e9..92bc903b10eb426c8d84fbfbc2ec8f908c4c9b4d 100755 GIT binary patch delta 5689 zcmZ8l4_s7L+MY9T0yk$bZcKrQV2O$#$Ukj_A%>lii-P%?q}KLlQ_+fcwb07_twX^S zr|XpM(Y~@YcYnLz*KfBzD}>xOYDQflwE`=&)IxK0$kvb)PF>=m?o7ozvoqPF0oM;a}Hlv?2t>G*JJ?Q>Su1tSubdAeq+rfZD&h(pR zpBBfbEmG+k`F(n_ebfw@JlX3XhpL=Vq!uLxKeNDQ)3))`FoDq8)SScbrBeGcmHgC7 z?uDt}#axH{$0JW8p}+glz%5_>>BZftx@glg+?3Y^-=|Di7lV4(yh+b+>?B~|j4nF# z@L-IdJ}CH23vKe`4|j)x*Ou24@&xpEj90m0iR;Z&Y!+;D@Qq z;2|>gk?20{&TyYLinmkj+M_kpjUQ~wH!WfR{sM2uXl}?~& z*A1tSy!4Qloy9dqmDgWj!m*O7>N`w5qhOAFEhF7uM1X6j*5JYk^!lCX-Wj=-u5}hN zh9e(Gui;385qq?4XT9kk2Ku$9-J{hN^rKQ=%m~!>t zTb98;M21+=>n}3&&_Dbgo%na z-dAvo57=V$VpDX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