ffmpeg连接合并拆分音频


If it is all m4a, then the problem is a bit more complex: m4a contains timecodes, which may or may not start at zero. The concat demuxer is notorious for not considering this. In broadcast we allways convert to raw PCM (or something else that has not timestamps), then concat, then create the final output format.
Along the lines of
ffmpeg -i file1,m4a -c:a pcm_s16le -f s16le file1.pcm ;
ffmpeg -i file2,m4a -c:a pcm_s16le -f s16le file2.pcm ;
cat file2.pcm >> file1.pcm ; 
ffmpeg -f s16le -i file1.pcm -c:a aac -b:a whatever -ac whatever output.m4a

https://stackoverflow.com/questions/48934906/ffmpeg-cannot-concatenate-m4a-files-with-c-copy-parameter

I just found out the error was due to the Stream #0, which is the cover art, and covers the actual audio track.
After removing the
cover artworks in all files, I was able to concatenate them. And the speed is quite fast : speed=1.92e+03x.


https://superuser.com/questions/1368180/concatenation-of-m4a-files-is-either-too-long-or-too-short
--------------
Concatenation of files is sometimes not very intuitive - this is due to the fact, that many formats contain timestamps, that may or may not start at zero, be continuous etc., depending on the creation and editing history of that file.

This is one of the reasons, why in the broadcast world formats rule, that can just be concatenated: MPEGTS (with the need to have an eye on continuity counters) or RAW (raw PCM resp. raw h.264).

If reencoding is an option I recommend you convert your original files to raw PCM, along the lines of

ffmpeg -i file1.m4a -c:a pcm_s16le -ac 2 -ar 48000 -f s16le file1.pcm
ffmpeg -i file2.m4a -c:a pcm_s16le -ac 2 -ar 48000 -f s16le file2.pcm

This will create 2 raw PCM files, with 2 channels (Stereo, -ac 2) each and a sample rate of 48KHz (-ar 48000)

You can now concatenate those files, e.g. via cat file2.pcm >> file1.pcm - this creates a new raw representation of the file with no timestamps, just the plain audio samples.

To reencode the result into AAC, you go along the lines of

ffmpeg -f s16le -ac 2 -ar 48000 -i file1.pcm -c:a aac -b:a 192K -ac 2 output.m4a

Let's break this down:

  • First I tell ffmpeg to open a file of format raw PCM (signed 16bit low endian -f s16le) containing 2 audio channels (-ac 2) of 48KHz sample rate (-ar 48000) and stored in file1.pcm (as usual with ffmpeg, the order of the parameters is important)
  • then to reencode with AAC (-c:a) and a bandwidth of 192Kbit/s (-ba:a) again in stereo (-ac 2)


http://ffmpeg.org/ffmpeg.html

https://clideo.com/merge-m4a


深入挖掘 M4A 和常见问题解答
问: .MP4 和 .M4A 有什么区别?
答: .MP4 与 .M4A:.m4a 简而言之,只能包含 MPEG 4 音频,是用于表示音频文件的文件扩展名。但是 .mp4 可能包含也可能不包含 MPEG 4 音频,并且可以用于 MPEG 4 视频文件。.m4a 文件扩展名用于包含有损 AAC 或其自身无损 ALAC 格式音频数据的 MP4 容器。标准中的 m4a 文件用于 iTunes DRM 不受保护的内容,而 .mp4 或 .m4v 文件用于受 iTunes DRM 复制保护的内容。

问: M4A 音频文件和 AAC 音频文件之间是否有区别,或者它们完全相同但文件扩展名不同?
A: AAC是一种音频编码方案,而M4A只是一种文件扩展名。AAC 编码的音频可以具有 AAC、MP4 和 M4A 扩展名。

问:我的 iTunes 库中的一些音乐文件是 M4A 与 M4P。这是为什么?
答:这些文件中包含数字版权管理以限制用户共享文件的能力。DRM 总是在 M4P 文件上出售,而 M4A 文件没有限制,并且没有 DRM。Apple M4P 文件以 128 比特率出售,这远低于速度为 256 kbps 的 M4A 文件所需的比特率。


linux命令实现音频格式转换和拼接的方法

 2020-10-19阅读 2740
安装FFmpeg flac

eric@ray:~$ sudo apt install FFmpeg flac
安装lame faac

eric@ray:~$ sudo apt install lame faac
将一个后缀为.ape格式的视频转换成m4a(mp4)格式

1、首先用ffmpeg命令或者flac 命令将它转换成mav格式,再用lame将wav转换成mp4格式

eric@ray:~/Music$ ffmpeg -i Gracie-Theme.ape Gracie-Theme.wav

