Created
July 25, 2014 08:03
-
-
Save tfogo/647ab7e4e50a4c4d7fdf to your computer and use it in GitHub Desktop.
Split long videos into 2 minute segments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILES=/home/tim/Videos/marathon-vids/*.mp4 | |
for f in $FILES | |
do | |
time="$(avprobe "$f" 2>&1 >/dev/null | grep -Po '(?<=Duration:\s)\d{2}:\d{2}:\d{2}')" | |
hrs="$(echo "$time" | grep -Po '\d{2}(?=:\d{2}:\d{2})')" | |
mins="$(echo "$time" | grep -Po '(?<=\d{2}:)\d{2}(?=:\d{2})')" | |
secs="$(echo "$time" | grep -Po '(?<=\d{2}:\d{2}:)\d{2}')" | |
filename="$(echo "$f" | grep -Po '(?<=/home/tim/Videos/marathon-vids/).*(?=\.mp4)')" | |
let time=$hrs*3600+$mins*60+$secs | |
echo $time | |
if [[ $time -gt 150 ]] | |
then | |
split=120 | |
while [ $split -lt $time ] | |
do | |
let diff=time-split | |
if [[ $diff -gt 120 ]] | |
then | |
diff=120 | |
fi | |
let number=split/120 | |
ffmpeg -i "$f" -ss "$split" -t "$diff" -acodec copy -vcodec copy -async 1 -y ./output/"$filename"_"$number".mp4 | |
let split=split+120 | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment