ffmpeg视频滤镜: 裁剪-crop

滤镜简述

复制代码
crop

官网链接 => FFmpeg Filters Documentation

crop滤镜可以对视频进行裁剪,并且这个滤镜可以接受一些变量比如时间和帧数,这样我们实现动态裁剪,从而实现一些特效。

滤镜使用

参数
复制代码
   out_w             <string>     ..FV.....T. set the width crop area expression (default "iw")
   w                 <string>     ..FV.....T. set the width crop area expression (default "iw")
   out_h             <string>     ..FV.....T. set the height crop area expression (default "ih")
   h                 <string>     ..FV.....T. set the height crop area expression (default "ih")
   x                 <string>     ..FV.....T. set the x crop area expression (default "(in_w-out_w)/2")
   y                 <string>     ..FV.....T. set the y crop area expression (default "(in_h-out_h)/2")
   keep_aspect       <boolean>    ..FV....... keep aspect ratio (default false)
   exact             <boolean>    ..FV....... do exact cropping (default false)
  • out_w 和 out_h 这两个参数是要裁剪的宽度和高度. w和h是这两个参数的别名。
  • x和y 是开始裁剪的位置
  • keep_aspect:等比例裁剪,要保持图片的原比例
  • exact:这个参数理解太清楚,按照翻译是精确裁剪的意思,不使用近似值进行裁剪。
可以接受的常量

|-------------------|--------------------------------|
| in_w,in_h,iw,ih | 输入图片的宽和高。iw和ih是in_w和in_h的缩写。 |
| out_w,out_h,ow,oh | 输出图片的宽和高。ow和oh是out_w和out_h的缩写。 |
| a | iw / ih |
| n | 第几帧 |
| t | 视频的第几秒 |

案例

原图

复制代码
ffmpeg -y -i ffm_media/air.jpg -filter_complex "crop=100:100:12:34"  result/crop/crop_test_01.jpg

从图片的(12,34)位置开始裁剪图片,裁剪后的图片是100*100

复制代码
ffmpeg -y -i ffm_media/air.jpg -filter_complex "crop=out_w=in_h"  result/crop/crop_test_03.jpg

从图片的中心位置开始裁剪,获取剩余的全部,相当于将图片分为四份,获取右下角部分

复制代码
ffmpeg -y -i ffm_media/short_dancer.mp4 -filter_complex "crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(n/10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(n/7)"  result/crop/crop_test_06.mp4

基于帧数,使用运镜特效,大家可以找个视频试试,这里上传视频不太方便,也可以进群找我要一下啊。

复制代码
ffmpeg -y -i ffm_media/short_dancer.mp4 -filter_complex "crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(t*10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(t*13)"  result/crop/crop_test_07.mp4

基于时间戳,使用运镜特效,大家可以找个视频试试,这里上传视频不太方便。

复制代码
## 祝你好运
 
hope("大神多多指点")
topic("有问题可以交流呀")
concat("求求QUN", "61480", "9646")

相关推荐
Maverick061 天前
02-SQL执行计划与优化器:Oracle是怎么决定“该怎么查“的
数据库·sql·oracle·ffmpeg
EasyDSS1 天前
RTMP高清推流直播/智能转码/无人机直播EasyDSS破局旅游慢直播痛点
ffmpeg·旅游·视频转码·fmp4·点播技术
EasyDSS1 天前
RTMP高清推流直播/视频转码EasyDSS在无人机RTMP直播场景中的应用技术解析
ffmpeg·音视频·无人机·视频转码·语音转写·点播技术
私人珍藏库1 天前
[Windows] FFmpeg 图形化:EasyFF v0.17
ffmpeg·媒体·工具·软件·win·多功能
EasyDSS2 天前
场景深耕:低延迟高并发EasyDSS无人机RTMP高清推流直播技术剖析
ffmpeg·webrtc·rtmp
小鹿软件办公2 天前
FFmpeg 8.1 正式发布:引入 Vulkan 计算加速,支持 DPX 与 ProRes
ffmpeg
开开心心就好2 天前
轻量级PDF阅读器,仅几M大小打开秒开
linux·运维·服务器·安全·pdf·1024程序员节·oneflow
chushiyunen2 天前
ffmpeg将mp4转换为swf、视频格式、m3u8等(二)
ffmpeg
1234567890@world2 天前
FFmpeg | Day1 FFmpege音视频开发与学习
学习·ffmpeg·音视频
MaximusCoder3 天前
等保测评命令——达梦数据库 DM
linux·运维·数据库·安全·ffmpeg·安全威胁分析