summaryrefslogtreecommitdiff
path: root/bin/decode+edit+encodeDV
blob: 1a8bb45b7c17cc6cf23390f55bf598b6318f9fd1 (plain)
  1. #!/bin/sh
  2. # FIXME: Handle audio
  3. set -e
  4. ##
  5. ## defaults
  6. ##
  7. INPUT=../src/omni/show0/earth.mp4
  8. LOGO=../../content/icon_small.png
  9. OUTPUT=../tmp/omni/show0/earth.dv
  10. RATIO=4:3
  11. HEIGHT=360
  12. videosize() { height=$1; width_or_ratio=$2;
  13. case $width_or_ratio in
  14. *:*) num=${width_or_ratio%:*}; den=${width_or_ratio#*:}; width=$((height*num/den));;
  15. *) width=$width_or_ratio;;
  16. esac
  17. echo_n $((height*width))
  18. }
  19. BITS=$(videosize "$HEIGHT" "$RATIO")
  20. # * bitrates and bits in parens based on https://developer.apple.com/library/content/documentation/General/Reference/HLSAuthoringSpec/Requirements.html
  21. # + bits rounded up to include nearby modulo 16 formats
  22. # + best (i.e. high-modulo) 16:9 heights: 216 288 360 432 576 720
  23. # + best (i.e. high-modulo) 4:3 heights: 288 312 384 480 624 816
  24. if [ $BITS -le 110592 ]; then # 234p → 97344
  25. VBITRATE=145000
  26. elif [ $BITS -le 150528 ]; then # 270p → 129600
  27. VBITRATE=365000
  28. elif [ $BITS -le 196608 ]; then # 360p → 172800
  29. VBITRATE=730000
  30. elif [ $BITS -le 331776 ]; then # 432p → 331776
  31. VBITRATE=1100000
  32. elif [ $BITS -le 589824 ]; then # 540p → 518400
  33. VBITRATE=2000000
  34. elif [ $BITS -le 921600 ]; then # 720p → 921600
  35. VBITRATE=3000000
  36. fi
  37. mkdir -p $(dirname "$OUTPUT")
  38. # based on http://www.webmproject.org/docs/encoder-parameters/#real-time-cbr-encoding-and-streaming
  39. # + scale+watermark trick based on http://stackoverflow.com/a/10937357
  40. # + scale to square pixels as needed
  41. # + Add 1s latency (deadline)
  42. ffmpeg -hide_banner -threads auto -y \
  43. -i "$INPUT" \
  44. -i "$LOGO" \
  45. -filter_complex \
  46. "[0:v]scale=iw*sar*$HEIGHT/ih:$HEIGHT,setsar=1[bg];
  47. [bg][1:v]overlay=main_w-overlay_w-20:main_h-overlay_h-20[v]" \
  48. -map '[v]' \
  49. -target pal-dv "$OUTPUT"