Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
4be8ab70
Commit
4be8ab70
authored
Aug 03, 2016
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/af_astats: extend bitdepth calculation
parent
b1ce8003
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
9 deletions
+28
-9
af_astats.c
libavfilter/af_astats.c
+28
-9
No files found.
libavfilter/af_astats.c
View file @
4be8ab70
...
...
@@ -35,7 +35,7 @@ typedef struct ChannelStats {
double
min_runs
,
max_runs
;
double
min_diff
,
max_diff
;
double
diff1_sum
;
uint64_t
mask
;
uint64_t
mask
,
imask
;
uint64_t
min_count
,
max_count
;
uint64_t
nb_samples
;
}
ChannelStats
;
...
...
@@ -116,6 +116,7 @@ static void reset_stats(AudioStatsContext *s)
p
->
max_runs
=
0
;
p
->
diff1_sum
=
0
;
p
->
mask
=
0
;
p
->
imask
=
0xFFFFFFFFFFFFFFFF
;
p
->
min_count
=
0
;
p
->
max_count
=
0
;
p
->
nb_samples
=
0
;
...
...
@@ -139,13 +140,20 @@ static int config_output(AVFilterLink *outlink)
return
0
;
}
static
unsigned
bit_depth
(
uint64_t
mask
)
static
void
bit_depth
(
uint64_t
mask
,
uint64_t
imask
,
AVRational
*
depth
)
{
unsigned
result
=
64
;
mask
=
mask
&
(
~
imask
);
for
(;
result
&&
!
(
mask
&
1
);
--
result
,
mask
>>=
1
);
return
result
;
depth
->
den
=
result
;
depth
->
num
=
0
;
for
(;
result
;
--
result
,
mask
>>=
1
)
if
(
mask
&
1
)
depth
->
num
++
;
}
static
inline
void
update_stat
(
AudioStatsContext
*
s
,
ChannelStats
*
p
,
double
d
)
...
...
@@ -182,6 +190,7 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d)
p
->
diff1_sum
+=
fabs
(
d
-
p
->
last
);
p
->
last
=
d
;
p
->
mask
|=
llrint
(
d
*
(
UINT64_C
(
1
)
<<
63
));
p
->
imask
&=
llrint
(
d
*
(
UINT64_C
(
1
)
<<
63
));
if
(
p
->
nb_samples
>=
s
->
tc_samples
)
{
p
->
max_sigma_x2
=
FFMAX
(
p
->
max_sigma_x2
,
p
->
avg_sigma_x2
);
...
...
@@ -208,7 +217,7 @@ static void set_meta(AVDictionary **metadata, int chan, const char *key,
static
void
set_metadata
(
AudioStatsContext
*
s
,
AVDictionary
**
metadata
)
{
uint64_t
mask
=
0
,
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
uint64_t
mask
=
0
,
imask
=
0xFFFFFFFFFFFFFFFF
,
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
double
min_runs
=
0
,
max_runs
=
0
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
min_diff
=
DBL_MAX
,
max_diff
=
0
,
max_sigma_x
=
0
,
...
...
@@ -217,6 +226,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
sigma_x2
=
0
,
min_sigma_x2
=
DBL_MAX
,
max_sigma_x2
=
DBL_MIN
;
AVRational
depth
;
int
c
;
for
(
c
=
0
;
c
<
s
->
nb_channels
;
c
++
)
{
...
...
@@ -239,6 +249,7 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
min_runs
+=
p
->
min_runs
;
max_runs
+=
p
->
max_runs
;
mask
|=
p
->
mask
;
imask
&=
p
->
imask
;
nb_samples
+=
p
->
nb_samples
;
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
max_sigma_x
=
p
->
sigma_x
;
...
...
@@ -256,7 +267,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta
(
metadata
,
c
+
1
,
"Crest_factor"
,
"%f"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
set_meta
(
metadata
,
c
+
1
,
"Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
set_meta
(
metadata
,
c
+
1
,
"Peak_count"
,
"%f"
,
(
float
)(
p
->
min_count
+
p
->
max_count
));
set_meta
(
metadata
,
c
+
1
,
"Bit_depth"
,
"%f"
,
bit_depth
(
p
->
mask
));
bit_depth
(
p
->
mask
,
p
->
imask
,
&
depth
);
set_meta
(
metadata
,
c
+
1
,
"Bit_depth"
,
"%f"
,
depth
.
num
);
set_meta
(
metadata
,
c
+
1
,
"Bit_depth2"
,
"%f"
,
depth
.
den
);
}
set_meta
(
metadata
,
0
,
"Overall.DC_offset"
,
"%f"
,
max_sigma_x
/
(
nb_samples
/
s
->
nb_channels
));
...
...
@@ -271,7 +284,9 @@ static void set_metadata(AudioStatsContext *s, AVDictionary **metadata)
set_meta
(
metadata
,
0
,
"Overall.RMS_trough"
,
"%f"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
set_meta
(
metadata
,
0
,
"Overall.Flat_factor"
,
"%f"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
set_meta
(
metadata
,
0
,
"Overall.Peak_count"
,
"%f"
,
(
float
)(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
set_meta
(
metadata
,
0
,
"Overall.Bit_depth"
,
"%f"
,
bit_depth
(
mask
));
bit_depth
(
mask
,
imask
,
&
depth
);
set_meta
(
metadata
,
0
,
"Overall.Bit_depth"
,
"%f"
,
depth
.
num
);
set_meta
(
metadata
,
0
,
"Overall.Bit_depth2"
,
"%f"
,
depth
.
den
);
set_meta
(
metadata
,
0
,
"Overall.Number_of_samples"
,
"%f"
,
nb_samples
/
s
->
nb_channels
);
}
...
...
@@ -320,7 +335,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static
void
print_stats
(
AVFilterContext
*
ctx
)
{
AudioStatsContext
*
s
=
ctx
->
priv
;
uint64_t
mask
=
0
,
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
uint64_t
mask
=
0
,
imask
=
0xFFFFFFFFFFFFFFFF
,
min_count
=
0
,
max_count
=
0
,
nb_samples
=
0
;
double
min_runs
=
0
,
max_runs
=
0
,
min
=
DBL_MAX
,
max
=
DBL_MIN
,
min_diff
=
DBL_MAX
,
max_diff
=
0
,
max_sigma_x
=
0
,
...
...
@@ -329,6 +344,7 @@ static void print_stats(AVFilterContext *ctx)
sigma_x2
=
0
,
min_sigma_x2
=
DBL_MAX
,
max_sigma_x2
=
DBL_MIN
;
AVRational
depth
;
int
c
;
for
(
c
=
0
;
c
<
s
->
nb_channels
;
c
++
)
{
...
...
@@ -351,6 +367,7 @@ static void print_stats(AVFilterContext *ctx)
min_runs
+=
p
->
min_runs
;
max_runs
+=
p
->
max_runs
;
mask
|=
p
->
mask
;
imask
&=
p
->
imask
;
nb_samples
+=
p
->
nb_samples
;
if
(
fabs
(
p
->
sigma_x
)
>
fabs
(
max_sigma_x
))
max_sigma_x
=
p
->
sigma_x
;
...
...
@@ -370,7 +387,8 @@ static void print_stats(AVFilterContext *ctx)
av_log
(
ctx
,
AV_LOG_INFO
,
"Crest factor: %f
\n
"
,
p
->
sigma_x2
?
FFMAX
(
-
p
->
min
,
p
->
max
)
/
sqrt
(
p
->
sigma_x2
/
p
->
nb_samples
)
:
1
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
p
->
min_runs
+
p
->
max_runs
)
/
(
p
->
min_count
+
p
->
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %"
PRId64
"
\n
"
,
p
->
min_count
+
p
->
max_count
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u
\n
"
,
bit_depth
(
p
->
mask
));
bit_depth
(
p
->
mask
,
p
->
imask
,
&
depth
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u/%u
\n
"
,
depth
.
num
,
depth
.
den
);
}
av_log
(
ctx
,
AV_LOG_INFO
,
"Overall
\n
"
);
...
...
@@ -387,7 +405,8 @@ static void print_stats(AVFilterContext *ctx)
av_log
(
ctx
,
AV_LOG_INFO
,
"RMS trough dB: %f
\n
"
,
LINEAR_TO_DB
(
sqrt
(
min_sigma_x2
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Flat factor: %f
\n
"
,
LINEAR_TO_DB
((
min_runs
+
max_runs
)
/
(
min_count
+
max_count
)));
av_log
(
ctx
,
AV_LOG_INFO
,
"Peak count: %f
\n
"
,
(
min_count
+
max_count
)
/
(
double
)
s
->
nb_channels
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u
\n
"
,
bit_depth
(
mask
));
bit_depth
(
mask
,
imask
,
&
depth
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Bit depth: %u/%u
\n
"
,
depth
.
num
,
depth
.
den
);
av_log
(
ctx
,
AV_LOG_INFO
,
"Number of samples: %"
PRId64
"
\n
"
,
nb_samples
/
s
->
nb_channels
);
}
...
...
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