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 f300679..92bc903 100755 Binary files a/tvp and b/tvp differ