summaryrefslogtreecommitdiff
path: root/bin/livedump
blob: 5db6c3cebd8d8fcb978bd0e2c58c5ef009bec83e (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. set -eu
  20. FORMAT=${1:-dv}
  21. BASESTEM=${2:-./dump}
  22. SESSIONPATTERN=${3:-/%Y%m%d/%H%M%S}
  23. SEGMENTPATTERN=${4:-/%H%M%S}
  24. case $FORMAT in
  25. dv)
  26. set -- -f iec61883 -i auto \
  27. -f dv -codec copy
  28. SUFFIX=dv
  29. ;;
  30. dv-avi)
  31. set -- -f iec61883 -i auto \
  32. -f avi -codec copy
  33. SUFFIX=avi
  34. ;;
  35. dv-nut)
  36. set -- -f iec61883 -i auto \
  37. -f nut -codec copy -f_strict experimental -syncpoints timestamped -write_index 0
  38. SUFFIX=nut
  39. ;;
  40. esac
  41. LINKPATH="$BASESTEM.$SUFFIX"
  42. SESSIONSTEM=$(date +"$SESSIONPATTERN")
  43. SESSIONPATH="$BASESTEM$SESSIONSTEM.$SUFFIX"
  44. mkdir -p "$(dirname "$LINKPATH")" "$(dirname "$SESSIONPATH")"
  45. touch "$SESSIONPATH"
  46. [ -z "$LINKPATH" ] | ln -fs "$SESSIONPATH" "$LINKPATH"
  47. while true; do
  48. SEGMENTSTEM=$(date +"$SEGMENTPATTERN")
  49. LOGPATH="$BASESTEM$SESSIONSTEM$SEGMENTSTEM.log"
  50. mkdir -p "$(dirname "$LOGPATH")"
  51. FFREPORT="file=$LOGPATH" \
  52. ffmpeg -hide_banner "$@" pipe: \
  53. >> "$SESSIONPATH"
  54. done