Browse Source

add a script that parses more readable time for pulling a segment from

a file using ffmpeg..
main
John-Mark Gurney 3 years ago
parent
commit
b7bbff5108
1 changed files with 69 additions and 0 deletions
  1. +69
    -0
      clipmv.sh

+ 69
- 0
clipmv.sh View File

@@ -0,0 +1,69 @@
#!/bin/sh
# This is in the public domain.
# written by John-Mark Gurney

timetosec()
{
sec="${1##*:}"
rem="${1%:*}"
if [ x"$rem" = x"" -o x"$1" = x"$sec" ]; then
hour=0
min=0
sec=${sec#0}
else
orig="$rem"
min="${rem##*:}"
rem="${rem%:*}"
sec=${sec#0}
if [ x"$rem" = x"" -o x"$min" = x"$orig" ]; then
hour=0
else
hour="$rem"
fi

fi

echo $(($hour * 60 * 60 + $min * 60 + $sec ))
}

failed()
{
echo failed
exit 1
}

if [ x"$1" = x"-t" ]; then
set -x

x=$(timetosec 30)
if [ x"$x" != x"30" ]; then
failed
fi

x=$(timetosec 1:30)
if [ x"$x" != x"$((60+30))" ]; then
failed
fi

x=$(timetosec 1:01:30)
if [ x"$x" != x"$((60*60+60+30))" ]; then
failed
fi

exit 0
fi

if [ x"$#" != x"4" ]; then
echo "Usage: $0 <inp> <start> <stop> <output>"
exit 1
fi

inp="$1"
start="$2"
end="$3"
out="$4"

startsec=$(timetosec "$start")
endsec=$(timetosec "$end")

ffmpeg -ss "$startsec" -i "$inp" -t $(($endsec - $startsec + 1)) -codec copy "$out"

Loading…
Cancel
Save