gpt4 book ai didi

ffmpeg - 使用 ffmpeg 剪切视频时,如何获得一致的开始时间和持续时间?

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

我正在尝试将一个约 20 分钟的视频分割成几个 1 分钟的 block this approach 之后,但得到非常奇怪的结果。

我首先尝试使用 -ss 编写循环在 -i 之后.

for m in $(seq 0 20); ffmpeg -i video.mov -ss $((60 * $m)) -t 60 -vcodec copy video.$m.1min.mov

我得到一堆不同的“开始”时间和视频持续时间:
$ for f in *.1min.mov; do echo $f $(ffprobe $f 2>&1 | grep Duration); done
video.0.1min.mov Duration: 00:01:00.01, start: 0.000000, bitrate: 3014 kb/s
video.1.1min.mov Duration: 00:01:00.00, start: 0.012000, bitrate: 3002 kb/s
video.2.1min.mov Duration: 00:01:00.00, start: 0.012000, bitrate: 3002 kb/s
video.3.1min.mov Duration: 00:01:00.00, start: 0.011000, bitrate: 3002 kb/s
video.4.1min.mov Duration: 00:01:00.00, start: 0.010000, bitrate: 3001 kb/s
video.5.1min.mov Duration: 00:01:00.00, start: 0.010000, bitrate: 3002 kb/s
video.6.1min.mov Duration: 00:01:00.00, start: 0.009000, bitrate: 3003 kb/s
video.7.1min.mov Duration: 00:01:00.00, start: 0.009000, bitrate: 3006 kb/s
video.8.1min.mov Duration: 00:01:00.00, start: 0.008000, bitrate: 2999 kb/s
video.9.1min.mov Duration: 00:01:00.00, start: 0.007000, bitrate: 3003 kb/s
video.10.1min.mov Duration: 00:01:00.00, start: 0.007000, bitrate: 3002 kb/s
video.11.1min.mov Duration: 00:01:00.00, start: 0.006000, bitrate: 3002 kb/s
video.12.1min.mov Duration: 00:01:00.00, start: 0.006000, bitrate: 3005 kb/s
video.13.1min.mov Duration: 00:00:50.57, start: 9.438000, bitrate: 3004 kb/s
video.14.1min.mov Duration: 00:00:50.57, start: 9.438000, bitrate: 3003 kb/s
video.15.1min.mov Duration: 00:00:50.57, start: 9.437000, bitrate: 3004 kb/s
video.16.1min.mov Duration: 00:00:50.57, start: 9.436000, bitrate: 2998 kb/s
video.17.1min.mov Duration: 00:00:50.57, start: 9.436000, bitrate: 3004 kb/s
video.18.1min.mov Duration: 00:00:50.57, start: 9.435000, bitrate: 3005 kb/s
video.19.1min.mov Duration: 00:00:50.57, start: 9.435000, bitrate: 3004 kb/s
video.20.1min.mov Duration: 00:00:50.57, start: 9.434000, bitrate: 3001 kb/s

如果我改为移动 -ss-i 之前:
for m in $(seq 0 20); ffmpeg -ss $((60 * $m)) -i video.mov -vcodec copy -t 60 video.$m.1min.mov

然后我得到很好的开始时间,但长度可变:
$ for f in *.1min.mov; do echo $f $(ffprobe $f 2>&1 | grep Duration); done
video.0.1min.mov Duration: 00:01:00.01, start: 0.000000, bitrate: 3014 kb/s
video.1.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3003 kb/s
video.2.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.3.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.4.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3001 kb/s
video.5.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3001 kb/s
video.6.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.7.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3005 kb/s
video.8.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.9.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.10.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3007 kb/s
video.11.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3002 kb/s
video.12.1min.mov Duration: 00:01:10.00, start: 0.000000, bitrate: 3004 kb/s
video.13.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3003 kb/s
video.14.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3003 kb/s
video.15.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3005 kb/s
video.16.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3001 kb/s
video.17.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3004 kb/s
video.18.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3002 kb/s
video.19.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3006 kb/s
video.20.1min.mov Duration: 00:01:00.57, start: 0.000000, bitrate: 3001 kb/s

这里发生了什么?如何获得持续时间均匀且开始时间合理的视频?我的输入视频有什么奇怪的吗? (我无法分享,抱歉!)

最佳答案

我认为问题在于 ffmpeg 试图变得聪明而不是重新编码视频。这使它运行得很快,但代价是我在问题中描述的奇怪的开始和持续时间效果。

解决方案是重新编码视频:

for m in $(seq 0 20); ffmpeg -i video.mov -ss $((60 * $m)) -t 60 video.$m.1min.mov

这运行速度慢了 100 倍,但它至少会生成具有我期望的开始和持续时间的视频:
$ for f in *.1min.mov; do echo $f $(ffprobe $f 2>&1 | grep Duration); done
video.0.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2108 kb/s
video.1.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2519 kb/s
video.2.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2318 kb/s
video.3.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2573 kb/s
video.4.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2104 kb/s
video.5.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2292 kb/s
video.6.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2219 kb/s
video.7.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2381 kb/s
video.8.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2184 kb/s
video.9.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2726 kb/s
video.10.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2253 kb/s
video.11.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 1872 kb/s
video.12.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2418 kb/s
video.13.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2624 kb/s
video.14.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2252 kb/s
video.15.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2426 kb/s
video.16.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2491 kb/s
video.17.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2276 kb/s
video.18.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2249 kb/s
video.19.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2071 kb/s
video.20.1min.mov Duration: 00:01:00.00, start: 0.000000, bitrate: 2317 kb/s

关于ffmpeg - 使用 ffmpeg 剪切视频时,如何获得一致的开始时间和持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45067355/

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