avfilter/avf_showvolume: add background opacity option
This makes output more visible when overlayed. Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
016d40011a
commit
b78d55b2e6
@ -19941,8 +19941,11 @@ Set orientation, can be @code{horizontal} or @code{vertical},
|
|||||||
default is @code{horizontal}.
|
default is @code{horizontal}.
|
||||||
|
|
||||||
@item s
|
@item s
|
||||||
Set step size, allowed range s [0, 5]. Default is 0, which means
|
Set step size, allowed range is [0, 5]. Default is 0, which means
|
||||||
step is disabled.
|
step is disabled.
|
||||||
|
|
||||||
|
@item p
|
||||||
|
Set background opacity, allowed range is [0, 1]. Default is 0.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@section showwaves
|
@section showwaves
|
||||||
|
@ -43,6 +43,7 @@ typedef struct ShowVolumeContext {
|
|||||||
char *color;
|
char *color;
|
||||||
int orientation;
|
int orientation;
|
||||||
int step;
|
int step;
|
||||||
|
float bgopacity;
|
||||||
|
|
||||||
AVFrame *out;
|
AVFrame *out;
|
||||||
AVExpr *c_expr;
|
AVExpr *c_expr;
|
||||||
@ -69,6 +70,7 @@ static const AVOption showvolume_options[] = {
|
|||||||
{ "h", "horizontal", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "orientation" },
|
{ "h", "horizontal", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "orientation" },
|
||||||
{ "v", "vertical", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "orientation" },
|
{ "v", "vertical", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "orientation" },
|
||||||
{ "s", "set step size", OFFSET(step), AV_OPT_TYPE_INT, {.i64=0}, 0, 5, FLAGS },
|
{ "s", "set step size", OFFSET(step), AV_OPT_TYPE_INT, {.i64=0}, 0, 5, FLAGS },
|
||||||
|
{ "p", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, FLAGS },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -224,18 +226,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < outlink->h; i++)
|
for (i = 0; i < outlink->h; i++) {
|
||||||
memset(s->out->data[0] + i * s->out->linesize[0], 0, outlink->w * 4);
|
uint32_t *dst = (uint32_t *)(s->out->data[0] + i * s->out->linesize[0]);
|
||||||
|
const uint32_t bg = (uint32_t)(s->bgopacity * 255) << 24;
|
||||||
|
|
||||||
|
for (j = 0; j < outlink->w; j++)
|
||||||
|
AV_WN32A(dst + j, bg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s->out->pts = insamples->pts;
|
s->out->pts = insamples->pts;
|
||||||
|
|
||||||
for (j = 0; j < outlink->h; j++) {
|
for (j = 0; j < outlink->h; j++) {
|
||||||
uint8_t *dst = s->out->data[0] + j * s->out->linesize[0];
|
uint8_t *dst = s->out->data[0] + j * s->out->linesize[0];
|
||||||
|
const uint32_t alpha = s->bgopacity * 255;
|
||||||
|
|
||||||
for (k = 0; k < outlink->w; k++) {
|
for (k = 0; k < outlink->w; k++) {
|
||||||
dst[k * 4 + 0] = FFMAX(dst[k * 4 + 0] * s->f, 0);
|
dst[k * 4 + 0] = FFMAX(dst[k * 4 + 0] * s->f, 0);
|
||||||
dst[k * 4 + 1] = FFMAX(dst[k * 4 + 1] * s->f, 0);
|
dst[k * 4 + 1] = FFMAX(dst[k * 4 + 1] * s->f, 0);
|
||||||
dst[k * 4 + 2] = FFMAX(dst[k * 4 + 2] * s->f, 0);
|
dst[k * 4 + 2] = FFMAX(dst[k * 4 + 2] * s->f, 0);
|
||||||
dst[k * 4 + 3] = FFMAX(dst[k * 4 + 3] * s->f, 0);
|
dst[k * 4 + 3] = FFMAX(dst[k * 4 + 3] * s->f, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user