如何保持 ffmpeg 裁剪检测的最高值
How to keep highest value of ffmpeg crop detect
案例:
我正在转换包含 18000 个广告的旧存档
我想自动从 DV 重新转换为一些更轻和最新的 h264 mp4
整个过程已经准备就绪,但我卡在了第一部分:裁剪黑条...
使用的工具:
问题是:所有视频都不同,我不能使用一个静态值,因此我使用了 ffmpeg 的精彩 cropdetect 工具,它在 cli 中输出了这种行:
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:483 w:672 h:384 x:24 y:98 pts:63 t:2.520000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:483 w:672 h:384 x:24 y:98 pts:64 t:2.560000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:484 w:672 h:384 x:24 y:98 pts:65 t:2.600000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:496 w:672 h:400 x:24 y:96 pts:66 t:2.640000 crop=672:400:24:96
[Parsed_cropdetect_0 @ 0xbe5e960] x1:2 x2:717 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:67 t:2.680000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:68 t:2.720000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:69 t:2.760000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:70 t:2.800000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:71 t:2.840000 crop=704:416:8:80
所以最后一部分:crop=
给出了剩余帧的结果(宽度,高度,开始 x 点开始 y 点。裁剪视频..
但是这些值在一个视频中并不总是相同的我如何从这数百行中提取 'the biggest values'?
在这种情况下,只需保持crop=704:416:8:80
编辑
其实这个结果应该考虑到最低的x1,最高的x2,最低的y1和最高的y2,然后在里面创建一个16的倍数的矩形...
肯定有更好的方法,但也许这可以作为你的蹦床:
#!/bin/bash
IFS=':'
while read a b c d; do
w+=("$a")
h+=("$b")
x+=("$c")
y+=("$d")
done < <(sed 's/.*crop=\(.*\)//g' file)
IFS=$'\n'
echo "w_max=$(echo "${w[*]}" | sort -nr | head -n1)"
echo "w_min=$(echo "${w[*]}" | sort -n | head -n1)"
echo "h_max=$(echo "${h[*]}" | sort -nr | head -n1)"
echo "h_min=$(echo "${h[*]}" | sort -n | head -n1)"
echo "x_max=$(echo "${x[*]}" | sort -nr | head -n1)"
echo "x_min=$(echo "${x[*]}" | sort -n | head -n1)"
echo "y_max=$(echo "${y[*]}" | sort -nr | head -n1)"
echo "y_min=$(echo "${y[*]}" | sort -n | head -n1)"
# do your math here
输出为:
w_max=704
w_min=672
h_max=416
h_min=384
x_max=24
x_min=8
y_max=98
y_min=80
你仍然应该在最后做你的"multiple of 16"数学。
输出中的每一行显示的是迄今为止进程遇到的最大区域,而不是每一帧的确切区域。所以你应该只看最后一行。
案例:
我正在转换包含 18000 个广告的旧存档 我想自动从 DV 重新转换为一些更轻和最新的 h264 mp4
整个过程已经准备就绪,但我卡在了第一部分:裁剪黑条...
使用的工具:
问题是:所有视频都不同,我不能使用一个静态值,因此我使用了 ffmpeg 的精彩 cropdetect 工具,它在 cli 中输出了这种行:
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:483 w:672 h:384 x:24 y:98 pts:63 t:2.520000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:483 w:672 h:384 x:24 y:98 pts:64 t:2.560000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:484 w:672 h:384 x:24 y:98 pts:65 t:2.600000 crop=672:384:24:98
[Parsed_cropdetect_0 @ 0xbe5e960] x1:22 x2:697 y1:93 y2:496 w:672 h:400 x:24 y:96 pts:66 t:2.640000 crop=672:400:24:96
[Parsed_cropdetect_0 @ 0xbe5e960] x1:2 x2:717 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:67 t:2.680000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:68 t:2.720000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:69 t:2.760000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:70 t:2.800000 crop=704:416:8:80
[Parsed_cropdetect_0 @ 0xbe5e960] x1:1 x2:718 y1:80 y2:496 w:704 h:416 x:8 y:80 pts:71 t:2.840000 crop=704:416:8:80
所以最后一部分:crop=
给出了剩余帧的结果(宽度,高度,开始 x 点开始 y 点。裁剪视频..
但是这些值在一个视频中并不总是相同的我如何从这数百行中提取 'the biggest values'?
在这种情况下,只需保持crop=704:416:8:80
编辑
其实这个结果应该考虑到最低的x1,最高的x2,最低的y1和最高的y2,然后在里面创建一个16的倍数的矩形...
肯定有更好的方法,但也许这可以作为你的蹦床:
#!/bin/bash
IFS=':'
while read a b c d; do
w+=("$a")
h+=("$b")
x+=("$c")
y+=("$d")
done < <(sed 's/.*crop=\(.*\)//g' file)
IFS=$'\n'
echo "w_max=$(echo "${w[*]}" | sort -nr | head -n1)"
echo "w_min=$(echo "${w[*]}" | sort -n | head -n1)"
echo "h_max=$(echo "${h[*]}" | sort -nr | head -n1)"
echo "h_min=$(echo "${h[*]}" | sort -n | head -n1)"
echo "x_max=$(echo "${x[*]}" | sort -nr | head -n1)"
echo "x_min=$(echo "${x[*]}" | sort -n | head -n1)"
echo "y_max=$(echo "${y[*]}" | sort -nr | head -n1)"
echo "y_min=$(echo "${y[*]}" | sort -n | head -n1)"
# do your math here
输出为:
w_max=704
w_min=672
h_max=416
h_min=384
x_max=24
x_min=8
y_max=98
y_min=80
你仍然应该在最后做你的"multiple of 16"数学。
输出中的每一行显示的是迄今为止进程遇到的最大区域,而不是每一帧的确切区域。所以你应该只看最后一行。