SciTech-AV-Audio-DAP(Digital Audio Processing)-ffmpeg -AMR录音文件剪切+格式转换+Normalization音量规范化
AMR录音文件的剪切和格式转换
- 剪切+格式转换:
ffmpeg -i evidence.amr -ss 01:10 -to 04:10 -f mp3 sample.mp3
ffmpeg -i x.mp3 -ss 01:14 -to 01:27 -f mp3 sample.mp3 - FFmpeg音频 格式转换
- ffmpeg做 8000hz采样率,单声道,每个采样样本8bit 这种转换只要:
ffmpeg -i in.mp3 -acodec pcm_s8 -ac 1 -ar 8000 -vn out.wav - mplayer可以用mencoder,对wav的细节处理也要间接用ffmpeg
mencoder in.mp3 −oac lavc -lavcopts acodec=pcm_s8:o=ac=1,ar=8000 -of lavf -o out.wav
- ffmpeg做 8000hz采样率,单声道,每个采样样本8bit 这种转换只要:
- 音量检测和Normalization:
- 音量采样、离散统计检测:
ffmpeg -i sample.mp3 -filter:a volumedetect -f null /dev/null 2>>input.log 1>>input.log
grep 'volumedetect' input.log
- Loudness Normalization
ffmpeg -i sample.mp3 -filter:a loudnorm norm.mp3
- 音量采样、离散统计检测:
音频Normalization:统一音量音效
https://trac.ffmpeg.org/wiki/AudioVolume
Audio Volume Manipulation
Changing volume: you may use FFmpeg's volume audio filter.
If we want our volume to be
# half of the input volume
ffmpeg -i input.wav -filter:a "volume=0.5" output.wav
# 150% of current volume
ffmpeg -i input.wav -filter:a "volume=1.5" output.wav
# To **reduce the volume**, use a negative value:
ffmpeg -i input.wav -filter:a "volume=-5dB" output.wav
# You can also use decibel measures. To **increase the volume by 10dB**:
`ffmpeg -i input.wav -filter:a "volume=10dB" output.wav`
Note: the volume filter only adjusts the volume. It does not set the volume. To set or otherwise normalize the volume of a stream, see the sections below.
Peak and RMSNormalization
To normalize the volume to a given peak or RMS level,
the file first has to be analyzed using thevolumedetectfilter,
doc: https://ffmpeg.org/ffmpeg-filters.html#volumedetect
ffmpeg -i input.wav -filter:a volumedetect -f null /dev/null 2>>input.log 1>>input.log
Read the output values from the command line log from file:input.log:[Parsed_volumedetect_0 @ 0x30000a7490] n_samples: 96000
[Parsed_volumedetect_0 @ 0x30000a7490] mean_volume: -28.3 dB
[Parsed_volumedetect_0 @ 0x30000a7490] max_volume: -7.5 dB
[Parsed_volumedetect_0 @ 0x30000a7490] histogram_7db: 1
[Parsed_volumedetect_0 @ 0x30000a7490] histogram_8db: 4
[Parsed_volumedetect_0 @ 0x30000a7490] histogram_9db: 16
[Parsed_volumedetect_0 @ 0x30000a7490] histogram_10db: 43
[Parsed_volumedetect_0 @ 0x30000a7490] histogram_11db: 131
Here is an excerpt of the output:
mean_volume: -27 dB
max_volume: -4 dB
histogram_4db: 6
histogram_5db: 62
histogram_6db: 286
histogram_7db: 1042
histogram_8db: 2551
histogram_9db: 4609
histogram_10db: 8409
It means that:
- The
mean square energyis approximately-27dB( or10^-2.7). - The
largest sampleis at-4dB, ormore preciselybetween-4dBand-5dB. - There are 6 samples at
-4dB, 62 at-5dB, 286 at-6dB, etc.
In other words,
raising the volume by+4dBdoes not cause anyclipping,
raising it by+5dBcausesclippingfor6 samples, etc..
then calculate the required offset, and use the volume filter as shown above.
- The
LoudnessNormalization
If you want to normalize the (perceived) loudness of the file, use theloudnormfilter,
doc: https://ffmpeg.org/ffmpeg-filters.html#loudnorm
which implements theEBU R128algorithm:
ffmpeg -i input.wav -filter:a loudnorm output.wav
This is recommended for most applications, as it will lead to a more uniform loudness level,
compared to simple peak-based normalization. However, it is recommended to run the normalization withtwopasses,- extracting the measured values from the first run,
- then using the values in a second run with
linear normalizationenabled.
See theloudnormfilterdocumentationfor more.
Automatization with
ffmpeg-normalize
To automate thenormalization processeswith ffmpeg without having tomanually perform two passes,
and run normalization on multiple files (including video), you can also use the ffmpeg-normalize Python program viapip install ffmpeg-normalize. The script defaults to EBU R128 normalization with two passes, but peak and RMS normalization are also supported.
For details, runffmpeg-normalize -hor see theREADMEfile.
FFmpeg CommandLine Args. and Params.
FFmpegAudio options:
-aframes number **set the number of audio frames to output**
-aq quality set audio quality (codec-specific)
-ar rate **set audio sampling rate (in Hz)**
-ac channels **set number of audio channels**
-an **disable audio**
-acodec codec **force audio codec** ('copy' to copy stream)
-ab bitrate **audio bitrate (please use -b:a)**
-af filter_graph **set audio filters**
FFmpegTime Duration
FFmpeg时间段( time duration )格式,两种:
- [-][:]:[....]
HH 小时, MM 分钟(最大两位数), SS 秒(最多两位数),
m 小数秒(高精度, 十进制); - [-]<S>+[.<m>...]
S 秒数, m 作小数秒(高精度, 十进制);;
上两种duration, 都可选前加-指示negative duration.
例如:
-13.567: **negative** 13.567 seconds
12:03:45: 12hours 03minutes 45 seconds
23.189: 23.189 seconds
00:01:00: 60 seconds
60: 60 seconds
FFmpegGlobal options
affect whole program instead of just one file:
-loglevel loglevel set logging level-v loglevel **set logging level**-report generate a report-max_alloc bytes **set maximum size of a single allocated block**-y **overwrite output files**-n never overwrite output files-ignore_unknown Ignore unknown stream types-filter_threads **number of non-complex filter threads**-filter_complex_threads **number of threads for -filter_complex**-stats print progress report during encoding-max_error_rate maximum error rate ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.-frames[:stream_specifier] framecount (output,per-stream)
指定产出帧数: 设置产出视频的帧数 framecount .-f fmt (input/output), 指定文件格式:- 导入:会自动检测导入格式;
- 产出:文件扩展名自动推导产出格式 ( 因此这个 -f fmt 选项只在必要时使用. )
- FFmpeg 支持的所有 fmt 格式可以查看执行:
ffmpeg -formats
-ss position (input/output), 指定时间起点:- 在
-i参数的前面是作为导入设置, 从导入文件快进到指定position.
注️意:- 多数文件不真正支持seek, ffmpeg 会快进到 position 之前
最接近的seek point. - 转码(
transcoding)时并启用选项-accurate_seek(默认), 则解码并丢弃 前置seek point 和 position 之间的帧. - 流复制(
stream copy) 时并启用选项-noaccurate_seek(默认), 则保留seek point 和 position 之间的帧.
- 多数文件不真正支持seek, ffmpeg 会快进到 position 之前
- 在
-i参数的后面是作为产出选项(放在 output url 之前);
解码读入文件并丢弃导入, 直到产出流的 timestamp 到达这个指定的 position.
- 在
-sseof position (input/output):
类似 "-ss" 选项,但时间点相对于eof(end of file). 0 表示 EOF, 负数表示文件的stream上.-to position (input/output), 指定时间终点.- 在 写产出文件 / 读导入文件
到达指定时间终点 position后停止. ( ffmpeg Time duration 格式) -to和-t两个选项只能两选一,且-t的优先级更高.
- 在 写产出文件 / 读导入文件
-t duration (input/output), 指定时长.- 在 "-i" 的前面,作为导入设置, 指定只从导入文件读取的数据时间长度.
- 在 "-i" 的后面(output url前),作为产出设置, 指定只写指定时长的数据,就停止.
-to和-t两个选项只能两选一,且-t的优先级更高。
-fs limit_size (output), Set thefile size limit, expressedin bytes.
No further chunk of bytes is writtenafterthe limit is exceeded.
Thesize of the output fileisslightly morethanthe requested file size.-itsoffset offset (input), 指定导入时间偏移.offset为ffmpeg time duration 格式
offset被添加到导入文件的timestamps(时间戳).
指定positive offset表示 streams 被 delayed 到指定offset的时间.-timestamp date (output), 指定录制时间戳
在 container(数据容器, 输出stream到存储的格式容器)上 设置录制timestamp.
FFmpegPer-file main options:
-f fmt **force format**
-c codec **codec name**
-codec codec codec name
-pre preset preset name
-map_metadata outfile[,metadata]:infile[,metadata] **set metadata information of outfile from infile**
-t duration **record or transcode "duration" seconds of audio/video**
-to time_stop **record or transcode stop time**
-fs limit_size **set the limit file size in bytes**
-ss time_off **set the start time offset**
-sseof time_off **set the start time offset relative to EOF**
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp ('now' to set the current time)
-metadata string=string **add metadata**
-program title=string:st=number... add program with specified streams
-target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad audio pad
-frames number **set the number of frames to output**
-filter filter_graph **set stream filtergraph**
-filter_script filename **read stream filtergraph description from a file**
-reinit_filter **reinit filtergraph on input parameter changes**
-discard discard
-disposition disposition
FFmpeg常用到PCM格式
DE s16be PCM signed 16-bit big-endian
DE s16le PCM signed 16-bit little-endian
DE s24be PCM signed 24-bit big-endian
DE s24le PCM signed 24-bit little-endian
DE s32be PCM signed 32-bit big-endian
DE s32le PCM signed 32-bit little-endian
DE s8 PCM signed 8-bit
DE f32be PCM 32-bit floating-point big-endian
DE f32le PCM 32-bit floating-point little-endian
DE f64be PCM 64-bit floating-point big-endian
DE f64le PCM 64-bit floating-point little-endian
DE mulaw PCM mu-law
DE u16be PCM unsigned 16-bit big-endian
DE u16le PCM unsigned 16-bit little-endian
DE u24be PCM unsigned 24-bit big-endian
DE u24le PCM unsigned 24-bit little-endian
DE u32be PCM unsigned 32-bit big-endian
DE u32le PCM unsigned 32-bit little-endian
DE u8 PCM unsigned 8-bit
ffmpeg 的解码编码格式
SciTech-AV-Audio-DAP(Digital Audio Processing)-ffmpeg -AMR录音文件剪切+格式转换+Normalization音量规范化的更多相关文章
- FFmpeg学习4:音频格式转换
前段时间,在学习试用FFmpeg播放音频的时候总是有杂音,网上的很多教程是基于之前版本的FFmpeg的,而新的FFmepg3中audio增加了平面(planar)格式,而SDL播放音频是不支持平面格式 ...
- 史林枫:C#.NET利用ffmpeg操作视频实战(格式转换,加水印 一步到位)
ffmpeg.exe是大名鼎鼎的视频处理软件,以命令行参数形式运行.网上也有很多关于ffmpeg的资料介绍.但是在用C#做实际开发时,却遇到了几个问题及注意事项,比如如何无损处理视频?如何在转换格式的 ...
- java使用ffmpeg和mencoder做视频格式转换
首发:个人博客,持续更新和纠错 主要使用技术:1)FFmpeg,用于主流格式之间的转换,例如AVI,MP4,FLV等.2)MEncoder,用于奇葩格式转主流格式,例如RMVB转AVI.这样我们可以把 ...
- ffmpeg m3u8生成 剪辑及格式转换
使用 ffmpeg 工具, 生成 m3u8 文件 ffmpeg -re -i 03.ts -c copy -f hls -hls_base_url /Users/admin/Downloads/dow ...
- Building a Radio Listening Station to Decode Digital Audio & Police Dispatches
On April 7, 2017, residents in Dallas, Texas, woke to the sound of emergency sirens blaring all over ...
- Digital image processing(数字图像处理)
In computer science, digital image processing is the use of computer algorithms to perform image pro ...
- audio 基本功能实现(audio停止播放,audio如何静音,audio音量控制等)
audio最简单原始的播放.暂停.停止.静音.音量大小控制的功能,注意某些浏览器会有权限无法自动播放噢(video也会如此) <!doctype html> <html> &l ...
- Digital Image Processing 学习笔记3
第三章 灰度变换与空间滤波 3.1 背景知识 3.1.1 灰度变换和空间滤波基础 本章节所讨论的图像处理技术都是在空间域进行的.可以表示为下式: $$g(x, y) = T[f(x,y)]$$ 其中$ ...
- wave文件(*.wav)格式、PCM数据格式, goldwave 可以播放pcm raw audio
1. 音频简介 经常见到这样的描述: 44100HZ 16bit stereo 或者 22050HZ 8bit mono 等等. 44100HZ 16bit stereo: 每秒钟有 44100 次采 ...
- 信号处理的好书Digital Signal Processing - A Practical Guide for Engineers and Scientists
诚心给大家推荐一本讲信号处理的好书<Digital Signal Processing - A Practical Guide for Engineers and Scientists>[ ...
随机推荐
- grafana最新任意文件读取
一.Grafana简介 Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知.它主要有以下六大特点: 1.展示方式:快速灵活的客户端图表,面板插 ...
- Cline技术分析:基于Cline Prompt的File Tools MCP Server实现
我们将基于Cline prompt技术,构建一个基于MCP协议的文件工具服务器.我们将从任务定义开始,并在任务执行过程中探讨各个关键环节. 任务提示词定义 1. 访问[hub.gitmirror.co ...
- .NET AI从0开始入门 SemanticKernel 从基础到实践
引言 本教程将带你全面了解SemanticKernel,一款强大的AI开发工具包.以下内容基于实际代码示例,帮助你快速掌握使用技巧. 资源链接: 教程代码仓库:https://github.com/A ...
- 高度混淆和多层嵌套的JSP案例免杀思路
免责声明:本文所涉及的技术仅供学习和参考,严禁使用本文内容从事违法行为和未授权行为,如因个人原因造成不良后果,均由使用者本人负责,作者及本博客不承担任何责任. 01 分析特征 目前webshell检测 ...
- 5.3K star!硅基生命新纪元,这个开源数字人框架要火!
嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 "只需3分钟视频素材,就能打造专属数字分身!""开源免费商用, ...
- 解决MySQL 8.0 设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy require...
MySQL8.0下设置简单密码出现错误提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirem ...
- length与capacity
package javaBasic; public class DifferenceLengthCapacity { public static void main(String[] args) { ...
- Redundant Connection——LeetCode进阶路
原题链接https://leetcode.com/problems/redundant-connection/ 题目描述 In this problem, a tree is an undirecte ...
- 使用aqt安装Qt历史版本
首先是安装aqt: Windows 端 pip install -U pip pip install aqtinstall Mac端(可以用pip,也可以用brew) brew install aqt ...
- Openmv简明使用教程
Openmv简明使用教程 写在前面 本教程主要目的是指明学习资源在哪,可以怎么学,不教具体怎么使用,因为没有什么教程比官网上的教程更详细了,希望大家看完这篇文章后,能对如何学习使用Openmv有一个清 ...