summaryrefslogtreecommitdiff
path: root/bin/livedump
blob: 77daac3e3e967adafa5bbff304e75a25ae333219 (plain)
  1. #!/bin/sh
  2. #
  3. # Usage: livedump [FORMAT [BASESTEM [SESSIONPATTERN [SEGMENTPATTERN]]]]
  4. #
  5. # Patterns are fed through "date +PATTERN"
  6. #
  7. # Examples: livedump
  8. # livedump dv ./dump /%Y%m%d/%H%M%S /%H%M%S
  9. # livedump dv-avi
  10. #
  11. # First two examples effectively identical, using defaults.
  12. # Third example using AVI container instead
  13. #
  14. # Description: Save live source to file and append if interupted.
  15. # By default captures IEC61883 DVCPRO stream from IEEE1394 (Firewire)
  16. # device, some of which apparently sustaining streams max. 17 minutes.
  17. #
  18. # Depends: ffmpeg
  19. #
  20. # TODO: Add formats mkv and avi, the latter possibly most suitable:
  21. # http://trac.ffmpeg.org/wiki/Concatenate#binconcat
  22. set -eu
  23. FORMAT=${1:-dv}
  24. BASESTEM=${2:-./dump}
  25. SESSIONPATTERN=${3:-/%Y%m%d/%H%M%S}
  26. SEGMENTPATTERN=${4:-/%H%M%S}
  27. case $FORMAT in
  28. dv|dv-*)
  29. INPUTFORMAT=dv
  30. SUFFIX=${FORMAT#dv-}
  31. OUTPUTFORMAT=${FORMAT#dv-}
  32. ;;
  33. esac
  34. case $SUFFIX in
  35. mkv) OUTPUTFORMAT=matroska;;
  36. esac
  37. case $INPUTFORMAT in
  38. dv)
  39. set -- \
  40. -f iec61883 -i auto \
  41. -f ${OUTPUTFORMAT#dv-} \
  42. -timecode "$(date +%H:%M:%S.00)" -codec copy
  43. ;;
  44. esac
  45. LINKPATH="$BASESTEM.$SUFFIX"
  46. SESSIONSTEM=$(date +"$SESSIONPATTERN")
  47. SESSIONPATH="$BASESTEM$SESSIONSTEM.$SUFFIX"
  48. mkdir -p "$(dirname "$LINKPATH")" "$(dirname "$SESSIONPATH")"
  49. touch "$SESSIONPATH"
  50. [ -z "$LINKPATH" ] | ln -fs "$SESSIONPATH" "$LINKPATH"
  51. while true; do
  52. SEGMENTSTEM=$(date +"$SEGMENTPATTERN")
  53. LOGPATH="$BASESTEM$SESSIONSTEM$SEGMENTSTEM.log"
  54. mkdir -p "$(dirname "$LOGPATH")"
  55. FFREPORT="file=$LOGPATH" \
  56. ffmpeg -hide_banner "$@" pipe: \
  57. >> "$SESSIONPATH"
  58. done