ffmpeg使用filter crop 裁剪视频

作者: mudssky | 来源:发表于2019-06-25 14:02 被阅读0次

​ 有时候使用OBS之类的工具录制生放送视频会把多余的边框录制进去,网上有一些这样的视频,这样的视频看起来不太舒服,边框占据屏幕面积,实际的内容只有很小的部分,不方便观看,最近就碰到一个这样的例子。于是我查看ffmpeg文档找到了裁剪视频的方法。

1.filter介绍

​ 使用filter可以对视频流和音频流进行一些处理,包含了很多工具,可以实现诸如裁剪视频,给视频加水印,去色块,加字幕等功能,也有对音频处理的功能,比如可以实现双声道合并转单声道,调整音频采样率等

2.crop

​ 这次我需要处理的一个视频的情况是录制niconico生放送,实际录制区域在左上角,整个视频为1920x1080大小,但是只有左上角部分是浏览器的视频内容,周边全是黑色区域。

​ 执行的ffmpeg命令如下:

ffmpeg -i in.mp4 -vf crop='1280:720:0:0' -acodec copy out.mp4

其中crop常用的4个参数分别用:隔开,w,h,x,y,分别是裁剪的宽高和裁剪的位置。

也可以按如下方式指定参数

ffmpeg -i in.mp4 -vf crop='out_w=1280:out_h=720:x=0:y=0' -acodec copy out.mp4

-vf是 -filter:v的缩写。

还有一些其他参数可以指定:

  1. keep_aspect,默认是0,设置为1可以保持原视频的宽高比

  2. exact,默认为0,设置为1后裁剪的大小不会取整为最接近的值,而是准确值

  3. out_w,out_h,in_w.in_h,ow,oh,iw,ih可以在参数中使用,分别代表输入输出的宽和高。可以实现复杂一些的应用,比如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)

  4. 通过iw/ih或者a参数,指定宽高比

  5. sar,input sample aspect ratio,输入样本宽高比

  6. dar,input display aspect ratio, it is the same as (iw / ih) * sar,输入样本显示宽高比。

  7. n,起始帧,从0开始

3.cropdetect

自动检测裁剪大小,没有试过实际效果,所以先把文档贴上,以后用到了再看吧。

Auto-detect the crop size.

It calculates the necessary cropping parameters and prints the recommended parameters via the logging system. The detected dimensions correspond to the non-black area of the input video.

It accepts the following parameters:

  • limit

    Set higher black value threshold, which can be optionally specified from nothing (0) to everything (255 for 8-bit based formats). An intensity value greater to the set value is considered non-black. It defaults to 24. You can also specify a value between 0.0 and 1.0 which will be scaled depending on the bitdepth of the pixel format.

  • round

    The value which the width/height should be divisible by. It defaults to 16. The offset is automatically adjusted to center the video. Use 2 to get only even dimensions (needed for 4:2:2 video). 16 is best when encoding to most video codecs.

  • reset_count, reset

    Set the counter that determines after how many frames cropdetect will reset the previously detected largest video area and start over to detect the current optimal crop area. Default value is 0.This can be useful when channel logos distort the video area. 0 indicates ’never reset’, and returns the largest area encountered during playback.

相关文章

  • ffmpeg使用filter crop 裁剪视频

    ​ 有时候使用OBS之类的工具录制生放送视频会把多余的边框录制进去,网上有一些这样的视频,这样的视频看...

  • ffmpeg滤镜命令

    视频裁剪 -vf video filter 视频滤镜 crop 裁剪 -c:v 视频的编码器 libx264 -c...

  • ffmpeg 滤镜命令

    画中画 视频的裁剪 音频倍速 水印的添加和删除 ffmpeg -i 002.mp4 -af crop=in_w-2...

  • ffmpeg使用总结

    需求:实现Android上使用ffmpeg进行视频裁剪,压缩功能 使用到相关技术: 1FFmpeg实现录制视频 采...

  • 007 2019-06-26FFmpeg 滤镜命令

    裁剪尺寸 ffmpeg -i a.mp4 -vf crop=in_w-200:in_h-200 -c:v libx...

  • 2019-03-22

    FFmpeg使用filter_complex命令合并多个视频 我的csdn原文 filter_complex合并多...

  • FFmpeg filter的使用介绍

    目录 参考 FFmpeg filter简介 filter的使用方法 1. 参考 [1] ffmpeg.org/li...

  • ffmpeg常用命令合集

    ffmpeg查询命令 常用命令 视频裁剪滤镜(播放器大小裁剪): ffmpeg -i killer.mp4 -vf...

  • FFmpeg滤镜命令-----视频裁剪

    视频裁剪 执行该命令后,视频的大小都会减少200个像素 参数说明: -vf:视频滤镜 crop=in_w-200:...

  • (裁剪)Crop

    Crop 裁剪图片Repo(备用): https://github.com/jeduan/cordova-plug...

网友评论

    本文标题:ffmpeg使用filter crop 裁剪视频

    本文链接:https://www.haomeiwen.com/subject/vhmtcctx.html