Set of scripts used for various projects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
980 B

  1. #!/bin/sh
  2. # This is in the public domain.
  3. # written by John-Mark Gurney
  4. timetosec()
  5. {
  6. sec="${1##*:}"
  7. rem="${1%:*}"
  8. if [ x"$rem" = x"" -o x"$1" = x"$sec" ]; then
  9. hour=0
  10. min=0
  11. sec=${sec#0}
  12. else
  13. orig="$rem"
  14. min="${rem##*:}"
  15. rem="${rem%:*}"
  16. sec=${sec#0}
  17. if [ x"$rem" = x"" -o x"$min" = x"$orig" ]; then
  18. hour=0
  19. else
  20. hour="$rem"
  21. fi
  22. fi
  23. echo $(($hour * 60 * 60 + $min * 60 + $sec ))
  24. }
  25. failed()
  26. {
  27. echo failed
  28. exit 1
  29. }
  30. if [ x"$1" = x"-t" ]; then
  31. set -x
  32. x=$(timetosec 30)
  33. if [ x"$x" != x"30" ]; then
  34. failed
  35. fi
  36. x=$(timetosec 1:30)
  37. if [ x"$x" != x"$((60+30))" ]; then
  38. failed
  39. fi
  40. x=$(timetosec 1:01:30)
  41. if [ x"$x" != x"$((60*60+60+30))" ]; then
  42. failed
  43. fi
  44. exit 0
  45. fi
  46. if [ x"$#" != x"4" ]; then
  47. echo "Usage: $0 <inp> <start> <stop> <output>"
  48. exit 1
  49. fi
  50. inp="$1"
  51. start="$2"
  52. end="$3"
  53. out="$4"
  54. startsec=$(timetosec "$start")
  55. endsec=$(timetosec "$end")
  56. ffmpeg -ss "$startsec" -i "$inp" -t $(($endsec - $startsec + 1)) -codec copy "$out"