添加音轨
ffmpeg -i input.mp4 -i cc.MP3 -c:v copy -c:a aac -map 0:v -map 1:a -shortest output.mp4
并行合并多个视频
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a][3:v][3:a]concat=n=4:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v h264_qsv -c:a aac output.mp4
混音以及调节音量
ffmpeg -i input.mp4 -i cc.MP3 -i bgmusic.mp3 -filter_complex "[1:a]volume=2.0[a];[2:a]volume=0.3[b];[a][b]amix=inputs=2:duration=shortest:dropout_transition=2[outa]" -map 0:v -map "[outa]" -c:v copy -c:a aac -shortest output.mp4
按长的来
ffmpeg -i input.mp4 -i cc.MP3 -i bgmusic.mp3 -filter_complex "[1:a]volume=2.0[a];[2:a]volume=0.3[b];[a][b]amix=inputs=2:duration=longest:dropout_transition=2[outa]" -map 0:v -map "[outa]" -c:v copy -c:a aac -shortest output.mp4
并行合并多个视频(去音轨)
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -filter_complex "[0:v][1:v][2:v][3:v]concat=n=4:v=1:a=0[outv]" -map "[outv]" -c:v h264_qsv -q:v 19 output.mp4
横屏转为竖屏(竖屏改尺寸也可以用)
ffmpeg -i input.mp4 -vf "scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black" -c:v libx264 -c:a copy output.mp4
裁剪合并视频
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v0];[1:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v1];[2:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v2];[3:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v3];[v0][0:a][v1][1:a][v2][2:a][v3][3:a]concat=n=4:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libx264 -c:a copy output.mp4
给视频添加水印(两种都可以用)
坐标
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0:v][1:v]overlay=0:0" -c:v libx264 -c:a copy output.mp4
ffmpeg -i input.mp4 -vf "movie=watermark.png[watermark1];[in][watermark1]overlay=0:0" -y output.mp4
添加更改尺寸以及添加水印
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v];[v][1:v]overlay=0:0" -c:v libx264 -c:a copy output.mp4
添加字幕
ffmpeg -i input.mp4 -vf "subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=50" -c:v h264_qsv -q:v 19 -c:a copy -t 50 test.mp4
连续指令
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v];[v][1:v]overlay=0:0" -c:v libx264 -c:a copy -f nut - | ffmpeg -y -i - -vf "subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=50" -c:v h264_qsv -q:v 19 -c:a copy -t 50 output.mp4
连续指令并合成音轨
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v];[v][1:v]overlay=0:0" -c:v libx264 -c:a copy -f nut - | ffmpeg -y -i - -i cc.MP3 -vf "subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=50" -c:v h264_qsv -q:v 19 -c:a copy -map 0:v -map 0:a -map 1:a -t 50 output.mp4
推荐
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v];[v][1:v]overlay=0:0" -c:v libx264 -c:a copy -f nut - | ffmpeg -y -i - -i cc.MP3 -vf "subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=50" -c:v h264_qsv -q:v 19 -c:a copy -map 0:v -map 1:a -t 87 output.mp4
终极指令
(1)
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v0];[1:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v1];[2:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v2];[3:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v3];[v0][0:a][v1][1:a][v2][2:a][v3][3:a]concat=n=4:v=1:a=1[outv][outa];[outv][4:v]overlay=0:0[out]" -map "[out]" -map "[outa]" -c:v libx264 -c:a aac -movflags +faststart -f nut - | ffmpeg -y -i - -i cc.MP3 -vf "subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=100" -c:v h264_qsv -q:v 19 -c:a copy -map 0:v -map 1:a -t 87 output.mp4
(2)推荐
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -i watermark.png -filter_complex "[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v0];[1:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v1];[2:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v2];[3:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v3];[v0][0:a][v1][1:a][v2][2:a][v3][3:a]concat=n=4:v=1:a=1[outv][outa];[outv][4:v]overlay=0:0[out]" -map "[out]" -map "[outa]" -c:v libx264 -c:a aac -movflags +faststart -f nut - | ffmpeg -y -i - -i cc.MP3 -i bgmusic.mp3 -filter_complex "[0:v]subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=100'[v];[1:a]volume=2.0[a];[2:a]volume=0.3[b];[a][b]amix=inputs=2:duration=longest:dropout_transition=2[outa]" -map "[v]" -map "[outa]" -c:v h264_qsv -q:v 19 -c:a aac -t 80 output.mp4
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -i video4.mp4 -i watermark.png -filter_complex "
[0:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v0];[1:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v1];[2:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v2];[3:v]scale=720:-1,pad=720:1280:(720-iw)/2:(1280-ih)/2:black[v3];
[v0][0:a][v1][1:a][v2][2:a][v3][3:a]concat=n=4:v=1:a=1[outv][outa];[outv][4:v]overlay=0:0[out]" -map "[out]" -map "[outa]" -c:v libx264 -c:a aac -movflags +faststart -f nut - | ffmpeg -y -i - -i cc.MP3 -i bgmusic.mp3 -filter_complex "[0:v]subtitles=src.srt:force_style='fontname=黑体,fontsize=8,primarycolour=&Hffffff,OutlineColour=&h00222222,outline=1,Alignment=2,MarginV=100'[v];[1:a]volume=2.0[a];[2:a]volume=0.3[b];[a][b]amix=inputs=2:duration=longest:dropout_transition=2[outa]" -map "[v]" -map "[outa]" -c:v h264_qsv -q:v 19 -c:a aac -t 80 output.mp4
# 更改这样的尺寸合并不会错
ffmpeg -i input.mp4 -vf "scale=720:1280,setsar=1:1" output.mp4
# 设置立体声以及采样频率为 44100HZ
ffmpeg -i input1.mp4 -i music/cc.MP3 -i bgmusic.mp3 -filter_complex "[1:a]volume=2.0[a];[2:a]volume=0.3[b];[a][b]amix=inputs=2:duration=longest:dropout_transition=2[outa]" -map 0:v -map "[outa]" -c:v copy -c:a aac -ar 44100 -ac 2 -shortest output.mp4
#更改尺寸以及采样频率 帧率为30
ffmpeg -i video2.mp4 -vf "scale=720:1280,fps=30" -c:v libx264 -preset medium -crf 23 -c:a copy -ar 44100 -ac 2 output.mp4
合并两个相同的视频(光速合并)
ffmpeg -f concat -safe 0 -i input.txt -c copy output.mp4
input.txt写法:
file 'video1.mp4'
file 'video2.mp4'
剪辑横版视频
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=720:1280" -c:a copy output.mp4
# 转竖版加速
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=720:1280" -c:v h264_qsv -c:a aac output.mp4
把视频切割成1分钟
ffmpeg -i input.mp4 -c copy -f segment -segment_time 60 -reset_timestamps 1 output_%03d.mp4
转竖版并切割1分钟
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=720:1280" -c:v h264_qsv -c:a aac output.mp4 && ffmpeg -i output.mp4 -c copy -f segment -segment_time 60 -reset_timestamps 1 video/output_%03d.mp4
解决windows添加文字水印问题
ffmpeg -y -i input.mp4 -vf "drawtext=text='总裁三代单传,你大爷的':x=(w-text_w)/2:y=200:fontsize=50:fontcolor=white:borderw=2:bordercolor=black:fontfile=方正粗黑宋简体,drawtext=text='没想到她生了个孩子':x=(w-text_w)/2:y=250:fontsize=50:fontcolor=yellow:borderw=2:bordercolor=black:fontfile=方正粗黑宋简体,drawtext=text='老爷子放话:给我死劲宠':x=(w-text_w)/2:y=300:fontsize=50:fontcolor=yellow:borderw=2:bordercolor=black:fontfile=方正粗黑宋简体" -c:a copy -t 20 output1.mp4
*** fontfile如果要加载字体,必须fontfile='yhct.ttf',加引号并且不能用中文
标签:map,常用,操作命令,1280,ih,mp4,720,ffmpeg
From: https://www.cnblogs.com/wukai66/p/17509621.html