是否可以使用 ffmpeg 自动裁剪视频的黑色边框?

Kon*_*tin 21 video script automation ffmpeg crop

我认为它有一个“黑度”视频过滤器,可以确定图片序列是否为黑色。也许它还有一个过滤器来自动确定裁剪值以去除视频边缘的黑色边框。或者也许可以以某种方式使用“黑色”过滤器编写脚本。

Cor*_*ius 31

对的,这是可能的。

先播放你的视频看是否正常:

ffplay -i YourMovie.mp4 -vf "cropdetect=24:16:0"
Run Code Online (Sandbox Code Playgroud)

cropdetect过滤器的值是:

cropdetect=limit:round:reset

limit = black threshold (default 24)
round = output resolution must be divisible to this
reset = after how many frames the detection process will start over
Run Code Online (Sandbox Code Playgroud)

如果看起来没问题,请裁剪它:

ffmpeg -i YourMovie.mp4 -vf "crop=640:256:0:36" YourCroppedMovie.mp4
Run Code Online (Sandbox Code Playgroud)

来源和更多信息:René Calles 博客renevolution.com

  • 使用cropdetect(在输入-i 之前)时放置一个起点(-ss 00:05:00)可能会有所帮助,因为某些视频在启动时会出现纯黑屏。 (8认同)

Jan*_*nes 16

来自:https : //stackoverflow.com/questions/17265381/ffmpeg-get-value-from-cropdetect

ffmpeg -i input -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1
Run Code Online (Sandbox Code Playgroud)


Ale*_*che 5

将其他两个答案放在一个脚本中:

#!/bin/sh
#ffmpeg_zoom ver 20180128202453
I="$@";X=${I##*.};O=${I%.*}_zoomed.${X};f=$(which ffmpeg 2>/dev/null)
if [ ! "$f" ]||[ "$f" = '' ];then echo "Install ffmpeg";exit 1;fi
C=$($f -i "$I" -t 1 -vf cropdetect -f null - 2>&1|awk '/crop/{print $NF}'|tail -n1)
echo $f -i "$I" -vf "$C" "$O"; $f -i "$I" -vf "$C" "$O"
Run Code Online (Sandbox Code Playgroud)

这个问题有一些相关的 ffmpeg 例子