Stefan Schuermans commited on 2014-05-10 16:16:11
Showing 3 changed files, with 60 additions and 2 deletions.
... | ... |
@@ -263,6 +263,8 @@ int main(int argCnt, char **args) |
263 | 263 |
" reverse movie\n" |
264 | 264 |
" -ct <begin> <end>\n" |
265 | 265 |
" cut movie to time span from begin (in ms) till end (in ms)\n" |
266 |
+ " -dur <duration>\n" |
|
267 |
+ " adapt duration (in ms) of movie\n" |
|
266 | 268 |
" -d <first> <count>\n" |
267 | 269 |
" delete frames\n" |
268 | 270 |
" -t <width>x<height>-<channels>/<colors> <test_mode> <duration>\n" |
... | ... |
@@ -523,6 +525,22 @@ int main(int argCnt, char **args) |
523 | 525 |
} else |
524 | 526 |
printf("missing begin time for \"-ct\"\n"); |
525 | 527 |
} |
528 |
+ // adapt duration of movie |
|
529 |
+ else if (strcmp(args[i], "-dur") == 0) { |
|
530 |
+ if (i + 1 < argCnt) { |
|
531 |
+ unsigned int duration; |
|
532 |
+ i++; |
|
533 |
+ if (sscanf(args[i], "%u", &duration) != 1) |
|
534 |
+ printf("invalid duration \"%s\"\n", args[i]); |
|
535 |
+ else if (pMovie == NULL) |
|
536 |
+ printf("no movie loaded to adapt duration of\n"); |
|
537 |
+ else { |
|
538 |
+ BlinkenMovieAdaptDuration(pMovie, duration); |
|
539 |
+ printf("duration adapted to %u ms\n", duration); |
|
540 |
+ } |
|
541 |
+ } else |
|
542 |
+ printf("missing new duration for movie for \"-dur\"\n"); |
|
543 |
+ } |
|
526 | 544 |
// delete frames |
527 | 545 |
else if (strcmp(args[i], "-d") == 0) { |
528 | 546 |
if (i + 2 < argCnt) { |
... | ... |
@@ -540,8 +540,8 @@ void BlinkenMovieCutTime(stBlinkenMovie *pMovie, |
540 | 540 |
int frameCnt; |
541 | 541 |
stBlinkenFrame **ppNewFrames; |
542 | 542 |
|
543 |
- // do nothing if empty movie |
|
544 |
- if (pMovie->frameCnt < 1) |
|
543 |
+ // do nothing if no movie or empty movie |
|
544 |
+ if (pMovie == NULL || pMovie->frameCnt < 1) |
|
545 | 545 |
return; |
546 | 546 |
|
547 | 547 |
// get movie duration |
... | ... |
@@ -626,6 +626,44 @@ void BlinkenMovieCutTime(stBlinkenMovie *pMovie, |
626 | 626 |
} |
627 | 627 |
} |
628 | 628 |
|
629 |
+void BlinkenMovieAdaptDuration(stBlinkenMovie *pMovie, |
|
630 |
+ int duration /* in ms */) |
|
631 |
+{ |
|
632 |
+ int old_duration, old_curtime, curtime; |
|
633 |
+ int i, old_dur, dur, old_end, end; |
|
634 |
+ |
|
635 |
+ // do nothing if no movie, empty movie or invalid duration |
|
636 |
+ if (pMovie == NULL || pMovie->frameCnt < 1 || duration <= 0) |
|
637 |
+ return; |
|
638 |
+ |
|
639 |
+ // get movie duration |
|
640 |
+ old_duration = 0; |
|
641 |
+ for (i = 0; i < pMovie->frameCnt; i++) |
|
642 |
+ old_duration += BlinkenFrameGetDuration(pMovie->ppFrames[i]); |
|
643 |
+ |
|
644 |
+ // adapt duration of frames |
|
645 |
+ old_curtime = 0; |
|
646 |
+ curtime = 0; |
|
647 |
+ for (i = 0; i < pMovie->frameCnt; i++) { |
|
648 |
+ // get old end time of current frame |
|
649 |
+ old_dur = BlinkenFrameGetDuration(pMovie->ppFrames[i]); |
|
650 |
+ old_end = old_curtime + old_dur; |
|
651 |
+ // compute new end time and new duration |
|
652 |
+ end = (int)((double)old_end / (double)old_duration * (double)duration |
|
653 |
+ + 0.5); |
|
654 |
+ dur = end - curtime; |
|
655 |
+ if (dur < BlinkenDurationMin) |
|
656 |
+ dur = BlinkenDurationMin; |
|
657 |
+ if (dur > BlinkenDurationMax) |
|
658 |
+ dur = BlinkenDurationMax; |
|
659 |
+ // update frame duration |
|
660 |
+ BlinkenFrameSetDuration(pMovie->ppFrames[i], dur); |
|
661 |
+ // advance time |
|
662 |
+ old_curtime += old_dur; |
|
663 |
+ curtime += dur; |
|
664 |
+ } |
|
665 |
+} |
|
666 |
+ |
|
629 | 667 |
void BlinkenMovieResize(stBlinkenMovie *pMovie, int height, int width, |
630 | 668 |
int channels, int maxval) |
631 | 669 |
{ |
... | ... |
@@ -62,6 +62,8 @@ int BlinkenMovieConcat(stBlinkenMovie *pMovie, |
62 | 62 |
void BlinkenMovieReverse(stBlinkenMovie *pMovie); |
63 | 63 |
void BlinkenMovieCutTime(stBlinkenMovie *pMovie, |
64 | 64 |
int begin /* in ms */, int end /* in ms */); |
65 |
+void BlinkenMovieAdaptDuration(stBlinkenMovie *pMovie, |
|
66 |
+ int duration /* in ms */); |
|
65 | 67 |
|
66 | 68 |
void BlinkenMovieResize(stBlinkenMovie *pMovie, int height, int width, |
67 | 69 |
int channels, int maxval); |
68 | 70 |