History

avfilter/avf_showcwt: add frame slide mode

Paul B Mahol committed 3 years ago

Commit 7d206351 parent bcb5ef62 files · +99 −15Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/avf_showcwt.c+98−15
@@ -54,6 +54,7 @@ enum DirectionMode { · 53 unmodified lines
5454 enum SlideMode {
5555 SLIDE_REPLACE,
5656 SLIDE_SCROLL,
57+ SLIDE_FRAME,
5758 NB_SLIDE
5859 };
5960
@@ -94,6 +95,7 @@ typedef struct ShowCWTContext { · 34 unmodified lines
9495 int pps;
9596 int eof;
9697 int slide;
98+ int new_frame;
9799 int direction;
98100 int hop_size;
99101 int hop_index;
@@ -138,6 +140,7 @@ static const AVOption showcwt_options[] = { · 38 unmodified lines
138140 { "slide", "set slide mode", OFFSET(slide), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SLIDE-1, FLAGS, "slide" },
139141 { "replace", "replace", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_REPLACE},0, 0, FLAGS, "slide" },
140142 { "scroll", "scroll", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_SCROLL}, 0, 0, FLAGS, "slide" },
143+ { "frame", "frame", 0, AV_OPT_TYPE_CONST,{.i64=SLIDE_FRAME}, 0, 0, FLAGS, "slide" },
141144 { "direction", "set direction mode", OFFSET(direction), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_DIRECTION-1, FLAGS, "direction" },
142145 { "lr", "left to right", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_LR}, 0, 0, FLAGS, "direction" },
143146 { "rl", "right to left", 0, AV_OPT_TYPE_CONST,{.i64=DIRECTION_RL}, 0, 0, FLAGS, "direction" },
@@ -330,6 +333,7 @@ static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) · 186 unmodified lines
330333
331334 switch (s->slide) {
332335 case SLIDE_REPLACE:
336+ case SLIDE_FRAME:
333337 /* nothing to do here */
334338 break;
335339 case SLIDE_SCROLL:
@@ -515,6 +519,7 @@ static int config_output(AVFilterLink *outlink) · 179 unmodified lines
515519 break;
516520 }
517521
522+ s->new_frame = 1;
518523 s->nb_threads = FFMIN(s->frequency_band_count, ff_filter_get_nb_threads(ctx));
519524 s->nb_channels = inlink->ch_layout.nb_channels;
520525 s->old_pts = AV_NOPTS_VALUE;
@@ -675,7 +680,6 @@ static int output_frame(AVFilterContext *ctx) · 154 unmodified lines
675680 AVFilterLink *outlink = ctx->outputs[0];
676681 AVFilterLink *inlink = ctx->inputs[0];
677682 ShowCWTContext *s = ctx->priv;
678− int64_t pts_offset;
679683 int ret;
680684
681685 switch (s->slide) {
@@ -709,35 +713,37 @@ static int output_frame(AVFilterContext *ctx) · 27 unmodified lines
709713
710714 ff_filter_execute(ctx, draw, NULL, NULL, s->nb_threads);
711715
712− pts_offset = av_rescale(s->ihop_index, s->hop_size, s->ihop_size);
713− s->outpicref->pts = av_rescale_q(s->in_pts + pts_offset, inlink->time_base, outlink->time_base);
714−
715− s->ihop_index++;
716− if (s->ihop_index >= s->ihop_size)
717− s->ihop_index = 0;
718−
719716 switch (s->slide) {
720717 case SLIDE_REPLACE:
718+ case SLIDE_FRAME:
721719 switch (s->direction) {
722720 case DIRECTION_LR:
723721 s->pos++;
724− if (s->pos >= s->w)
722+ if (s->pos >= s->w) {
725723 s->pos = 0;
724+ s->new_frame = 1;
725+ }
726726 break;
727727 case DIRECTION_RL:
728728 s->pos--;
729− if (s->pos < 0)
729+ if (s->pos < 0) {
730730 s->pos = s->w - 1;
731+ s->new_frame = 1;
732+ }
731733 break;
732734 case DIRECTION_UD:
733735 s->pos++;
734− if (s->pos >= s->h)
736+ if (s->pos >= s->h) {
735737 s->pos = 0;
738+ s->new_frame = 1;
739+ }
736740 break;
737741 case DIRECTION_DU:
738742 s->pos--;
739− if (s->pos < 0)
743+ if (s->pos < 0) {
740744 s->pos = s->h - 1;
745+ s->new_frame = 1;
746+ }
741747 break;
742748 }
743749 break;
@@ -757,6 +763,77 @@ static int output_frame(AVFilterContext *ctx) · 13 unmodified lines
757763 break;
758764 }
759765
766+ if (s->slide == SLIDE_FRAME && s->eof) {
767+ switch (s->direction) {
768+ case DIRECTION_LR:
769+ for (int p = 0; p < 3; p++) {
770+ ptrdiff_t linesize = s->outpicref->linesize[p];
771+ const int size = s->w - s->pos;
772+ const int fill = p ? 128 : 0;
773+ const int x = s->pos;
774+
775+ for (int y = 0; y < s->h; y++) {
776+ uint8_t *dst = s->outpicref->data[p] + y * linesize + x;
777+
778+ memset(dst, fill, size);
779+ }
780+ }
781+ break;
782+ case DIRECTION_RL:
783+ for (int p = 0; p < 3; p++) {
784+ ptrdiff_t linesize = s->outpicref->linesize[p];
785+ const int size = s->w - s->pos;
786+ const int fill = p ? 128 : 0;
787+
788+ for (int y = 0; y < s->h; y++) {
789+ uint8_t *dst = s->outpicref->data[p] + y * linesize;
790+
791+ memset(dst, fill, size);
792+ }
793+ }
794+ break;
795+ case DIRECTION_UD:
796+ for (int p = 0; p < 3; p++) {
797+ ptrdiff_t linesize = s->outpicref->linesize[p];
798+ const int fill = p ? 128 : 0;
799+
800+ for (int y = s->pos; y < s->h; y++) {
801+ uint8_t *dst = s->outpicref->data[p] + y * linesize;
802+
803+ memset(dst, fill, s->w);
804+ }
805+ }
806+ break;
807+ case DIRECTION_DU:
808+ for (int p = 0; p < 3; p++) {
809+ ptrdiff_t linesize = s->outpicref->linesize[p];
810+ const int fill = p ? 128 : 0;
811+
812+ for (int y = s->h - s->pos; y >= 0; y--) {
813+ uint8_t *dst = s->outpicref->data[p] + y * linesize;
814+
815+ memset(dst, fill, s->w);
816+ }
817+ }
818+ break;
819+ }
820+ }
821+
822+ s->new_frame = s->slide == SLIDE_FRAME && (s->new_frame || s->eof);
823+
824+ if (s->slide != SLIDE_FRAME || s->new_frame == 1) {
825+ int64_t pts_offset = s->new_frame ? 0LL : av_rescale(s->ihop_index, s->hop_size, s->ihop_size);
826+
827+ s->outpicref->pts = av_rescale_q(s->in_pts + pts_offset, inlink->time_base, outlink->time_base);
828+ }
829+
830+ s->ihop_index++;
831+ if (s->ihop_index >= s->ihop_size)
832+ s->ihop_index = 0;
833+
834+ if (s->slide == SLIDE_FRAME && s->new_frame == 0)
835+ return 1;
836+
760837 if (s->old_pts < s->outpicref->pts) {
761838 AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
762839 if (!out)
@@ -768,6 +845,7 @@ static int output_frame(AVFilterContext *ctx) · 5 unmodified lines
768845 if (ret < 0)
769846 goto fail;
770847 s->old_pts = s->outpicref->pts;
848+ s->new_frame = 0;
771849 ret = ff_filter_frame(outlink, out);
772850 if (ret <= 0)
773851 return ret;
@@ -816,8 +894,10 @@ static int activate(AVFilterContext *ctx) · 42 unmodified lines
816894 ff_filter_execute(ctx, run_channels_cwt_prepare, fin, NULL,
817895 FFMIN(s->nb_threads, s->nb_channels));
818896 if (fin) {
819− if (s->hop_index == 0)
897+ if ((s->hop_index == 0 && s->slide != SLIDE_FRAME) || s->new_frame) {
820898 s->in_pts = fin->pts;
899+ s->new_frame = 0;
900+ }
821901 s->hop_index += fin->nb_samples;
822902 av_frame_free(&fin);
823903 } else {
@@ -843,9 +923,12 @@ static int activate(AVFilterContext *ctx) · 19 unmodified lines
843923 }
844924 }
845925
846− if (s->eof && s->eof_pts != AV_NOPTS_VALUE && s->old_pts + 1 >= s->eof_pts) {
926+ if (s->eof && s->eof_pts != AV_NOPTS_VALUE &&
927+ (s->old_pts + 1 >= s->eof_pts || (s->slide == SLIDE_FRAME))) {
928+ if (s->slide == SLIDE_FRAME)
929+ ret = output_frame(ctx);
847930 ff_outlink_set_status(outlink, AVERROR_EOF, s->eof_pts);
848− return 0;
931+ return ret;
849932 }
850933
851934 if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t