关于ffmpeg工具对视频的处理,适用于windows和linux

在需要去官网上下载对应的平台的 static版本的ffmpeg库,解压之后,配置好环境变量,就可以进行使用了。

ffmprg -i test.flv   test.avi

ffplay test.avi

ffprobe test.avi


ffmpeg - h  进行查看帮助

1.
=========================
音视频的提取:
ffmpeg -i test.mp4  -vcodec copy -an test.mp4  //输出文件的格式要是一样的
ffmpeg -i test.flv -an test2.mp4               //在禁用的时候,可以进行格式的转化

-an禁用音频
-vcodec copy 拷贝视频流


提取音频为mp3
ffmpeg -i test.mp4 -vn -acodec copy test.aac  //这里输出格式,要先用ff[robe查看里面的流的格式,然后再确

定其格式
ffmpeg -i test.mp4 -vn test.mp3               //在禁用视频流的同时,把音频流的格式也进行转化了

-vn禁止视频流

2.
=========================
视频的截取

从1分钟一直截取到末尾
ffmpeg -i test.mp4 -ss 00:01:00 -vcodec copy -acodec copy out.mp4  -y //out.mp4存在,就进行覆盖

-ss 要开始操作的起始位子
-t  表示要截多少时间的视频
-to 表示要截取到那个时间
-y  如果存在就进行覆盖


从1分钟开始截取120秒  (-t 0:03:00,表示要截从开始持续三分钟的视频)
ffmpeg -i test.mp4 -ss 00:01:00 -t 120  -vcode copy -acodec copy out.mp4 -y

从1分钟开始截取到5分钟
ffmepg -i test.mp4 -ss 00:01:00 -to 00:02:00 -vcodec copy -acodec copy out.mp4 -y

3.
============================
对音视频的合并

合并h.264  和 aac 的文件进行合并成 mkv或者mp4 的文件(这个封装不涉及编码和解码,所以视频的清晰度不会发生

什么变化,主要就是对应的封装的协议大小的差异)
ffmpeg -i out.flv -i out.aac -vcodec copy -acodec copy mynote.mp4


4.
============================
对视频添加水印

x=0:y=0      左上角
x=0:y=h-th        左下角
x=w-tw:y=0       右上角
x=w-tw:y=h-th     右下角


ffmpeg -y -i test.flv -acodec copy -vcodec libx264 -vf "drawtext=fontfile=mysh.ttf:text='hello

world':x=20:y=20:fontsize=32:[email protected]" drawtext.mp4

加右上角
ffmpeg -y -i test.flv -acodec copy -vcodec libx264 -vf  "drawtext=fontfile=mysh.ttf:text='hello

world':x=w-tw:y=20:fontsize=32:[email protected]" drawtext.mp4

-vf   加水印的过滤
这里要在对应的文件下,准备好对应的字体比如微软雅黑
@0.7表示透明度

实现文件滚动的水印效果
ffmpeg -y -i 111.mp4 -acodec copy -vcodec libx264 -vf  "drawtext=fontfile=mysh.ttf:text='hello

world':x=w-t*10:y=20:fontsize=32:[email protected]" drawtext.mp4


ffmpeg -y -i test.flv -acodec copy -vcodec libx264 -vf  "drawtext=fontfile=mysh.ttf:text='hello

world':x=w-t*10:y=h-th-20:fontsize=32:[email protected]" drawtext.mp4

垂直滚动
ffmpeg -y -i 111.mp4 -acodec copy -vcodec libx264 -vf  "drawtext=fontfile=mysh.ttf:text='hello

world':x=20:y=h-t*100:fontsize=32:[email protected]" drawtext.mp4


//x=w-t*10:y=20 调这里就可以调位子,然后通过调时间t*10  到t*100就可以调滚动的快慢了


5.
===================================
添加图片水印

右上角的添加
ffmpeg.exe -i test.mp4 -i test.png -vcodec libx264 -filter_complex overlay=main_w-overlay_w-10:15 out.mp4

test.png要添加的图片水印
-filter_complex overlay 使用过滤器 叠加

main_w-overlay_w-10:15 为右上角的坐标


为左上角的坐标
ffmpeg.exe -i test.mp4 -i test.png -vcodec libx264 -filter_complex overlay=10:15 out.mp4

6.
=======================================
对视频进行批量水印处理
我这里使用的是python2版本

#coding:utf-8
import os
fpath="e:\\decode"#要批处理的视频文件存放在这
fpicture="e:\\test.png"#要打水印的图片位置
os.chdir(fpath)
for f in os.listdir(f):
    for fin in os.listdir(f):
        os.chdir(f)
        ftemp = fin.split(".mp4")
        fout  = ftemp[0]+"-out.mp4"
        os.system('ffmpeg.exe -i %s -i %s -vcodec libx264 -filter_complex overlay=overlay=main_w-overlay_w-10:15 %s' %(fin,fpicture,fout))
        fname = ftmpe[0]+".avi"
        os.rename(fout,fname)
        os.chdir(fpath)

猜你喜欢

转载自blog.csdn.net/lailaiquququ11/article/details/81452435