Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
3e3d5677
Commit
3e3d5677
authored
Mar 23, 2018
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/avf_showvolume: implement basic rms metering mode
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
74c6a6d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
6 deletions
+48
-6
filters.texi
doc/filters.texi
+4
-0
avf_showvolume.c
libavfilter/avf_showvolume.c
+44
-6
No files found.
doc/filters.texi
View file @
3e3d5677
...
...
@@ -19970,6 +19970,10 @@ step is disabled.
@item p
Set background opacity, allowed range is [0, 1]. Default is 0.
@item m
Set metering mode, can be peak: @code{p} or rms: @code{r},
default is @code{p}.
@end table
@section showwaves
...
...
libavfilter/avf_showvolume.c
View file @
3e3d5677
...
...
@@ -44,6 +44,7 @@ typedef struct ShowVolumeContext {
int
orientation
;
int
step
;
float
bgopacity
;
int
mode
;
AVFrame
*
out
;
AVExpr
*
c_expr
;
...
...
@@ -51,6 +52,10 @@ typedef struct ShowVolumeContext {
int
draw_volume
;
double
*
values
;
uint32_t
*
color_lut
;
float
*
max
;
float
rms_factor
;
void
(
*
meter
)(
float
*
src
,
int
nb_samples
,
float
*
max
,
float
factor
);
}
ShowVolumeContext
;
#define OFFSET(x) offsetof(ShowVolumeContext, x)
...
...
@@ -71,6 +76,9 @@ static const AVOption showvolume_options[] = {
{
"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
},
{
"p"
,
"set background opacity"
,
OFFSET
(
bgopacity
),
AV_OPT_TYPE_FLOAT
,
{.
dbl
=
0
},
0
,
1
,
FLAGS
},
{
"m"
,
"set mode"
,
OFFSET
(
mode
),
AV_OPT_TYPE_INT
,
{.
i64
=
0
},
0
,
1
,
FLAGS
,
"mode"
},
{
"p"
,
"peak"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
0
},
0
,
0
,
FLAGS
,
"mode"
},
{
"r"
,
"rms"
,
0
,
AV_OPT_TYPE_CONST
,
{.
i64
=
1
},
0
,
0
,
FLAGS
,
"mode"
},
{
NULL
}
};
...
...
@@ -120,6 +128,23 @@ static int query_formats(AVFilterContext *ctx)
return
0
;
}
static
void
find_peak
(
float
*
src
,
int
nb_samples
,
float
*
peak
,
float
factor
)
{
int
i
;
*
peak
=
0
;
for
(
i
=
0
;
i
<
nb_samples
;
i
++
)
*
peak
=
FFMAX
(
*
peak
,
FFABS
(
src
[
i
]));
}
static
void
find_rms
(
float
*
src
,
int
nb_samples
,
float
*
rms
,
float
factor
)
{
int
i
;
for
(
i
=
0
;
i
<
nb_samples
;
i
++
)
*
rms
+=
factor
*
(
src
[
i
]
*
src
[
i
]
-
*
rms
);
}
static
int
config_input
(
AVFilterLink
*
inlink
)
{
AVFilterContext
*
ctx
=
inlink
->
dst
;
...
...
@@ -138,6 +163,18 @@ static int config_input(AVFilterLink *inlink)
if
(
!
s
->
color_lut
)
return
AVERROR
(
ENOMEM
);
s
->
max
=
av_calloc
(
inlink
->
channels
,
sizeof
(
*
s
->
max
));
if
(
!
s
->
max
)
return
AVERROR
(
ENOMEM
);
s
->
rms_factor
=
10000
.
/
inlink
->
sample_rate
;
switch
(
s
->
mode
)
{
case
0
:
s
->
meter
=
find_peak
;
break
;
case
1
:
s
->
meter
=
find_rms
;
break
;
default:
return
AVERROR_BUG
;
}
return
0
;
}
...
...
@@ -252,10 +289,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
for
(
c
=
0
;
c
<
inlink
->
channels
;
c
++
)
{
float
*
src
=
(
float
*
)
insamples
->
extended_data
[
c
];
uint32_t
*
lut
=
s
->
color_lut
+
s
->
w
*
c
;
float
max
=
0
;
float
max
;
for
(
i
=
0
;
i
<
insamples
->
nb_samples
;
i
++
)
max
=
FFMAX
(
max
,
src
[
i
])
;
s
->
meter
(
src
,
insamples
->
nb_samples
,
&
s
->
max
[
c
],
s
->
rms_factor
);
max
=
s
->
max
[
c
]
;
s
->
values
[
c
*
VAR_VARS_NB
+
VAR_VOLUME
]
=
20
.
0
*
log10
(
max
);
max
=
av_clipf
(
max
,
0
,
1
);
...
...
@@ -280,10 +317,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
for
(
c
=
0
;
c
<
inlink
->
channels
;
c
++
)
{
float
*
src
=
(
float
*
)
insamples
->
extended_data
[
c
];
uint32_t
*
lut
=
s
->
color_lut
+
s
->
w
*
c
;
float
max
=
0
;
float
max
;
for
(
i
=
0
;
i
<
insamples
->
nb_samples
;
i
++
)
max
=
FFMAX
(
max
,
src
[
i
])
;
s
->
meter
(
src
,
insamples
->
nb_samples
,
&
s
->
max
[
c
],
s
->
rms_factor
);
max
=
s
->
max
[
c
]
;
s
->
values
[
c
*
VAR_VARS_NB
+
VAR_VOLUME
]
=
20
.
0
*
log10
(
max
);
max
=
av_clipf
(
max
,
0
,
1
);
...
...
@@ -339,6 +376,7 @@ static av_cold void uninit(AVFilterContext *ctx)
av_expr_free
(
s
->
c_expr
);
av_freep
(
&
s
->
values
);
av_freep
(
&
s
->
color_lut
);
av_freep
(
&
s
->
max
);
}
static
const
AVFilterPad
showvolume_inputs
[]
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment