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.
Does anyone know how to do that? thx
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
.
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
Or as a single line:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With