官方下载 http://www.ffmpeg.org/download.html
官方文档:http://ffmpeg.org/ffmpeg-all.html#Filtering
ffmpeg -i /dy/ivideo/1212121.mp4 -i /dy/12121.png -filter_complex overlay=W-w /dy/test/aai_39_2_8_1212123.mp4
ffmpeg -i /dy/ivideo/1212121.mp4 -i /dy/loading2023008.gif -filter_complex overlay=W-w /dy/test/aai_39_2_8_1212122.mp4
ffmpeg -i /dy/ivideo/1212121.mp4 -vf "movie=/dy/12121.png[watermark];[in][watermark] overlay=10:10[out]" /dy/aai_39_2_8_1212121.mp4
yum -y install autoconf automake build-essential \
libass-dev libfreetype6-dev libsdl2-dev libtheora-dev \
libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev \
libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev
yum update -qq && sudo apt-get -y install \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libgnutls28-dev \
libmp3lame-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
meson \
ninja-build \
pkg-config \
texinfo \
wget \
yasm \
zlib1g-dev
vim /etc/profile
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/ffmpeg/lib/
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/ffmpeg/ffmpeg-6.0/libavdevice
vi /etc/profile 编辑文件
export PATH=$PATH:/usr/local/ffmpeg/bin 在最后PATH添加环境变量
wq! 保存退出
source /ect/profile 设置生效
测试环境媒体处理服务器:
120.78.86.132(公)
172.18.168.225(私有)
要求:本地测试用 120.78.86.132
发到服务器上用 172.18.168.225(私有)
ffmpeg -i pinjiule.mp4 -vf ass=pinjiule.ass ouptut_chi.mp4
ffmpeg -hide_banner -y -i pinjiule.mp4 -vf drawtext=fontcolor=white:fontsize=40:fontfile=msyh.ttc:text='本地生活专为线下门店引流增客,提升餐饮门店的效益':x=0:y=100 -b:v 3000K video2.mp4
水印位置:(x,y)=(10,10)<=(left,top)距离左侧、顶部各10像素;
贴图水印时间显示
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2.mp4 -i C:\Users\heshiping\Desktop\videoDown\4.jpg -filter_complex overlay=x='if(between(t,15,30),150,NAN)':0 -threads 5 -preset ultrafast C:\Users\heshiping\Desktop\videoDown\15-30s.mp4
透明度
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2.mp4 -i C:\Users\heshiping\Desktop\videoDown\4.jpg -filter_complex "[1:v]colorkey=0x000000:0.6:1.0[ckout];[0:v][ckout]overlay=10:10[out]" -map "[out]" -threads 5 -preset ultrafast C:\Users\heshiping\Desktop\videoDown\xuanzhuans.mp4
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2.mp4 -i C:\Users\heshiping\Desktop\videoDown\4.jpg -filter_complex "[1:v]scale=100:100[wm];[0:v][wm]overlay=x='if(between(t,15,30),150,NAN)':50[HSP];[HSP]colorkey=0x000000:0.6:1.0[ckouts];[0:v][ckouts]overlay=150:50[out]" -map "[out]" -threads 5 -preset ultrafast C:\Users\heshiping\Desktop\videoDown\缩放透明度时间显示位置.mp4
合成
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2.mp4 -i C:\Users\heshiping\Desktop\videoDown\4.jpg -filter_complex "[1:v]scale=500:500[sf];[0:v][sf]overlay=x='if(between(t,10,30),300,NAN)':150[cc];[cc]colorkey=0x000000:0.6:1.0[tmd];[0:v][tmd]overlay=300:150[out]" -map "[out]" -threads 5 -preset ultrafast -max_muxing_queue_size 1024 C:\Users\heshiping\Desktop\videoDown\111.mp4
ffmpeg
-i C:\Users\heshiping\Desktop\videoDown\2.mp4
-i C:\Users\heshiping\Desktop\videoDown\4.jpg
-filter_complex "[1:v]scale=500:500[sf];[0:v][sf]overlay=x='if(between(t,10,30),300,NAN)':150[cc];[cc]colorkey=0x000000:0.6:1.0[tmd];[0:v][tmd]overlay=300:150[out]"
-map "[out]"
-threads 5 -preset ultrafast
C:\Users\heshiping\Desktop\videoDown\final.mp4
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2.mp4 -i C:\Users\heshiping\Desktop\videoDown\4.jpg -filter_complex "[1:v]scale=500:500[sf];[0:v][sf]overlay=x='if(between(t,10,30),300,NAN)':150[cc];[cc]colorkey=0x000000:0.6:1.0[tmd];[0:v][tmd]overlay=300:150[out]" -map "[out]" -threads 5 -preset ultrafast -max_muxing_queue_size 1024 C:\Users\heshiping\Desktop\videoDown\111.mp4
//垂直翻转
ffmpeg -i C:\\Users\\heshiping\\Desktop\\videoDown\\1.jpg -vf vflip -y C:\\Users\\heshiping\\Desktop\\videoDown\\1s.jpg
//水平翻转
ffmpeg -i C:\\Users\\heshiping\\Desktop\\videoDown\\66.webm -vf hflip -y C:\\Users\\heshiping\\Desktop\\videoDown\\66.webm
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\4.jpg -vf vflip -y C:\Users\heshiping\Desktop\videoDown\vflip.jpg
delogo 去除视频某处的logo。其实实现原理就是将给出区域进行高斯模糊处理。
delogo=x=0:y=0:w=100:h=77:band=10
x,y,w,h 构成一个Rect,band是模糊强度。
removelogo ,消除logo水印,和delogo 类似。
视频水印 透明度
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\21.mp4 -itsoffset 5 -i C:\Users\heshiping\Desktop\videoDown\c.webm -filter_complex [1:v]scale=900:500[sf];[sf]format=yuva444p,colorchannelmixer=aa=0.5[sf];[0:v][sf]overlay=x='if(between(t,5,13),0,NAN)':0 -y C:\Users\heshiping\Desktop\videoDown\eric1.mp4
视频水印旋转透明
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\21.mp4 -itsoffset 10 -i C:\Users\heshiping\Desktop\videoDown\c.webm -filter_complex [1:v]scale=300:200[sf];[sf]format=yuva444p,colorchannelmixer=aa=0.6[sf];[sf]rotate='45*PI/180:ow=hypot(iw,ih):oh=ow:c=none'[sf];[0:v][sf]overlay=x='if(between(t,10,18),100,NAN)':100 C:\Users\heshiping\Desktop\videoDown\ccccc.mp4 -y
转场滤镜
ffmpeg -i /data/video/tencent/动漫/a8dukd400400_泽塔奥特曼_普通话版_18_mp4/a8dukd400400_泽塔奥特曼_普通话版_18_001121_001142.mp4 -i /data/video/tencent/动漫/a8dukd400400_泽塔奥特曼_普通话版_18_mp4/a8dukd400400_泽塔奥特曼_普通话版_18_001100_001121.mp4 -filter_complex "[0:v]split[v0a][v0b];[v0a]trim=0:20[v0020];[v0b]trim=20:21,setpts=PTS-STARTPTS[v02021];[1:v]split[v1a][v1b];[v1a]trim=0:20[v1020];[v1b]trim=20:21,setpts=PTS-STARTPTS[v12021];[v02021][v1020]gltransition=duration=2:source=/usr/local/src/ffmpeg-gl-transition/gl-transitions/transitions/InvertedPageCurl.glsl[g01];[v0020][g01][v12021]concat=n=3[outv];[outv]scale=1920:1080[outv]" -map "[outv]" -c:v libx264 -profile:v baseline -preset slow -movflags faststart -pix_fmt yuv420p -threads 5 -preset ultrafast /data/video/ovwq2f20210322171622763.mp4 -y
任意位置文字水印
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2021.mp4 -vf "drawtext=fontfile=MengNaJianCaiYun-2.ttf: text='heshiping':x=100:y=100:fontsize=29:fontcolor=yellow:shadowy=2" -b:v 3000k C:\Users\heshiping\Desktop\videoDown\222222.mp4 -y
滚动文字水印
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2021.mp4 -vf "drawtext=fontfile=Arial.ttf: text='hu': y=h-line_h-10:x=(mod(2*n\,w+tw)-tw):fontsize=34:fontcolor=yellow:shadowy=2" -b:v 3000k C:\Users\heshiping\Desktop\videoDown\222222.mp4 -y
底部文字水印
ffmpeg -i C:\Users\heshiping\Desktop\videoDown\2021.mp4 -vf "drawtext=fontfile=Arial.ttf:text='pruduction by http\://baidu.com':y=h-line_h-20:x=(w-text_w)/2:fontsize=34:fontcolor=yellow:shadowy=2" -b:v 3000k C:\Users\heshiping\Desktop\videoDown\222222.mp4 -y
水平运动
ffmpeg -y -i demo.mp4 -vf drawtext=arialbd.ttf:text=HelloWorld:x=w-t*5:fontcolor=red:fontsize=30 demo_drawtext_h_dyn.mp4
垂直运动
ffmpeg -y -i demo.mp4 -vf drawtext=arialbd.ttf:text=HelloWorld:x=w/2:y=h-t*5:fontcolor=red:fontsize=30 demo_drawtext_v_dyn.mp4
视频帧数,降低到10帧每秒, 从而降低视频的大小,实现视频压缩
ffmpeg -i "2.mp4" -r 10 -b:a 32k save2.mp4
CentOS 6 的 FFmpeg 构建
此 Docker 映像为 CentOS 6 构建静态 ffmpeg 库(和二进制文件)。其主要目标是提供将被编译为minidlna的静态库。 rpmforge 上 ffmpeg 的 RPM 非常过时,安装其中几个 RPM 最终会增加很多垃圾(minidlna 对我来说是 ffmpeg 的唯一消费者),所以它的存在是为了解决这个问题。
ffmpeg 库主要包含解码器而不是编码器。 大多数依赖库也是静态编译的,除了具有用于更新版本的二进制 RPM 的开源项目,例如 Vorbis。
用法
使用以下命令构建一个包含ffmpeg的 Docker 镜像:
git clone https://github.com/geekman/docker-centos-ffmpeg
docker build -t zxgm/ffmpeg-build docker-ce
$ docker login --username=ttsamj registry.cn-shenzhen.aliyuncs.com
$ docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/pjl-jiekou/pinjl:[镜像版本号]
$ docker push registry.cn-shenzhen.aliyuncs.com/pjl-jiekou/pinjl:[镜像版本号]