剪下多部影片 [英] Cut end of multiple videos
问题描述
我需要一个脚本来截断多个视频的最后6秒。这些视频的长度各不相同。
I need a script to cut off the last 6 seconds of multiple videos. The videos do all have different length.
我在网上找不到任何有用的东西。
I can‘t find anything helpful online.
有人知道吗?怎么做?
thx
Does anyone know how to do that? thx
推荐答案
使用 ffprobe
的方法输入持续时间, bc
计算所需的输出持续时间, ffmpeg
执行剪切。此方法不需要输入包含音频流,但是需要两个附加工具( ffprobe
和 bc
)而不只是 ffmpeg
。
A method that uses ffprobe
to get the input duration, bc
to calculate the desired output duration, and ffmpeg
to perform the cutting. This method does not require the inputs to contain an audio stream, but it requires two additional tools (ffprobe
and bc
) instead of just ffmpeg
.
没有提到您喜欢的脚本语言,所以我认为bash可以。以要求的脚本形式:
Your preferred scripting language wasn't mentioned so I'll assume bash will do. In a script form as requested:
#!/bin/bash
for f in *.mp4; do
cut_duration=6
input_duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$f")
output_duration=$(bc <<< "$input_duration"-"$cut_duration")
ffmpeg -i "$f" -map 0 -c copy -t "$output_duration" output/"$f"
done
或者作为一行:
for f in *.mp4; do ffmpeg -i "$f" -map 0 -c copy -t "$(bc <<< "$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$f")"-6)" output/"$f"; done
这篇关于剪下多部影片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!