| FFmpeg
    | 
音频重采样、样本格式转换和混音库。 更多的...
| 文件 | |
| file | swresample.h | 
| 功能 | |
| const AVClass * | swr_get_class(无效) | 
| 获取SwrContext的AVClass。  更多的... | |
| 选项常量 | |
| These constants are used for the AVOptions interface for lswr. | |
| enum | SwrDitherType { SWR_DITHER_NONE = 0, SWR_DITHER_RECTANGULAR, SWR_DITHER_TRIANGULAR, SWR_DITHER_TRIANGULAR_HIGHPASS, SWR_DITHER_NS = 64, SWR_DITHER_NS_LIPSHITZ, SWR_DITHER_NS_F_WEIGHTED, SWR_DIT_NS_MODIFIED_ E_WEIGHTED , SWR_DITHER_NS_IMPROVED_E_WEIGHTED, SWR_DITHER_NS_SHIBATA, SWR_DITHER_NS_LOW_SHIBATA, SWR_DITHER_NS_HIGH_SHIBATA, SWR_DITHER_NB } | 
| 抖动算法。  更多的... | |
| enum | SwrEngine { SWR_ENGINE_SWR , SWR_ENGINE_SOXR , SWR_ENGINE_NB } | 
| 重新采样引擎。  更多的... | |
| enum | SwrFilterType { SWR_FILTER_TYPE_CUBIC, SWR_FILTER_TYPE_BLACKMAN_NUTTALL, SWR_FILTER_TYPE_KAISER } | 
| 重新采样滤波器类型。  更多的... | |
| #define | SWR_FLAG_RESAMPLE 1 | 
| 即使采样率相同,也会强制重新采样。  更多的... | |
| SwrContext 构造函数 | |
| struct SwrContext * | swr_alloc(空) | 
| 分配SwrContext。  更多的... | |
| int | swr_init (结构SwrContext * s ) | 
| 设置用户参数后初始化上下文。  更多的... | |
| int | swr_is_initialized (结构SwrContext * s ) | 
| 检查swr上下文是否已初始化。  更多的... | |
| int | swr_alloc_set_opts2(结构SwrContext **ps,const AVChannelLayout *out_ch_layout,枚举AVSampleFormat out_sample_fmt,int out_sample_rate,const AVChannelLayout *in_ch_layout,枚举AVSampleFormat in_sample_fmt,int in_sample_rate,int log_offset,void *log_ctx) | 
| 如果需要,分配SwrContext并设置/重置公共参数。  更多的... | |
| SwrContext 析构函数 | |
| void | swr_free (结构SwrContext ** s ) | 
| 释放给定的SwrContext并将指针设置为 NULL。  更多的... | |
| void | swr_close (结构SwrContext * s ) | 
| 关闭上下文,以便swr_is_initialized()返回 0。  更多... | |
| 核心转换函数 | |
| int | swr_convert(struct SwrContext * s,uint8_t ** out,int out_count,const uint8_t **in,int in_count) | 
| 转换音频。  更多的... | |
| int64_t | swr_next_pts(结构SwrContext * s, int64_t pts) | 
| 将下一个时间戳从输入时间戳转换为输出时间戳,单位为 1/(in_sample_rate * out_sample_rate)。  更多的... | |
| 低级选项设置功能 | |
| These functons provide a means to set low-level options that is not possible with the AVOption API. | |
| int | swr_set_compensation (struct SwrContext * s , intsample_delta , intcompensation_distance ) | 
| 激活重采样补偿(“软”补偿)。  更多的... | |
| int | swr_set_channel_mapping (struct SwrContext * s , const int * channel_map ) | 
| 设置自定义输入通道映射。  更多的... | |
| int | swr_build_matrix2(const AVChannelLayout * in_layout,const AVChannelLayout * out_layout,双center_mix_level,双surround_mix_level,双lfe_mix_level,双maxval,双rematrix_volume,双*矩阵,ptrdiff_t步幅,枚举AVMatrixEncoding矩阵编码,无效* log_context) | 
| 生成通道混合矩阵。  更多的... | |
| int | swr_set_matrix(结构SwrContext * s, const double *矩阵,int 步幅) | 
| 设置自定义混音矩阵。  更多的... | |
| 样品处理功能 | |
| int | swr_drop_output (struct SwrContext * s , int count) | 
| 删除指定数量的输出样本。  更多的... | |
| int | swr_inject_silence (struct SwrContext * s , int count) | 
| 注入指定数量的静音样本。  更多的... | |
| int64_t | swr_get_delay (结构SwrContext * s , int64_t基) | 
| 获取下一个输入样本相对于下一个输出样本将经历的延迟。  更多的... | |
| int | swr_get_out_samples(struct SwrContext * s,int in_samples) | 
| 如果使用输入样本的 in_samples 进行调用,则找到下一个 swr_convert 调用将输出的样本数量的上限。  更多的... | |
| 配置访问器 | |
| unsigned | swrsample_version(空) | 
| 返回LIBSWRESAMPLE_VERSION_INT常量。  更多的... | |
| const char * | swrsample_configuration(空) | 
| 返回 swr 构建时配置。  更多的... | |
| const char * | swrsample_license(无效) | 
| 返回 swr 许可证。  更多的... | |
| 基于 AVFrame 的 API | |
| int | swr_convert_frame ( SwrContext *swr, AVFrame *输出, const AVFrame *输入) | 
| 转换输入AVFrame中的样本并将其写入输出AVFrame。  更多的... | |
| int | swr_config_frame ( SwrContext *swr, const AVFrame * out , const AVFrame *in ) | 
| 使用 AVFrame 提供的信息  配置或重新配置SwrContext 。更多的... | |
音频重采样、样本格式转换和混音库。
与 lswr 的交互是通过SwrContext完成的,它是用swr_alloc()或swr_alloc_set_opts2()分配的。它是不透明的,因此所有参数都必须使用AVOptions API设置。
为了使用 lswr,您需要做的第一件事是分配SwrContext。这可以通过swr_alloc()或swr_alloc_set_opts2()来完成。如果您使用前者,则必须通过AVOptions API 设置选项。后一个函数提供相同的功能,但它允许您在同一语句中设置一些常用选项。
例如,以下代码将设置从平面浮点采样格式到交错有符号 16 位整数的转换、从 48kHz 下采样到 44.1kHz 以及从 5.1 声道下混音到立体声(使用默认混合矩阵)。这是使用swr_alloc()函数。
也可以使用swr_alloc_set_opts2()完成相同的工作:
设置所有值后,必须使用swr_init()对其进行初始化。如果需要更改转换参数,可以使用AVOptions更改参数,如上面第一个示例中所述;或者使用swr_alloc_set_opts2(),但第一个参数是分配的上下文。然后您必须再次调用swr_init()。
转换本身是通过重复调用swr_convert()来完成的。请注意,如果您提供的输出空间不足或完成采样率转换(这需要“未来”样本),则样本可能会在 swr 中缓冲。不需要将来输入的样本可以使用swr_convert()随时检索(in_count 可以设置为 0)。在转换结束时,可以通过使用NULL in 和 0 in_count调用swr_convert()来刷新重采样缓冲区。
转换过程中使用的样本可以使用 libavutil样本操作API 进行管理,包括以下示例中使用的av_samples_alloc()函数。
输入和输出之间的延迟可以随时使用swr_get_delay()找到。
以下代码演示了假设上面的参数以及调用者定义的函数get_input()和 handle_output() 的转换循环:
转换完成后,必须使用swr_free()释放转换上下文以及与其关联的所有内容。swr_close ()函数也可用,但它的存在主要是为了与 libavresample 兼容,并且不需要调用。
如果在swr_free()之前数据没有完全刷新,则不会出现内存泄漏。
| #define SWR_FLAG_RESAMPLE 1 | 
即使采样率相同,也会强制重新采样。
文件swresample.h第143行的定义。
| enum SwrDitherType | 
抖动算法。
文件swresample.h第148行的定义。
| enum SwrEngine | 
重新采样引擎。
| 枚举器 | |
|---|---|
| SWR_ENGINE_SWR | SW重采样器。 | 
| SWR_ENGINE_SOXR | SoX重采样器。 | 
| SWR_ENGINE_NB | 不是 API/ABI 的一部分 | 
定义位于文件swresample.h的第166行。
| enum SwrFilterType | 
重新采样滤波器类型。
| 枚举器 | |
|---|---|
| SWR_FILTER_TYPE_CUBIC | 立方体。 | 
| SWR_FILTER_TYPE_BLACKMAN_NUTTALL | 布莱克曼·纳托尔(Blackman Nuttall)窗口化。 | 
| SWR_FILTER_TYPE_KAISER | 凯撒开窗以来。 | 
文件swresample.h第173行的定义。
| const AVClass* swr_get_class | ( | 空白 | ) | 
它可以与 AV_OPT_SEARCH_FAKE_OBJ 结合使用来检查选项。
文件options.c第164行的定义。
由opt_default()、resample_child_class_iterate()和show_help_default()引用。
| struct SwrContext* swr_alloc | ( | 空白 | ) | 
分配SwrContext。
如果使用此函数,则需要在调用swr_init()之前设置参数(手动或使用swr_alloc_set_opts2() ) 。
文件options.c第169行的定义。
由config_audio_output()、main()、open_audio()、opus_decode_init()、preinit()和swr_alloc_set_opts2()引用。
| int swr_init | ( | 结构SwrContext * | s | ) | 
设置用户参数后初始化上下文。
| [in,out] | s | 要初始化的 Swr 上下文 | 
文件swresample.c第193行的定义。
由audio_decode_frame()、config_audio_output()、config_output()、config_props()、init_resampler()、main()、open_audio()、opus_init_resample()、swr_convert_frame()和swr_set_compensation()引用。
| int swr_is_initialized | ( | 结构SwrContext * | s | ) | 
检查swr上下文是否已初始化。
| [in] | s | 要检查的 Swr 上下文 | 
文件swresample.c第832行的定义。
由opus_decode_frame()、opus_decode_subpacket()、swr_convert()和swr_convert_frame()引用。
| int swr_alloc_set_opts2 | ( | 结构SwrContext ** | 附: | 
| 常量AVChannelLayout * | 输出通道布局, | ||
| 枚举AVSampleFormat | 输出样本fmt, | ||
| 整数 | 输出样本率, | ||
| 常量AVChannelLayout * | in_ch_layout , | ||
| 枚举AVSampleFormat | in_sample_fmt , | ||
| 整数 | in_sample_rate , | ||
| 整数 | 对数偏移量, | ||
| 空白 * | 日志_ctx | ||
| ) | 
如果需要,分配SwrContext并设置/重置公共参数。
此函数不需要使用swr_alloc()分配 *ps 。另一方面,swr_alloc()可以使用swr_alloc_set_opts2()在分配的上下文上设置参数。
| ps | 指向现有 Swr 上下文(如果可用)的指针,如果不存在则指向 NULL。成功后,*ps 将被设置为分配的上下文。 | 
| out_ch_layout | 输出通道布局(例如AV_CHANNEL_LAYOUT_*) | 
| out_sample_fmt | 输出样本格式(AV_SAMPLE_FMT_*)。 | 
| out_sample_rate | 输出采样率(频率,单位 Hz) | 
| in_ch_layout | 输入通道布局(例如 AV_CHANNEL_LAYOUT_*) | 
| in_sample_fmt | 输入样本格式(AV_SAMPLE_FMT_*)。 | 
| in_sample_rate | 输入采样率(频率,单位 Hz) | 
| log_offset | 日志记录级别偏移 | 
| log_ctx | 父日志记录上下文,可以为 NULL | 
定义位于文件swresample.c第85行。
由audio_decode_frame()、config_output()、config_props()、init_resampler()和main()引用。
| void swr_free | ( | 结构SwrContext ** | s | ) | 
释放给定的SwrContext并将指针设置为 NULL。
| [in] | s | 指向 Swr 上下文的指针 | 
文件swresample.c第174行的定义。
由audio_decode_frame()、close_stream()、init_resampler()、main()、opus_decode_close()、stream_component_close()、swr_alloc_set_opts2()和uninit()引用。
| void swr_close | ( | 结构SwrContext * | s | ) | 
关闭上下文以便swr_is_initialized()返回 0。
可以通过运行swr_init()来恢复上下文,也可以在不使用swr_close()的情况下使用swr_init( ) 。提供此函数主要是为了简化尝试支持 libavresample 和 libswresample 的用例。
| [in,out] | s | swr 上下文要关闭 | 
文件swresample.c第189行的定义。
由opus_decode_flush()、opus_decode_subpacket()、swr_config_frame()、swr_convert_frame()和swr_init()引用。
| int swr_convert | ( | 结构SwrContext * | , _ | 
| uint8_t ** | 出去, | ||
| 整数 | 输出计数, | ||
| 常量 uint8_t ** | 在, | ||
| 整数 | 计数中 | ||
| ) | 
转换音频。
in 和 in_count 可以设置为 0 以在最后刷新最后几个样本。
如果提供的输入多于输出空间,则输入将被缓冲。您可以通过使用swr_get_out_samples()检索给定数量的输入样本所需的输出样本数量的上限来避免这种缓冲。只要有可能,转换将直接运行而不进行复制。
| s | 已分配 Swr 上下文,并设置了参数 | 
| out | 输出缓冲区,在打包音频的情况下只需要设置第一个 | 
| out_count | 每个通道样本中可用于输出的空间量 | 
| in | 输入缓冲区,在打包音频的情况下仅需要设置第一个缓冲区 | 
| in_count | 一个通道中可用的输入样本数量 | 
文件swresample.c第836行的定义。
由audio_decode_frame()、convert_frame()、convert_samples()、filter_frame()、flush_frame()、main()、opus_decode_frame()、opus_flush_resample( ) 、opus_init_resample()、swr_convert()、swr_drop_output()、swr_inject_silence()引用,wrap()和write_audio_frame()。
| int64_t swr_next_pts | ( | 结构SwrContext * | , _ | 
| int64_t | 分 | ||
| ) | 
将下一个时间戳从输入时间戳转换为输出时间戳,单位为 1/(in_sample_rate * out_sample_rate)。
| [in] | s | 初始化的 Swr 上下文 | 
| [in] | 分 | 下一个输入样本的时间戳,如果未知则为 INT64_MIN | 
文件swresample.c第1041行的定义。
| int swr_set_compensation | ( | 结构SwrContext * | , _ | 
| 整数 | 样本增量, | ||
| 整数 | 补偿距离 | ||
| ) | 
激活重采样补偿(“软”补偿)。
当需要时在swr_next_pts()中内部调用该函数。
| [in,out] | s | 分配的 Swr 上下文。如果未初始化,或未设置 SWR_FLAG_RESAMPLE,则调用swr_init()并设置标志。 | 
| [in] | 样本增量 | 每个样本的 PTS 增量 | 
| [in] | 补偿距离 | 要补偿的样本数量 | 
s一片空白,compensation_distance小于 0,compensation_distance是 0 但sample_delta 不是,文件swresample.c第1021行的定义。
| int swr_set_channel_mapping | ( | 结构SwrContext * | , _ | 
| 常量整型* | 频道地图 | ||
| ) | 
设置自定义输入通道映射。
| [in,out] | s | 已分配的 Swr 上下文,尚未初始化 | 
| [in] | 频道地图 | 自定义输入通道映射(通道索引数组,-1 表示静音通道) | 
定义位于文件swresample.c的第32行。
| int swr_build_matrix2 | ( | 常量AVChannelLayout * | 在布局中, | 
| 常量AVChannelLayout * | 输出布局, | ||
| 双倍的 | center_mix_level , | ||
| 双倍的 | 环绕混合级别, | ||
| 双倍的 | lfe_mix_level , | ||
| 双倍的 | 最大值, | ||
| 双倍的 | 重新矩阵体积, | ||
| 双倍的* | 矩阵, | ||
| ptrdiff_t | 跨步, | ||
| 枚举AVMatrixEncoding | 矩阵编码, | ||
| 空白 * | 日志上下文 | ||
| ) | 
生成通道混合矩阵。
该函数是 libswresample 内部使用的函数,用于构建默认的混合矩阵。它只是作为构建自定义矩阵的实用函数而公开的。
| 布局中 | 输入通道布局 | |
| 输出布局 | 输出通道布局 | |
| 中心混合级别 | 中央通道的混合电平 | |
| 环绕混音级别 | 环绕声道的混合级别 | |
| 生命混合级别 | 低频效果通道的混合电平 | |
| rematrix_maxval | 如果为 1.0,系数将被标准化以防止溢出。如果为 INT_MAX,则系数不会被归一化。 | |
| [out] | 矩阵 | 混合系数;Matrix[i + stride * o] 是输入通道 i 在输出通道 o 中的权重。 | 
| 跨步 | 矩阵阵列中相邻输入通道之间的距离 | |
| 矩阵编码 | 矩阵立体声缩混模式(例如 dplii) | |
| 日志_ctx | 父日志记录上下文,可以为 NULL | 
文件rematrix.c第170行的定义。
| int swr_set_matrix | ( | 结构SwrContext * | , _ | 
| 常量双* | 矩阵, | ||
| 整数 | 跨步 | ||
| ) | 
设置自定义混音矩阵。
| s | 已分配的 Swr 上下文,尚未初始化 | 
| matrix | 混音系数;matrix[i + stride * o] 是输入通道 i 在输出通道 o 中的权重 | 
| stride | 矩阵行之间的偏移 | 
文件rematrix.c第64行的定义。
| int swr_drop_output | ( | 结构SwrContext * | , _ | 
| 整数 | 数数 | ||
| ) | 
删除指定数量的输出样本。
如果需要“硬”补偿,则该函数与swr_inject_silence()一起由swr_next_pts()调用。
| s | 分配的 Swr 上下文 | 
| count | 要丢弃的样本数量 | 
文件swresample.c第952行的定义。
| int swr_inject_silence | ( | 结构SwrContext * | , _ | 
| 整数 | 数数 | ||
| ) | 
注入指定数量的静音样本。
如果需要“硬”补偿,则该函数与swr_drop_output()一起由swr_next_pts()调用。
| s | 分配的 Swr 上下文 | 
| count | 要丢弃的样本数量 | 
文件swresample.c第963行的定义。
| int64_t swr_get_delay | ( | 结构SwrContext * | , _ | 
| int64_t | 根据 | ||
| ) | 
获取下一个输入样本相对于下一个输出样本将经历的延迟。
如果提供的输入多于可用输出空间,Swresample 可以缓冲数据,并且采样率之间的转换也需要延迟。该函数返回所有此类延迟的总和。确切的延迟不一定是输入或输出采样率的整数值。特别是当按较大值进行下采样时,输出采样率可能不是表示延迟的糟糕选择,与上采样和输入采样率类似。
| s | swr上下文 | 
| base | 时基,其中返回的延迟将为: 
 | 
