Stefan Schuermans commited on 2023-08-18 10:27:32
Showing 1 changed files, with 40 additions and 0 deletions.
| ... | ... |
@@ -8,6 +8,7 @@ |
| 8 | 8 |
#include <string.h> |
| 9 | 9 |
|
| 10 | 10 |
#include <BlinkenLib/BlinkenLib.h> |
| 11 |
+#include <BlinkenLib/BlinkenTools.h> |
|
| 11 | 12 |
|
| 12 | 13 |
/** |
| 13 | 14 |
* @brief generate test movie |
| ... | ... |
@@ -438,6 +439,35 @@ static stBlinkenMovie *scroll(stBlinkenMovie *pMovie, const char *str_direction, |
| 438 | 439 |
return pMovie; |
| 439 | 440 |
} |
| 440 | 441 |
|
| 442 |
+/** |
|
| 443 |
+ * @brief "play" video to stdout (including delays) |
|
| 444 |
+ * |
|
| 445 |
+ * @param[in] pMovie movie to "play" |
|
| 446 |
+ */ |
|
| 447 |
+void play_movie(stBlinkenMovie *pMovie) {
|
|
| 448 |
+ int frameCnt = BlinkenMovieGetFrameCnt(pMovie); |
|
| 449 |
+ const char *sep = ""; |
|
| 450 |
+ for (int frameNo = 0; frameNo < frameCnt; frameNo++) {
|
|
| 451 |
+ stBlinkenFrame *pFrame = BlinkenMovieGetFrame(pMovie, frameNo); |
|
| 452 |
+ if (pFrame == NULL) {
|
|
| 453 |
+ break; // something is wrong, stop "playing" |
|
| 454 |
+ } |
|
| 455 |
+ // print frame |
|
| 456 |
+ char *str = BlinkenFrameToString(pFrame); |
|
| 457 |
+ if (str == NULL) {
|
|
| 458 |
+ break; // something is wrong, stop "playing" |
|
| 459 |
+ } |
|
| 460 |
+ printf("%sframe %u\n%s", sep, frameNo, str);
|
|
| 461 |
+ sep = "\n\n\n"; |
|
| 462 |
+ fflush(stdout); |
|
| 463 |
+ // delay |
|
| 464 |
+ int duration = BlinkenFrameGetDuration(pFrame); |
|
| 465 |
+ if (duration > 0) {
|
|
| 466 |
+ BlinkenMSleep(duration); |
|
| 467 |
+ } |
|
| 468 |
+ } // for frameNo |
|
| 469 |
+} |
|
| 470 |
+ |
|
| 441 | 471 |
int main(int argCnt, char **args) {
|
| 442 | 472 |
stBlinkenMovie *pMovie; |
| 443 | 473 |
int i; |
| ... | ... |
@@ -482,6 +512,8 @@ int main(int argCnt, char **args) {
|
| 482 | 512 |
" output format, frame count and duration of movie\n" |
| 483 | 513 |
" -p\n" |
| 484 | 514 |
" print movie\n" |
| 515 |
+ " -P\n" |
|
| 516 |
+ " \"play\" movie to stdout (including delays)\n" |
|
| 485 | 517 |
" -r <width>x<height>-<channels>/<colors>\n" |
| 486 | 518 |
" resize movie\n" |
| 487 | 519 |
" -cr <src-x>,<src-y> <width>x<height>\n" |
| ... | ... |
@@ -636,6 +668,14 @@ int main(int argCnt, char **args) {
|
| 636 | 668 |
} |
| 637 | 669 |
} |
| 638 | 670 |
} |
| 671 |
+ // "play" movie to stdout |
|
| 672 |
+ else if (strcmp(args[i], "-P") == 0) {
|
|
| 673 |
+ if (pMovie == NULL) |
|
| 674 |
+ printf("no movie loaded to \"play\"\n");
|
|
| 675 |
+ else {
|
|
| 676 |
+ play_movie(pMovie); |
|
| 677 |
+ } |
|
| 678 |
+ } |
|
| 639 | 679 |
// resize movie |
| 640 | 680 |
else if (strcmp(args[i], "-r") == 0) {
|
| 641 | 681 |
if (i + 1 < argCnt) {
|
| 642 | 682 |