FFmpeg使用教程

1、視頻轉換格式----將test.avi格式的軟件轉換為test.mp4

ffmpeg -i test.avi test.mp4

2、視頻截圖保存為圖片​​​​

ffmpeg -i inputfile.avi -r 1 -q:v 2 -f image2 image-%05d.jpg

-r:指定抽取的幀 即從視頻中每秒抽取圖片的數量 1代表每秒抽取一幀

-f:保存圖片使用的格式 可省略

Image-%05d.jpg:指定文件的輸出名字

3、截取與合併視頻

截取:​​​​​​​

ffmpeg -i 0005.mp4 -vcodec copy -acodec copy -ss 00:00:00 -to 00:00:100 d:/cutout1.mp4 -y -ss:指定從什麼時候開始

-t:指定需要截取多長時間

-i:指定輸入文件

截取視頻如果出現時間點不對,出現這種情況的原因是因為截取到的地方不是關鍵幀,如果項目中對時間要求比較精確的話,需要先將視頻將所有的幀提前轉換關鍵幀----將所有的幀編碼方式轉變為幀內編碼

具體操作:老版本:ffmpeg -i input -samep -intra output

-i:輸入視頻文件

-sameq :保持同樣的視頻質量

-intra :幀內編碼

output:輸出文件名

新版本:ffmpeg -i inputfile -strict -2 -qscale 0 -intra output.mp4​​​​​​​

合成:

ffmpeg -ss 00:00:00 -t 00:00:20 -i input.mp4 -vcodec copy output.mp4

ffmpeg -f concat -i list.txt -c copy concat.mp4

list.txt文件中的書寫方式:

file video1.mp4

file video2.mp4

4、給視頻添加水印​​​​​​​

ffmpeg -i xiaozheng.mp4 -i mark.png -filter_complex overlay test1.mp4

給視頻添加文字水印:

ffmpeg -i xiaozheng.mp4 -vf "drawtext=fontfile=simsunb.ttf: text='zhengqijia':x=100:y=10:fontsize=24:fontcolor=yellow:shadowy=2" drawtext.mp4

文字水印filter是drawtext simsunb.ttf:text=’zhengqijia’

x:y是顯示位置

fontsize:文字大小

fontcolor:文字顏色

​​​​​​給視頻添加圖片水印:

ffmpeg -i input.mp4 -vf "movie=mark.png[watermark];[in][watermark] overlay=10:10[out]" output.mp4


分享到:


相關文章: