Audio file ffmpeg and ffplay command line usage notes

convert pcm to aac

ffmpeg -f s16le -ar 44100 -ac 2 -i output.pcm -c:a aac -b:a 66k -strict -2 output_new.aac

-f s16le: Indicates that the format of the input audio file is s16le (that is, 16-bit signed linear PCM format), and you can also use -f u16le to indicate 16-bit unsigned linear PCM format, or -f f32le to indicate 32-bit floating-point number format. It should be noted that the audio format of the input file should match the format specified in the FFmpeg command; :
-ar 44100indicates that the sampling rate of the input audio file is 44100Hz (that is, 44100 samples per second), and other sampling rates can also be set as required;
-ac 2: Indicates that the number of channels of the input audio file is 2 (two-channel), and other channels can also be set as required; : Indicates the input
-i output.pcmaudio file in PCM format, which conforms to the format specified above (s16le, 44100Hz , 2-channel);
-c:a aac: Indicates that the encoding format of the output audio file is AAC, and other audio encoding formats, such as MP3, can also be used. It should be noted that the output encoding format needs to be supported by the environment where the FFmpeg command is located, otherwise the corresponding codec library may need to be installed; :
-b:a 66kIndicates that the bit rate of the output audio file is 66 kbps, and other bit rates can also be set as required; :
-strict -2Indicates Strictly control the format of the output file and need to be used together with the output encoding format. Because some old versions of FFmpeg do not support certain audio encoding formats by default, it is necessary to cancel the strict control through this command, otherwise encoding may fail; : Indicates the file name
output_new.aacand storage path of the output audio file in AAC format.
It should be noted that the parameters -ar, -ac and -b:a in the above command are optional. If not specified, the default value is the sampling rate and number of channels of the input file and the default bit rate of the encoder. In actual use, appropriate settings should be made according to the needs. In addition, if you need to convert audio files in PCM format to other formats, such as WAV, MP3, etc., you can modify the corresponding parameters and encoders.

Convert pcm to g711a

ffmpeg -f s16le -ar 44100 -ac 2 -i input.pcm -codec:a pcm_alaw -f alaw output.g711a

-f s16le: Specifies that the audio data format of the input file is s16le, that is, the signed linear PCM format using 2 bytes for each sample point. You can also use -f u16le to specify unsigned PCM format, or -f f32le to specify 32-bit floating point PCM format. It should be noted that if the input audio data format is not s16le (or u16le, f32le), it needs to be specified according to the actual situation.
-ar 44100: The sampling rate of the specified input file is 44100Hz, that is, 44100 samples per second;
-ac 2: The specified input file is dual-channel (that is, there are two channels on the left and right), or you can use -ac 1 to specify mono-channel; :
-i input.pcmSpecify the input File path and file name;
-codec:a pcm_alaw: Specifies that the encoder of the output audio stream is a PCM encoder in a-law format, or a PCM encoder in u-law format, and the corresponding command is -codec:a pcm_mulaw; : Specifies the output
-f alawfile The audio encapsulation format is alaw, an audio encoding format commonly used in telephone systems;
output.g711a: Specify the output file path and file name.
It should be noted that no audio compression is performed in this command, and the output audio file is a lossless G.711a format audio file, and the file size may be relatively large. If audio compression is required, other audio codecs can be used and corresponding audio bit rates can be set for conversion. In addition, in order to ensure the quality of audio conversion, it is recommended to check whether the sampling bit depth, sampling rate, number of channels and other information of the input file are correct before converting the file, and try to avoid non-audio data in the input file.

Play g711a audio with ffplay

ffplay -f alaw -ar 44100 -ac 2 -acodec pcm_alaw -b:a 66k output.g711a

ffplay: FFmpeg’s built-in audio and video player command;
-f alaw: Specify the audio encoding format adopted by the input audio file as alaw, that is, a-law format; :
-ar 44100Specify the sampling rate of the input audio file as 44100Hz, that is, 44100 samples per second;
-ac 2: Specifies that the input audio file is dual-channel (that is, there are two channels on the left and right), or you can use -ac 1 to specify monophonic; : Specify the
-acodec pcm_alawaudio decoder to decode the audio file in G.711a format into an audio file in PCM format , for subsequent players to play. It should be noted that pcm_alaw means to use the PCM encoder in a-law format, and the PCM encoder in u-law format can also be used. The corresponding command is -acodec pcm_mulaw; : Specify the input audio bit rate when the player reads the
-b:a 66kfile 66 kbps, and other audio bit rates can be set as required;
output.g711a: Specify the path and file name of the G.711a format audio file to be played.
It should be noted that if the player cannot play the audio file in G.711a format correctly, it may be because the player does not support the format. Also, if there are known noise issues when playing, it could be due to a mismatch between the input and output audio formats, or an issue with the audio file itself. You can try to modify the parameters of the input and output files to get a better playback effect.

Guess you like

Origin blog.csdn.net/qq_51282224/article/details/131131989