gpt4 book ai didi

bash - 如何保持ffmpeg裁剪检测的最高值

转载 作者:行者123 更新时间:2023-12-04 23:03:49 24 4
gpt4 key购买 nike

案子 :

我正在转换一个包含 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 点。裁剪视频..

但是这些值在一个视频中并不总是相同的,如何从这数百行中提取“最大值”?

在这种情况下,只需保留 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=\(.*\)/\1/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

最后,您仍然应该进行“16 的倍数”数学运算。

关于bash - 如何保持ffmpeg裁剪检测的最高值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31440450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com