The Method of Audio Format Conversion and Splicing Based on linux Command

  • 2021-07-03 01:09:38
  • OfStack

Installing FFmpeg flac


eric@ray:~$ sudo apt install FFmpeg flac

Installing lame faac


eric@ray:~$ sudo apt install lame faac

Convert 1 video with the suffix. ape to m4a (mp4)

1. First, convert it to mav format with ffmpeg command or flac command, and then convert wav to mp4 format with lame


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

## Or 

eric@ray:~/Music$ flac -d Gracie-Theme.flac Gracie-Theme.wav

2. Compress into MP3 by using lame command


## Use lame Command: Use the VBR Dynamic rate compression, 0 Indicates the highest quality, 9 Indicates the lowest quality, and the default is 4

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

## Or use faac Encoding obtains m4a(mp4) , mp3 Format file: 100 Indicates the highest quality  100% 

eric@ray:~/Music$ faac -w -q 100 Gracie-Theme.wav -o Gracie-Theme.mp4

3. You can also use ffmpeg compression to get m4a format:


# What is used here is ffmpeg Built-in aac From coding, the code rate is set to be fixed 320k

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

# You can also use the ffmpeg Decompress and compress into 1 Commands :-map_metadata  Indicates that the song metadata is preserved, that is, the name, singer, and so on 

eric@ray:~/Music$ ffmpeg -i Gracie-Theme.flac -ab 320k -map_metadata 0 Gracie-Theme.m4a

4. Batch scripts


#!/bin/bash

for FILE in *.ape;
do
ffmpeg -i "$FILE" temp.wav;
lame -b 320 temp.wav "${FILE%.*}.mp3";
rm temp.wav
done

For 1 ape/flac file containing more than one song

In this case, there is usually an cue file, which contains the album name and singer name of this ape/flac file, as well as the name and time range of each song. You can first use the above method to convert the entire file into Mp3 format, and then use mp3splt tool for segmentation.

Split the cue file into mp3:


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

Common parameters:

@ a: Singer name

@ b: Album name

@ t: Song title

@ n: Audio track serial number

Audio combination


# Audio merge (two audio overlaps) 

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

# Two audio splices 

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

#3 Audio mosaic 

eric@ray:~/Music$ffmpeg -i  Title .wav -i  Content .WAV -i  End of the film .wav -filter_complex '[0:0] [1:0] [2:0] concat=n=3:v=0:a=1 [a]' -map [a]  Synthesis .wav

References

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


Related articles: