This commit is contained in:
Ali Furkan Yıldız 2023-01-11 19:44:42 +03:00
parent 17f5644673
commit c0d8763d0b
3 changed files with 170 additions and 2 deletions

View file

@ -8,5 +8,5 @@ All code is licensed under GPL-3.0 unless specified otherwise.
| C | Bash | JS | | C | Bash | JS |
| ---------------------- | :-------------------------: | --- | | ---------------------- | :-------------------------: | --- |
| [unlink.c](c/unlink.c) | [arshit](shell/bash/arshit) | | | [unlink.c](c/unlink.c) | [avt](shell/bash/avt) | |
| [cecho.c](c/cecho.c) | | | | [cecho.c](c/cecho.c) | [arshit](shell/bash/arshit) | |

36
shell/bash/avt/README.md Normal file
View file

@ -0,0 +1,36 @@
# avt: ali's (h264) video tool
avt: ali's (h264) video tool
Usage: ./avt rec|record
./avt nvid|normalize
./avt help
Environment variables:
avt_cl: enable opencl [set to enable]
Commands:
./avt rec / record
Record screen and audio in very high quality
Usage: ./avt rec [output directory]
Enviroment variables:
rec_fps: set framerate (default: 60)
rec_res: set resolution (default: 1920x1080)
rec_crf: set crf, use 0 for lossless (default: 6)
rec_adev: set pulseaudio source devices (default: default and first running monitor) [array]
rec_ar: set audio samplerate (default: 192000)
rec_normalize: immediately start nvid after recording ends [set to enable]
./avt nvid / normalize
Normalize and compress video & audio
Usage: ./avt nvid <file> [outfile]
Environment variables:
nvid_preset: set preset (default: veryslow)
nvid_vrate: replace -crf options
nvid_crf: set crf value (default: 21)
nvid_rgb: use libx264rgb [set to enable]
nvid_pixfmt: set pixel format (default: yuv420p)
nvid_profile: set profile (default: high)
nvid_ac: set audio codec (default: aac)
nvid_ba: set audio bitrate (default: 160k)
nvid_ar: set audio samplerate (default: 48000)

132
shell/bash/avt/avt Executable file
View file

@ -0,0 +1,132 @@
#!/usr/bin/env bash
# avt: ali's (h264) vid tool
# Licensed under GPL-3.0, see the end of file for details
# https://gitlab.com/alifurkany/snippets/-/blob/main/shell/bash/avt
print_help() {
cat <<EOF
avt: ali's (h264) video tool
Usage: $0 rec|record
$0 nvid|normalize
$0 help
Environment variables:
avt_cl: enable opencl [set to enable]
Commands:
$0 rec / record
Record screen and audio in very high quality
Usage: $0 rec
Enviroment variables:
rec_out: set output file (default: $HOME/Desktop/$(date +%F_%H-%M-%S).mkv)
rec_fps: set framerate (default: 60)
rec_res: set resolution (default: 1920x1080)
rec_crf: set crf, use 0 for lossless (default: 6)
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
rec_ar: set audio samplerate (default: 192000)
rec_normalize: immediately start nvid after recording ends [set to enable]
$0 nvid / normalize
Normalize and compress video & audio
Usage: $0 nvid <file> [outfile]
Environment variables:
nvid_preset: set preset (default: veryslow)
nvid_vrate: replace -crf options
nvid_crf: set crf value (default: 21)
nvid_rgb: use libx264rgb [set to enable]
nvid_pixfmt: set pixel format (default: yuv420p)
nvid_profile: set profile (default: high)
nvid_ac: set audio codec (default: aac)
nvid_ba: set audio bitrate (default: 160k)
nvid_ar: set audio samplerate (default: 48000)
EOF
}
record() {
# shellcheck disable=SC2206
devices=(${rec_adev:-"default" "$(pactl list sinks | perl -e '
my $in = "";
while (<>) { $in .= $_; }
my @sinks = split("\n\n", $in);
foreach (@sinks) {
if (/State: RUNNING/) {
/Monitor Source: ([^\n]*)/;
print $1 . "\n";
exit;
}
}
')"})
# shellcheck disable=SC2206
# remove empty elements from array
devices=(${devices[@]});
pulse_inputs=""
audio_maps=""
audio_filter=""
i=0
for device in "${devices[@]}"; do
i=$(("$i" + 1))
pulse_inputs="$pulse_inputs -f pulse -i $device"
audio_maps="$audio_maps -map $i:a"
audio_filter="$audio_filter""[$i]"
done
audio_filter="$audio_filter amix=inputs=$i [merged]"
OUTPUTFILE="${1:-$HOME/Desktop/$(date +%F_%H-%M-%S).mkv}"
echo "Saving to $OUTPUTFILE"
# shellcheck disable=SC2086
ffmpeg -y -thread_queue_size 64 \
-f x11grab -r "${rec_fps:-60}" -s "${rec_res:-1920x1080}" -i :0 \
$pulse_inputs \
-filter_complex "$audio_filter" \
-c:a pcm_s16le -ar "${rec_ar:-192000}" \
-c:v libx264rgb -x264opts opencl -profile:v high444 -crf "${rec_crf:-4}" -tune film -preset ultrafast -r 60 \
-map 0:v $audio_maps -map '[merged]:a' \
"$OUTPUTFILE"
EXITCODE=$?
if { [[ "$EXITCODE" == 0 ]] || [[ "$EXITCODE" == 255 ]]; } && [[ "${rec_normalize+x}" == "x" ]]; then
normalize "$OUTPUTFILE"
return $?
else
return $EXITCODE
fi
}
normalize() {
OUTPUTFILE="${2:-n_$(grep -oP '^.+(?=\..+)' <<<"$1").mp4}"
echo "Saving to $OUTPUTFILE"
ffmpeg -y \
${nvid_cl+-hwaccel opencl} -i "$1" \
${nvid_cl+-init_hw_device opencl=ocl -filter_hw_device ocl} \
-c:v libx264${nvid_rgb+rgb} ${nvid_cl+-x264opts opencl} -preset "${nvid_preset:-veryslow}" ${nvid_vrate:--crf "${nvid_crf:-21}"} \
-pix_fmt "${nvid_pixfmt:-yuv420p}" -profile:v "${nvid_profile:-high}" \
-c:a "${nvid_ac:-aac}" -b:a "${nvid_ba:-160k}" -ar "${nvid_ar:-48000}" \
-map 0 \
"$OUTPUTFILE"
return $?
}
case "$1" in
rec | record)
# shellcheck disable=SC2068
record ${@:2}
;;
nvid | normalize)
# shellcheck disable=SC2068
normalize ${@:2}
;;
help)
print_help
;;
*)
echo "$0: Error: No command specified. See \`$0 help\` for more details."
false
;;
esac
exit $?