Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

144.3. FFmpeg

http://ffmpeg.org/

Converting video and audio has never been so easy.

144.3.1. 安装

MacOS

		
brew install ffmpeg		
		
		

sudo apt-get install ffmpeg

144.3.2. 视频格式转换

		
$ ffmpeg -i input.mp4 output.avi	
		
		

144.3.2.1. m4v to mov

			
for i in *.m4v; do ffmpeg -y -i "$i" "${i%.*}.mov"; done			
			
			

144.3.3. 提取视频中的音频

		
ffmpeg -i input.mp4 -f mp3 output.mp3	
		
		

144.3.4. 添加字幕

		
ffmpeg -i input.mp4 -vf subtitles=caption.srt -y output.mp4		
		
		

144.3.5. 音频格式转换

144.3.5.1. mp3 转 wav

mp3 转 wav

			
ffmpeg -i input.mp3 -f wav output.wav
			
			

144.3.5.2. wav 转 mp3

wav 转 mp3

			
ffmpeg -i input.wav -f mp2 output.mp3
			
			

144.3.5.3. wav to pcm

			
ffmpeg -i input.wav -f s16be -ar 8000 -ac 1 -acodec pcm_s16be output.pcm		
			
			

144.3.5.4. pcm to wav

			
ffmpeg -i input.pcm -f s16be -ar 8000 -ac 2 -acodec pcm_s16be  output.wav
			
			

144.3.5.5. 批量把wav转mp3

			
#!/bin/bash

folder=/home/XXX

for file in $(find "$folder" -type f -iname "*.mp3")
do
    name=$(basename "$file" .mp3)
    dir=$(dirname "$file")
    echo ffmpeg -i "$file" -acodec pcm_s16le -ac 1 -ar 16000 "$dir"/"$name".wav
    ffmpeg -i "$file" -acodec pcm_s16le -ac 1 -ar 16000 "$dir"/"$name".wav

done		
			
			

144.3.5.6. 批量把pcm转wav

			
#!/bin/bash

folder=/home/XXX
mkdir "$folder"/out

for file in $(find "$folder" -type f -iname "*.pcm")
do
    name=$(basename "$file" .pcm)
    dir=$(dirname "$file")
    echo ffmpeg -f s16le -ar 16000 -ac 1 -acodec pcm_s16le -i "$file" "$dir"/out/"$name".wav
    ffmpeg -f s16le -ar 16000 -ac 1 -acodec pcm_s16le -i "$file" "$dir"/out/"$name".wav
done
			
			

144.3.5.7. AMR

Mp3 转 AMR

			
ffmpeg -i input.mp3 -ar 8000 -ab 12.2k -ac 1 output.amr