base单位。文件swresample.c第991行的定义。
由filter_frame()、main()、swr_convert_frame()、swr_next_pts()和write_audio_frame()引用。
| int swr_get_out_samples | ( | 结构SwrContext * | , _ | 
| 整数 | 样本中 | ||
| ) | 
如果使用输入样本的 in_samples 进行调用,则找到下一个 swr_convert 调用将输出的样本数量的上限。
这取决于内部状态,任何改变内部状态的行为(比如进一步的swr_convert()调用)都可能会改变swr_get_out_samples()对于相同数量的输入样本返回的样本数量。
| in_samples | 输入样本的数量。 | 
文件swresample.c第999行的定义。
| unsigned swresample_version | ( | 空白 | ) | 
返回LIBSWRESAMPLE_VERSION_INT常量。
这对于检查构建时 libswresample 是否与运行时版本相同很有用。
定义位于文件version.c的第 29行。
| const char* swresample_configuration | ( | 空白 | ) | 
| const char* swresample_license | ( | 空白 | ) | 
转换输入AVFrame中的样本并将其写入输出AVFrame。
输入和输出 AVFrame 必须设置 channel_layout、sample_rate 和 format。
如果输出AVFrame没有分配数据指针,则将调用av_frame_get_buffer()来设置 nb_samples 字段以分配帧。
输出AVFrame可以为 NULL 或分配的样本少于所需的样本。在这种情况下,任何未写入输出的剩余样本都将添加到内部 FIFO 缓冲区,以便在下次调用此函数或 swr_convert( )时返回。
如果转换采样率,内部重采样延迟缓冲区中可能会残留数据。swr_get_delay()告诉剩余样本的数量。要获取此数据作为输出,请使用 NULL 输入调用此函数或swr_convert() 。
如果SwrContext配置与输出和输入AVFrame设置不匹配,则不会进行转换,并且根据哪个AVFrame不匹配 AVERROR_OUTPUT_CHANGED、AVERROR_INPUT_CHANGED 或返回它们的按位或的结果。
文件swresample_frame.c第184行的定义。
使用 AVFrame 提供的信息配置或重新配置SwrContext 。
即使失败,原始重采样上下文也会重置。如果上下文打开,该函数会在内部调用swr_close() 。
定义位于文件swresample_frame.c第27行。