##或者

eric@ray:~/Music$ flac -d Gracie-Theme.flac Gracie-Theme.wav
2、再使用lame命令 压缩成MP3

##使用lame命令:使用VBR动态码率压缩,0表示质量最高,9表示质量最低,默认为4

eric@ray:~/Music$ lame -v Gracie-Theme.wav

##或者使用faac编码得到m4a(mp4)、mp3格式文件:100表示质量最高 100% 

eric@ray:~/Music$ faac -w -q 100 Gracie-Theme.wav -o Gracie-Theme.mp4
3、也可以使用ffmpeg压缩得到m4a格式:

#这里使用的是ffmpeg内置的aac编码起,设置码率为固定的320k

eric@ray:~/Music$ ffmpeg -i Gracie-Theme.wav -strict experimental -c:a aac -b:a 320k Gracie-Theme.m4a

#还可以使用ffmpeg将解压和压缩为一条命令:-map_metadata 表示保留歌曲元数据,即名称、演唱者等

eric@ray:~/Music$ ffmpeg -i Gracie-Theme.flac -ab 320k -map_metadata 0 Gracie-Theme.m4a
4、批量脚本

#!/bin/bash

for FILE in *.ape;
do
ffmpeg -i "$FILE" temp.wav;
lame -b 320 temp.wav "${FILE%.*}.mp3";
rm temp.wav
done
对于一个ape/flac文件包含多首歌曲

这种情况,通常会有一个cue文件,这个文件中包含这个ape/flac文件的专辑名称、演唱者名称、还有每首歌曲的名称、时间范围。可以先用上面的方法将整个文件转化为Mp3格式之后,再用mp3splt工具进行分割。

将cue文件分割为mp3:

eric@ray:~/Music$mp3splt -c song.cue -o @n.@t song.mp3
常用参数:

@a:歌手名称

@b:专辑名称

@t:歌曲标题

@n:音轨序号

音频合并

#音频合并(两个音频重叠)

eric@ray:~/Music$ffmpeg -i first.mp3 -i second.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f mp3 third.mp3

#两个音频拼接

eric@ray:~/Music$ffmpeg -i d1.mp3 -i d2.mp3 -filter_complex '[0:0] [1:0] concat=n=2:v=0:a=1 [a]' -map [a] j5.mp3

#三个音频拼接

eric@ray:~/Music$ffmpeg -i 片头.wav -i 内容.WAV -i 片尾.wav -filter_complex '[0:0] [1:0] [2:0] concat=n=3:v=0:a=1 [a]' -map [a] 合成.wav
参考资料

FFmpeg and AAC Encoding Guide https://trac.ffmpeg.org/wiki/Encode/AAC 

以上这篇linux命令实现音频格式转换和拼接的方法就是小编分享给大家的全部内容了,希望能给大家一个参考。



1 多个mp3文件合并成一个mp3文件

一种方法是连接到一起
ffmpeg64.exe -i "concat:123.mp3|124.mp3" -acodec copy output.mp3
解释:-i代表输入参数
          contact:123.mp3|124.mp3代表着需要连接到一起的音频文件
           -acodec copy output.mp3 重新编码并复制到新文件中
另一种方法是混合到一起
ffmpeg64.exe -i 124.mp3 -i 123.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f mp3 remix.mp3
解释:-i代表输入参数
           -filter_complex ffmpeg滤镜功能,非常强大,详细请查看文档
           amix是混合多个音频到单个音频输出
           inputs=2代表是2个音频文件,如果更多则代表对应数字
           duration 确定最终输出文件的长度
               longest(最长)|shortest(最短)|first(第一个文件)
            dropout_transition
The transition time, in seconds, for volume renormalization when an input stream ends. The default value is 2 seconds.
            -f mp3  输出文件格式
 
2 音频文件截取指定时间部分
 
ffmpeg64.exe -i 124.mp3 -vn -acodec copy -ss 00:00:00 -t 00:01:32 output.mp3
解释:-i代表输入参数
          -acodec copy output.mp3 重新编码并复制到新文件中
           -ss 开始截取的时间点
           -t 截取音频时间长度
           
3 音频文件格式转换
 
ffmpeg64.exe -i null.ape -ar 44100 -ac 2 -ab 16k -vol 50 -f mp3 null.mp3
解释:-i代表输入参数
           -acodec aac(音频编码用AAC) 
          -ar 设置音频采样频率
          -ac  设置音频通道数
          -ab 设定声音比特率
           -vol <百分比> 设定音量
 
转自:http://blog.sina.com.cn/s/blog_50e610900102vkab.html
阅读量: 579
发布于:
修改于: