summaryrefslogtreecommitdiff
path: root/bin/livedump
blob: 3120affb7930e48b433f50f075f2d08c2cb35706 (plain)
  1. #!/bin/sh
  2. #
  3. # Usage: livedump [FORMAT [BASEPATH [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. #
  10. # (examples are effectively identical, the latter showing defaults)
  11. #
  12. # Description: Save live source to file and append if interupted.
  13. # By default captures IEC61883 DVCPRO stream from IEEE1394 (Firewire)
  14. # device, some of which apparently sustaining streams max. 17 minutes.
  15. #
  16. # Depends: ffmpeg
  17. #
  18. # TODO: Add formats mkv and avi, the latter possibly most suitable:
  19. # http://trac.ffmpeg.org/wiki/Concatenate#binconcat
  20. set -eu
  21. FORMAT=${1:-dv}
  22. BASEPATH=${2:-./dump}
  23. SESSIONPATTERN=${3:-/%Y%m%d/%H%M%S}
  24. SEGMENTPATTERN=${4:-/%H%M%S}
  25. case $FORMAT in
  26. dv)
  27. set -- \
  28. -f iec61883 -i auto \
  29. -f dv -timecode "$(date +%H:%M:%S.00)" -codec copy
  30. SUFFIX=dv
  31. ;;
  32. esac
  33. LINKPATH="$LINKSTEM.$SUFFIX"
  34. SESSIONSTEM=$(date +"$TARGETPATTERN")
  35. SESSIONPATH="$SESSIONSTEM.$SUFFIX"
  36. mkdir -p "$(dirname "$LINKPATH" "$SESSIONPATH")"
  37. touch "$SESSIONPATH"
  38. [ -z "$LINKPATH" ] | ln -fs "$SESSIONPATH" "$LINKPATH"
  39. while true; do
  40. SEGMENTSTEM=$(date +"$SEGMENTPATTERN")
  41. LOGPATH="$BASEPATH$SESSIONSTEM$SEGMENTSTEM.log"
  42. mkdir -p "$LOGPATH"
  43. FFREPORT="file=$LOGPATH" \
  44. ffmpeg -hide_banner "$@" pipe: \
  45. >> "$SESSIONPATH"
  46. done