Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
d371e7b9
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d371e7b9
编写于
5月 04, 2012
作者:
A
Anton Khirnov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lavfi: add lavr-based audio resampling filter.
上级
ea60dfe2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
235 addition
and
0 deletion
+235
-0
configure
configure
+1
-0
doc/filters.texi
doc/filters.texi
+6
-0
libavfilter/Makefile
libavfilter/Makefile
+2
-0
libavfilter/af_resample.c
libavfilter/af_resample.c
+225
-0
libavfilter/allfilters.c
libavfilter/allfilters.c
+1
-0
未找到文件。
configure
浏览文件 @
d371e7b9
...
...
@@ -1531,6 +1531,7 @@ frei0r_filter_extralibs='$ldl'
frei0r_src_filter_deps
=
"frei0r dlopen strtok_r"
frei0r_src_filter_extralibs
=
'$ldl'
hqdn3d_filter_deps
=
"gpl"
resample_filter_deps
=
"avresample"
ocv_filter_deps
=
"libopencv"
yadif_filter_deps
=
"gpl"
...
...
doc/filters.texi
浏览文件 @
d371e7b9
...
...
@@ -111,6 +111,12 @@ Below is a description of the currently available audio filters.
Pass the audio source unchanged to the output.
@section resample
Convert the audio sample format, sample rate and channel layout. This filter is
not meant to be used directly, it is inserted automatically by libavfilter
whenever conversion is needed. Use the @var{aformat} filter to force a specific
conversion.
@c man end AUDIO FILTERS
@chapter Audio Sources
...
...
libavfilter/Makefile
浏览文件 @
d371e7b9
NAME
=
avfilter
FFLIBS
=
avutil swscale
FFLIBS-$(CONFIG_MOVIE_FILTER)
+=
avformat avcodec
FFLIBS-$(CONFIG_RESAMPLE_FILTER)
+=
avresample
HEADERS
=
avfilter.h
\
avfiltergraph.h
\
...
...
@@ -22,6 +23,7 @@ OBJS = allfilters.o \
vsrc_buffer.o
\
OBJS-$(CONFIG_ANULL_FILTER)
+=
af_anull.o
OBJS-$(CONFIG_RESAMPLE_FILTER)
+=
af_resample.o
OBJS-$(CONFIG_ANULLSRC_FILTER)
+=
asrc_anullsrc.o
...
...
libavfilter/af_resample.c
0 → 100644
浏览文件 @
d371e7b9
/*
*
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* sample format and channel layout conversion audio filter
*/
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavresample/avresample.h"
#include "audio.h"
#include "avfilter.h"
#include "internal.h"
typedef
struct
ResampleContext
{
AVAudioResampleContext
*
avr
;
int64_t
next_pts
;
}
ResampleContext
;
static
av_cold
void
uninit
(
AVFilterContext
*
ctx
)
{
ResampleContext
*
s
=
ctx
->
priv
;
if
(
s
->
avr
)
{
avresample_close
(
s
->
avr
);
avresample_free
(
&
s
->
avr
);
}
}
static
int
query_formats
(
AVFilterContext
*
ctx
)
{
AVFilterLink
*
inlink
=
ctx
->
inputs
[
0
];
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFilterFormats
*
in_formats
=
avfilter_all_formats
(
AVMEDIA_TYPE_AUDIO
);
AVFilterFormats
*
out_formats
=
avfilter_all_formats
(
AVMEDIA_TYPE_AUDIO
);
avfilter_formats_ref
(
in_formats
,
&
inlink
->
out_formats
);
avfilter_formats_ref
(
out_formats
,
&
outlink
->
in_formats
);
return
0
;
}
static
int
config_output
(
AVFilterLink
*
outlink
)
{
AVFilterContext
*
ctx
=
outlink
->
src
;
AVFilterLink
*
inlink
=
ctx
->
inputs
[
0
];
ResampleContext
*
s
=
ctx
->
priv
;
char
buf1
[
64
],
buf2
[
64
];
int
ret
;
if
(
s
->
avr
)
{
avresample_close
(
s
->
avr
);
avresample_free
(
&
s
->
avr
);
}
if
(
inlink
->
channel_layout
==
outlink
->
channel_layout
&&
inlink
->
sample_rate
==
outlink
->
sample_rate
&&
inlink
->
format
==
outlink
->
format
)
return
0
;
if
(
!
(
s
->
avr
=
avresample_alloc_context
()))
return
AVERROR
(
ENOMEM
);
av_opt_set_int
(
s
->
avr
,
"in_channel_layout"
,
inlink
->
channel_layout
,
0
);
av_opt_set_int
(
s
->
avr
,
"out_channel_layout"
,
outlink
->
channel_layout
,
0
);
av_opt_set_int
(
s
->
avr
,
"in_sample_fmt"
,
inlink
->
format
,
0
);
av_opt_set_int
(
s
->
avr
,
"out_sample_fmt"
,
outlink
->
format
,
0
);
av_opt_set_int
(
s
->
avr
,
"in_sample_rate"
,
inlink
->
sample_rate
,
0
);
av_opt_set_int
(
s
->
avr
,
"out_sample_rate"
,
outlink
->
sample_rate
,
0
);
/* if both the input and output formats are s16 or u8, use s16 as
the internal sample format */
if
(
av_get_bytes_per_sample
(
inlink
->
format
)
<=
2
&&
av_get_bytes_per_sample
(
outlink
->
format
)
<=
2
)
av_opt_set_int
(
s
->
avr
,
"internal_sample_fmt"
,
AV_SAMPLE_FMT_S16P
,
0
);
if
((
ret
=
avresample_open
(
s
->
avr
))
<
0
)
return
ret
;
outlink
->
time_base
=
(
AVRational
){
1
,
outlink
->
sample_rate
};
s
->
next_pts
=
AV_NOPTS_VALUE
;
av_get_channel_layout_string
(
buf1
,
sizeof
(
buf1
),
-
1
,
inlink
->
channel_layout
);
av_get_channel_layout_string
(
buf2
,
sizeof
(
buf2
),
-
1
,
outlink
->
channel_layout
);
av_log
(
ctx
,
AV_LOG_VERBOSE
,
"fmt:%s srate: %d cl:%s -> fmt:%s srate: %d cl:%s
\n
"
,
av_get_sample_fmt_name
(
inlink
->
format
),
inlink
->
sample_rate
,
buf1
,
av_get_sample_fmt_name
(
outlink
->
format
),
outlink
->
sample_rate
,
buf2
);
return
0
;
}
static
int
request_frame
(
AVFilterLink
*
outlink
)
{
AVFilterContext
*
ctx
=
outlink
->
src
;
ResampleContext
*
s
=
ctx
->
priv
;
int
ret
=
avfilter_request_frame
(
ctx
->
inputs
[
0
]);
/* flush the lavr delay buffer */
if
(
ret
==
AVERROR_EOF
&&
s
->
avr
)
{
AVFilterBufferRef
*
buf
;
int
nb_samples
=
av_rescale_rnd
(
avresample_get_delay
(
s
->
avr
),
outlink
->
sample_rate
,
ctx
->
inputs
[
0
]
->
sample_rate
,
AV_ROUND_UP
);
if
(
!
nb_samples
)
return
ret
;
buf
=
ff_get_audio_buffer
(
outlink
,
AV_PERM_WRITE
,
nb_samples
);
if
(
!
buf
)
return
AVERROR
(
ENOMEM
);
ret
=
avresample_convert
(
s
->
avr
,
(
void
**
)
buf
->
extended_data
,
buf
->
linesize
[
0
],
nb_samples
,
NULL
,
0
,
0
);
if
(
ret
<=
0
)
{
avfilter_unref_buffer
(
buf
);
return
(
ret
==
0
)
?
AVERROR_EOF
:
ret
;
}
buf
->
pts
=
s
->
next_pts
;
ff_filter_samples
(
outlink
,
buf
);
return
0
;
}
return
ret
;
}
static
void
filter_samples
(
AVFilterLink
*
inlink
,
AVFilterBufferRef
*
buf
)
{
AVFilterContext
*
ctx
=
inlink
->
dst
;
ResampleContext
*
s
=
ctx
->
priv
;
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
if
(
s
->
avr
)
{
AVFilterBufferRef
*
buf_out
;
int
delay
,
nb_samples
,
ret
;
/* maximum possible samples lavr can output */
delay
=
avresample_get_delay
(
s
->
avr
);
nb_samples
=
av_rescale_rnd
(
buf
->
audio
->
nb_samples
+
delay
,
outlink
->
sample_rate
,
inlink
->
sample_rate
,
AV_ROUND_UP
);
buf_out
=
ff_get_audio_buffer
(
outlink
,
AV_PERM_WRITE
,
nb_samples
);
ret
=
avresample_convert
(
s
->
avr
,
(
void
**
)
buf_out
->
extended_data
,
buf_out
->
linesize
[
0
],
nb_samples
,
(
void
**
)
buf
->
extended_data
,
buf
->
linesize
[
0
],
buf
->
audio
->
nb_samples
);
av_assert0
(
!
avresample_available
(
s
->
avr
));
if
(
s
->
next_pts
==
AV_NOPTS_VALUE
)
{
if
(
buf
->
pts
==
AV_NOPTS_VALUE
)
{
av_log
(
ctx
,
AV_LOG_WARNING
,
"First timestamp is missing, "
"assuming 0.
\n
"
);
s
->
next_pts
=
0
;
}
else
s
->
next_pts
=
av_rescale_q
(
buf
->
pts
,
inlink
->
time_base
,
outlink
->
time_base
);
}
if
(
ret
>
0
)
{
buf_out
->
audio
->
nb_samples
=
ret
;
if
(
buf
->
pts
!=
AV_NOPTS_VALUE
)
{
buf_out
->
pts
=
av_rescale_q
(
buf
->
pts
,
inlink
->
time_base
,
outlink
->
time_base
)
-
av_rescale
(
delay
,
outlink
->
sample_rate
,
inlink
->
sample_rate
);
}
else
buf_out
->
pts
=
s
->
next_pts
;
s
->
next_pts
=
buf_out
->
pts
+
buf_out
->
audio
->
nb_samples
;
ff_filter_samples
(
outlink
,
buf_out
);
}
avfilter_unref_buffer
(
buf
);
}
else
ff_filter_samples
(
outlink
,
buf
);
}
AVFilter
avfilter_af_resample
=
{
.
name
=
"resample"
,
.
description
=
NULL_IF_CONFIG_SMALL
(
"Audio resampling and conversion."
),
.
priv_size
=
sizeof
(
ResampleContext
),
.
uninit
=
uninit
,
.
query_formats
=
query_formats
,
.
inputs
=
(
const
AVFilterPad
[])
{{
.
name
=
"default"
,
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
filter_samples
=
filter_samples
,
.
min_perms
=
AV_PERM_READ
},
{
.
name
=
NULL
}},
.
outputs
=
(
const
AVFilterPad
[])
{{
.
name
=
"default"
,
.
type
=
AVMEDIA_TYPE_AUDIO
,
.
config_props
=
config_output
,
.
request_frame
=
request_frame
},
{
.
name
=
NULL
}},
};
libavfilter/allfilters.c
浏览文件 @
d371e7b9
...
...
@@ -35,6 +35,7 @@ void avfilter_register_all(void)
initialized
=
1
;
REGISTER_FILTER
(
ANULL
,
anull
,
af
);
REGISTER_FILTER
(
RESAMPLE
,
resample
,
af
);
REGISTER_FILTER
(
ANULLSRC
,
anullsrc
,
asrc
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录