#!/usr/bin/env bash # set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function main { local cmd cmd=$1 shift if [ "$cmd" = "copy" ]; then copy "${@}" elif [ "$cmd" = "av1" ]; then av1 "${@}" elif [ "$cmd" = "stream_software_h264" ]; then stream_software_h264 "${@}" elif [ "$cmd" = "stream_hardware_h264" ]; then stream_hardware_h264 "${@}" elif [ "$cmd" = "preprocess_software_h264" ]; then preprocess_software_h264 "${@}" elif [ "$cmd" = "preprocess_hardware_h264" ]; then preprocess_hardware_h264 "${@}" elif [ "$cmd" = "vp9" ]; then vp9 "${@}" elif [ "$cmd" = "preprocess_hardware_vp9" ]; then preprocess_hardware_vp9 "${@}" elif [ "$cmd" = "vp8" ]; then vp8 "${@}" elif [ "$cmd" = "software_vp8" ]; then software_vp8 "${@}" elif [ "$cmd" = "preprocess_h264" ]; then preprocess_h264 "${@}" elif [ "$cmd" = "preprocess_vp8" ]; then preprocess_vp8 "${@}" elif [ "$cmd" = "webcam" ]; then webcam "${@}" elif [ "$cmd" = "encode_webcam" ]; then encode_webcam "${@}" else (>&2 echo "Unknown command: $cmd") exit 1 fi } function copy { local file_to_cast file_to_cast="$3" local USERNAME PASSWORD USERNAME="$1" PASSWORD="$2" set -x &2 echo "Unknown destination type: $destination_type") exit 1 fi if [ "$acceleration_type" == "software" ]; then true elif [ "$acceleration_type" == "hardware" ]; then args+=(-vaapi_device /dev/dri/renderD128) else (>&2 echo "Unknown acceleration type: $acceleration_type") exit 1 fi args+=(-i "$file_to_cast") if [ "$acceleration_type" == "software" ]; then args+=(-c:v h264) elif [ "$acceleration_type" == "hardware" ]; then args+=(-vf 'format=nv12|vaapi,hwupload') args+=(-c:v h264_vaapi) else (>&2 echo "Unknown acceleration type: $acceleration_type") exit 1 fi args+=(-b:v 2M) args+=(-profile:v high) args+=(-bf 0) args+=(-strict -2) args+=(-c:a opus) args+=(-ac 2) args+=(-b:a 320k) args+=(-ar 48000) if [ "$destination_type" == "stream" ]; then args+=(-f rtsp) args+=(-rtsp_transport tcp) args+=("rtsp://$USERNAME:$PASSWORD@172.16.16.251:8554/fetch") elif [ "$destination_type" == "preproces" ]; then args+=("$file_to_save") else (>&2 echo "Unknown destination type: $destination_type") exit 1 fi } function stream_software_h264 { local file_to_cast file_to_cast="$3" local USERNAME PASSWORD USERNAME="$1" PASSWORD="$2" set -x # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames.