summaryrefslogtreecommitdiff
path: root/bin/livedump
blob: 77b2add10a4de26288fc07a0206087afab0f3aa6 (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. set -eu
  18. FORMAT=${1:-dv}
  19. BASEPATH=${2:-./dump}
  20. SESSIONPATTERN=${3:-/%Y%m%d/%H%M%S}
  21. SEGMENTPATTERN=${4:-/%H%M%S}
  22. case $FORMAT in
  23. dv)
  24. set -- \
  25. -f iec61883 -i auto \
  26. -f dv -timecode "$(date +%H:%M:%S.00)" -codec copy
  27. SUFFIX=dv
  28. ;;
  29. esac
  30. LINKPATH="$LINKSTEM.$SUFFIX"
  31. SESSIONSTEM=$(date +"$TARGETPATTERN")
  32. SESSIONPATH="$SESSIONSTEM.$SUFFIX"
  33. mkdir -p "$(dirname "$LINKPATH" "$SESSIONPATH")"
  34. touch "$SESSIONPATH"
  35. [ -z "$LINKPATH" ] | ln -fs "$SESSIONPATH" "$LINKPATH"
  36. while true; do
  37. SEGMENTSTEM=$(date +"$SEGMENTPATTERN")
  38. LOGPATH="$BASEPATH$SESSIONSTEM$SEGMENTSTEM.log"
  39. mkdir -p "$LOGPATH"
  40. FFREPORT="file=$LOGPATH" \
  41. ffmpeg -hide_banner "$@" pipe: \
  42. >> "$SESSIONPATH"
  43. done