From 5c823f3353f503946f1d2d70088c6ab49d0d73b4 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 17 Nov 2024 21:29:42 -0500 Subject: [PATCH] Try a convert vs stream function instead for video conversion. --- .../environments/home/host_vars/homeserver | 2 +- .../roles/devfs/files/homeserver_devfs.rules | 6 + ansible/roles/firefox/defaults/main.yaml | 2 +- .../roles/framework_laptop/tasks/linux.yaml | 1 + ansible/roles/jail/files/jails/dagger.conf | 2 + ansible/roles/media/files/cast_file_vaapi | 368 +++++------------- ansible/roles/media/tasks/linux.yaml | 2 + ansible/roles/network/files/main.conf | 3 + .../currentznver4-default-framework-make.conf | 1 + ansible/roles/zfs/tasks/linux.yaml | 7 +- 10 files changed, 114 insertions(+), 280 deletions(-) diff --git a/ansible/environments/home/host_vars/homeserver b/ansible/environments/home/host_vars/homeserver index e23f546..5010a77 100644 --- a/ansible/environments/home/host_vars/homeserver +++ b/ansible/environments/home/host_vars/homeserver @@ -88,6 +88,6 @@ linfi: enabled: true zfs_dataset: zmass/unencrypted/vm/linfi zfs_mountpoint: /vm/linfi - driver_blocklist: "ath if_ath if_ath_pci ath_hal" + driver_blocklist: "ath if_ath if_ath_pci ath_hal if_iwm if_iwlwifi" pci_blocklist: "6/0/0" amd: false diff --git a/ansible/roles/devfs/files/homeserver_devfs.rules b/ansible/roles/devfs/files/homeserver_devfs.rules index b6ed32d..ba16c85 100644 --- a/ansible/roles/devfs/files/homeserver_devfs.rules +++ b/ansible/roles/devfs/files/homeserver_devfs.rules @@ -17,3 +17,9 @@ add include $devfsrules_hide_all add include $devfsrules_unhide_basic add include $devfsrules_unhide_login add path 'bpf*' unhide + +[tajailrand=15] +add include $devfsrules_hide_all +add include $devfsrules_unhide_basic +add include $devfsrules_unhide_login +add path urandom unhide diff --git a/ansible/roles/firefox/defaults/main.yaml b/ansible/roles/firefox/defaults/main.yaml index 8d2125a..98a8840 100644 --- a/ansible/roles/firefox/defaults/main.yaml +++ b/ansible/roles/firefox/defaults/main.yaml @@ -28,7 +28,7 @@ firefox_config: # Disable that websites can get notifications if you copy, paste, or cut something from a web page, and it lets them know which part of the page had been selected. # # This breaks copying from BigQuery https://github.com/microsoft/monaco-editor/issues/1540 - dom.event.clipboardevents.enabled: false + # dom.event.clipboardevents.enabled: false # Isolates all browser identifier sources (e.g. cookies) to the first party domain, with the goal of preventing tracking across different domains. privacy.firstparty.isolate: true # Do not preload URLs that auto-complete in the address bar. diff --git a/ansible/roles/framework_laptop/tasks/linux.yaml b/ansible/roles/framework_laptop/tasks/linux.yaml index 82a08f8..e515777 100644 --- a/ansible/roles/framework_laptop/tasks/linux.yaml +++ b/ansible/roles/framework_laptop/tasks/linux.yaml @@ -96,4 +96,5 @@ package: name: - fw-ectool-git + - wireless-regdb state: present diff --git a/ansible/roles/jail/files/jails/dagger.conf b/ansible/roles/jail/files/jails/dagger.conf index f7b6fb9..060642c 100644 --- a/ansible/roles/jail/files/jails/dagger.conf +++ b/ansible/roles/jail/files/jails/dagger.conf @@ -6,6 +6,8 @@ dagger { exec.prestart += "/usr/local/bin/jail_netgraph_bridge start cloak ${name} 192.168.1.0/24"; exec.poststop += "sleep 10; /usr/local/bin/jail_netgraph_bridge stop cloak ${name}"; + devfs_ruleset = 15; + mount.devfs; mount.fstab = "/etc/fstab.${name}"; exec.start += "/bin/sh /etc/rc"; diff --git a/ansible/roles/media/files/cast_file_vaapi b/ansible/roles/media/files/cast_file_vaapi index e972a8d..9c41665 100644 --- a/ansible/roles/media/files/cast_file_vaapi +++ b/ansible/roles/media/files/cast_file_vaapi @@ -4,7 +4,23 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +: ${VIDEO_BITRATE:="1M"} # Only for encoding modes targeting bitrate +: ${AUDIO_BITRATE:="192k"} +############## Setup ######################### + +function die { + local status_code="$1" + shift + (>&2 echo "${@}") + exit "$status_code" +} + +function log { + (>&2 echo "${@}") +} + +############## Program ######################### function main { local cmd @@ -12,28 +28,10 @@ function main { 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" = "convert" ]; then + convert "${@}" + elif [ "$cmd" = "stream" ]; then + stream "${@}" elif [ "$cmd" = "webcam" ]; then webcam "${@}" elif [ "$cmd" = "encode_webcam" ]; then @@ -64,286 +62,106 @@ function copy { "rtsp://$USERNAME:$PASSWORD@172.16.16.251:8554/fetch" } - - -function av1 { - # local additional_flags=() - # additional_flags+=(--profile "$PROFILE") - # (cd "$DIR/../" && cargo build --no-default-features "${additional_flags[@]}") - - local destination_type="$1" # "stream" or "preprocess" - local acceleration_type="$2" # "software" or "hardware" - # shift 2 - +function convert { local args=() + local acceleration_type="$1" # "software" or "hardware" + local codec="$2" # "h264" or "av1" + local file_to_cast="$3" + local file_to_save="$4" - if [ "$destination_type" == "stream" ]; then - args+=(-re -stream_loop -1) - elif [ "$destination_type" == "preproces" ]; then + + + # Verify parameters + + + if [ "$acceleration_type" == "software" ]; then + true + elif [ "$acceleration_type" == "hardware" ]; then true else - (>&2 echo "Unknown destination type: $destination_type") - exit 1 + die 1 "Unknown acceleration type: $acceleration_type" fi + if [ "$codec" == "h264" ]; then + true + elif [ "$codec" == "av1" ]; then + true + else + die 1 "Unknown codec: $codec" + fi + + + + # Build command + + + 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 + if [ "$codec" == "h264" ]; then + if [ "$acceleration_type" == "software" ]; then + args+=(-c:v h264) + args+=(-profile:v high) + args+=(-b:v "$VIDEO_BITRATE") + elif [ "$acceleration_type" == "hardware" ]; then + args+=(-vf 'format=nv12|vaapi,hwupload') + args+=(-c:v h264_vaapi) + args+=(-profile:v high) + args+=(-b:v "$VIDEO_BITRATE") + fi + elif [ "$codec" == "av1" ]; then + if [ "$acceleration_type" == "software" ]; then + args+=(-c:v libsvtav1) + args+=(-preset 4) # [0-13] default 10, lower = higher quality / slower encode + args+=(-crf 20) # [0-63] default 35, lower = higher quality / larger file + # Parameters: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Parameters.md + # fast-decode [0-2] default 0 (off), higher = faster decode + # tune [0-2] default 1, Specifies whether to use PSNR or VQ as the tuning metric [0 = VQ, 1 = PSNR, 2 = SSIM] + # film-grain-denoise, setting to 0 uses the original frames instead of denoising the film grain + args+=(-svtav1-params "fast-decode=1:film-grain-denoise=0") + elif [ "$acceleration_type" == "hardware" ]; then + # -c:v av1_amf -quality quality + args+=(-vf 'format=nv12|vaapi,hwupload') + args+=(-c:v av1_vaapi) + args+=(-b:v "$VIDEO_BITRATE") + fi fi - args+=(-b:v 2M) - args+=(-profile:v high) + + + # -bf 0 :: Disable b-frames because webrtc doesn't support h264 streams with b-frames. args+=(-bf 0) args+=(-strict -2) args+=(-c:a opus) args+=(-ac 2) - args+=(-b:a 320k) + args+=(-b:a "$AUDIO_BITRATE") 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 + args+=("$file_to_save") + set -x +