ffmpeg视频合并、添加背景音乐命令整理

1、视频合并

第一步将output1.mp4文件转成output1.ts

ffmpeg -i /storage/emulated/0/Movies/output1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb /storage/emulated/0/Movies/output1.ts

第二步将output1.ts和output2.ts合并为Cam01.mp4

ffmpeg -y -f concat -safe 0 -i /storage/emulated/0/Movies/list.txt -c copy /storage/emulated/0/Movies/Cam01.mp4

list.text内容如下:

file '/storage/emulated/0/Movies/output1.ts'

file '/storage/emulated/0/Movies/output2.ts'


2、视频编辑 比如从第5秒的地方开始,往后截取10秒钟

ffmpeg -ss 5 -t 10 -i /storage/emulated/0/Movies/output1.mp4 /storage/emulated/0/Movies/output2.mp4


3、视频加背景音乐

ffmpeg -y -i Cam01.mp4 -i jj01.mp3 -filter_complex [0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];[a0][a1]amix=inputs=2:duration=first[aout] -map [aout] -ac 2 -c:v copy -map 0:v:0 -preset superfast   result.mp4


4、视频加速

ffmpeg -i result.mp4 -vf setpts=PTS/2 -af atempo=2 result01.mp4


5、音频剪辑

ffmpeg -y -i 124.mp3 -vn -acodec copy -ss 00:00:00 -t 00:01:32 output.mp3


6、调整视频宽高

ffmpeg -i result.mp4 -vf scale=320*240 result02.mp4


7.16:9转9:16


ffmpeg -i input.mp4 -lavfi "[0:v]scale=256/81*iw:256/81*ih,boxblur=luma_radius=min(h\,w)/40:luma_power=3:chroma_radius=min(cw\,ch)/40:chroma_power=1[bg];[bg][0:v]overlay=(W-w)/2:(H-h)/2,setsar=1,crop=w=iw*81/256"  output.mp4


8.9:16转16:9


ffmpeg -i input.mp4 -lavfi '[0:v]scale=ih*16/9:-1,boxblur=luma_radius=min(h\,w)/20:luma_power=1:chroma_radius=min(cw\,ch)/20:chroma_power=1[bg];[bg][0:v]overlay=(W-w)/2:(H-h)/2,crop=h=iw*9/16' -vb 800K output.mp4


9.设置视频比例


ffmpeg -i -y a.avi -aspect 16:9