summaryrefslogtreecommitdiff
path: root/bin/captureIIDC+edit+encode+stream
blob: fd143c2d15d8d111ba7807e1cf6ad2de904ca077 (plain)
  1. #!/bin/sh
  2. set -e
  3. AINPUT=hw:0
  4. VINPUT=/dev/fw1
  5. LOGO=../../content/icon_small.png
  6. HOST=${1:-morla}
  7. if [ "$HOST" = "$(hostname --short)" ]; then
  8. IP=127.0.0.1
  9. else
  10. IP=$(host "$HOST" | grep -Po 'address \K\S+')
  11. fi
  12. FIRSTPORT=${2:-5002} # even number - next 3 ports used too
  13. ACHANNELS=2
  14. AFRAMERATE=48000
  15. ABITRATE=32000
  16. HEIGHT=360
  17. VBITRATE=256000
  18. # based on http://www.webmproject.org/docs/encoder-parameters/#real-time-cbr-encoding-and-streaming
  19. # + scale+watermark trick based on http://stackoverflow.com/a/10937357
  20. # + Add 1s latency (deadline)
  21. # + Use same RTP payload types as GStreamer
  22. ffmpeg -hide_banner -threads auto -re \
  23. -f alsa -sample_rate "$AFRAMERATE" -channels "$ACHANNELS" -thread_queue_size 1024 -i "$AINPUT" \
  24. -f libdc1394 -video_size 640x480 -framerate 15 -thread_queue_size 256 -i "$VINPUT" \
  25. -i "$LOGO" \
  26. -filter_complex \
  27. "[1:v]scale=-1:$HEIGHT[bg];
  28. [bg][2:v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v]" \
  29. -map '0:a' \
  30. -codec:a libopus -ac "$ACHANNELS" -ar "$AFRAMERATE" -b:a "$ABITRATE" \
  31. -f rtp -payload_type 111 "rtp://$IP:$FIRSTPORT?pkt_size=1200" \
  32. -map '[v]' \
  33. -pix_fmt yuv420p \
  34. -codec:v vp8 -quality realtime -deadline 1000000 -cpu-used 15 \
  35. -b:v "$VBITRATE" -minrate "$VBITRATE" -maxrate "$VBITRATE" \
  36. -undershoot-pct 95 -bufsize $((6000*VBITRATE/1000)) -rc_init_occupancy $((4000*VBITRATE/1000)) \
  37. -max-intra-rate 0 \
  38. -qmin 4 -qmax 56 \
  39. -f rtp -payload_type 100 "rtp://$IP:$((FIRSTPORT+2))?pkt_size=1200"