Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
ccefa89f
Commit
ccefa89f
authored
12 years ago
by
Anton Khirnov
Browse files
Options
Downloads
Patches
Plain Diff
avfiltergraph: smarter sample format selection.
parent
0629f612
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavfilter/avfiltergraph.c
+70
-1
70 additions, 1 deletion
libavfilter/avfiltergraph.c
with
70 additions
and
1 deletion
libavfilter/avfiltergraph.c
+
70
−
1
View file @
ccefa89f
...
...
@@ -461,6 +461,74 @@ static void swap_channel_layouts(AVFilterGraph *graph)
swap_channel_layouts_on_filter
(
graph
->
filters
[
i
]);
}
static
void
swap_sample_fmts_on_filter
(
AVFilterContext
*
filter
)
{
AVFilterLink
*
link
=
NULL
;
int
format
,
bps
;
int
i
,
j
;
for
(
i
=
0
;
i
<
filter
->
input_count
;
i
++
)
{
link
=
filter
->
inputs
[
i
];
if
(
link
->
type
==
AVMEDIA_TYPE_AUDIO
&&
link
->
out_formats
->
format_count
==
1
)
break
;
}
if
(
i
==
filter
->
input_count
)
return
;
format
=
link
->
out_formats
->
formats
[
0
];
bps
=
av_get_bytes_per_sample
(
format
);
for
(
i
=
0
;
i
<
filter
->
output_count
;
i
++
)
{
AVFilterLink
*
outlink
=
filter
->
outputs
[
i
];
int
best_idx
,
best_score
=
INT_MIN
;
if
(
outlink
->
type
!=
AVMEDIA_TYPE_AUDIO
||
outlink
->
in_formats
->
format_count
<
2
)
continue
;
for
(
j
=
0
;
j
<
outlink
->
in_formats
->
format_count
;
j
++
)
{
int
out_format
=
outlink
->
in_formats
->
formats
[
j
];
int
out_bps
=
av_get_bytes_per_sample
(
out_format
);
int
score
;
if
(
av_get_packed_sample_fmt
(
out_format
)
==
format
||
av_get_planar_sample_fmt
(
out_format
)
==
format
)
{
best_idx
=
j
;
break
;
}
/* for s32 and float prefer double to prevent loss of information */
if
(
bps
==
4
&&
out_bps
==
8
)
{
best_idx
=
j
;
break
;
}
/* prefer closest higher or equal bps */
score
=
-
abs
(
out_bps
-
bps
);
if
(
out_bps
>=
bps
)
score
+=
INT_MAX
/
2
;
if
(
score
>
best_score
)
{
best_score
=
score
;
best_idx
=
j
;
}
}
FFSWAP
(
int
,
outlink
->
in_formats
->
formats
[
0
],
outlink
->
in_formats
->
formats
[
best_idx
]);
}
}
static
void
swap_sample_fmts
(
AVFilterGraph
*
graph
)
{
int
i
;
for
(
i
=
0
;
i
<
graph
->
filter_count
;
i
++
)
swap_sample_fmts_on_filter
(
graph
->
filters
[
i
]);
}
static
int
pick_formats
(
AVFilterGraph
*
graph
)
{
int
i
,
j
,
ret
;
...
...
@@ -491,8 +559,9 @@ int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx)
* of format conversion inside filters */
reduce_formats
(
graph
);
/* for audio filters, ensure the best sample rate and channel layout
/* for audio filters, ensure the best
format,
sample rate and channel layout
* is selected */
swap_sample_fmts
(
graph
);
swap_samplerates
(
graph
);
swap_channel_layouts
(
graph
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment