summaryrefslogtreecommitdiff
path: root/bin/livedump
blob: bb0ca152ae9241feed2cd9888f5eafe499e618a0 (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. isight-nut)
  26. set -- -f libdc1394 -video_size 640x480 -framerate 15 -thread_queue_size 256 -i foo \
  27. -f alsa -thread_queue_size 2048 -i default:CARD=iSight \
  28. -f nut -codec copy -f_strict experimental -syncpoints timestamped -write_index 0
  29. SUFFIX=nut
  30. ;;
  31. dv)
  32. set -- -f iec61883 -i auto \
  33. -f dv -codec copy
  34. SUFFIX=dv
  35. ;;
  36. dv-avi)
  37. set -- -f iec61883 -i auto \
  38. -f avi -codec copy
  39. SUFFIX=avi
  40. ;;
  41. dv-nut)
  42. set -- -f iec61883 -i auto \
  43. -f nut -codec copy -f_strict experimental -syncpoints timestamped -write_index 0
  44. SUFFIX=nut
  45. ;;
  46. esac
  47. LINKPATH="$BASESTEM.$SUFFIX"
  48. SESSIONSTEM=$(date +"$SESSIONPATTERN")
  49. SESSIONPATH="$BASESTEM$SESSIONSTEM.$SUFFIX"
  50. mkdir -p "$(dirname "$LINKPATH")" "$(dirname "$SESSIONPATH")"
  51. touch "$SESSIONPATH"
  52. [ -z "$LINKPATH" ] | ln -fs "$SESSIONPATH" "$LINKPATH"
  53. while true; do
  54. SEGMENTSTEM=$(date +"$SEGMENTPATTERN")
  55. LOGPATH="$BASESTEM$SESSIONSTEM$SEGMENTSTEM.log"
  56. mkdir -p "$(dirname "$LOGPATH")"
  57. FFREPORT="file=$LOGPATH" \
  58. ffmpeg -hide_banner "$@" pipe: \
  59. >> "$SESSIONPATH"
  60. done