ffmpeg_splitter.sh 1.3 KB
Newer Older
Lars Beckers's avatar
Lars Beckers committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/bin/bash

# dirty little script to split a video into 15 minutes parts with ten
# seconds overlap (for upload to youtube)
# Author: milan <milan.santosi@gmail.com>
#
# USAGE: read comments and adjust where necessary, then:
# ./ffmpeg_splitter.sh <inputfile>
####################################################################


# use globbing to get basename and extension.
# see http://linuxgazette.net/18/bash.html
fname=$1           # the file name
bname=${fname%%.*} # the file basename
ext=${fname#*.}    # the file extension


# to avoid async a/v, re-encode with every frame as keyframe
if 
    test -f $bname-keyframes.$ext
then
    :
else 
    ffmpeg -g 1 -i $1 $bname-keyframes.$ext
fi    
    

# get length of the original video, calculate amount of segments and
# combined length of all parts (with overlap)
let vidlen=$(ffprobe -show_format $bname-keyframes.$ext | grep duration | cut -d "." -f 1 | cut -d "=" -f 2)
let segcount=$vidlen/900
let withoverlap=$vidlen+$segcount*10
let newsegcount=$withoverlap/900


# loop until it's done (actually one more time, just to make sure)
for (( i = 1; i <= $newsegcount+1; i++))
do                                                                     
    ffmpeg -vcodec copy -acodec copy -ss $[i*890 - 890] -t 899.999 -i $bname-keyframes.$ext $bname-part0$i.$ext
done