Added
- findmonitor function - example resource file - automatic sourcing of said resource file - avt_debug - compress command - automatic disabling of sound Changed - rec_normalize to rec_compress Removed - avt_cl
This commit is contained in:
parent
f19427da23
commit
5f3b445d79
3 changed files with 101 additions and 34 deletions
12
shell/bash/avt/.avtrc
Normal file
12
shell/bash/avt/.avtrc
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Example .avtrc file
|
||||
#avt_debug=
|
||||
rec_fps=60
|
||||
rec_res=1920x1080
|
||||
rec_ar=48000
|
||||
rec_crf=12
|
||||
rec_adev="$(findmonitor) default"
|
||||
#rec_adev="$(findmonitor)"
|
||||
#rec_adev="default"
|
||||
#rec_adev=
|
||||
comp_crf=16
|
||||
comp_ba=160k
|
|
@ -5,13 +5,13 @@
|
|||
./avt nvid|normalize
|
||||
./avt help
|
||||
Environment variables:
|
||||
avt_cl: enable opencl [set to enable]
|
||||
avt_debug: print every command before running [set to enable]
|
||||
|
||||
Commands:
|
||||
|
||||
./avt rec / record
|
||||
Record screen and audio in very high quality
|
||||
Usage: ./avt rec [output directory]
|
||||
Usage: ./avt rec
|
||||
Enviroment variables:
|
||||
rec_out: set output file (default: $HOME/Desktop/$(date +%F_%H-%M-%S).mkv)
|
||||
rec_fps: set framerate (default: 60)
|
||||
|
@ -21,11 +21,19 @@
|
|||
rec_crf: set crf, use 0 for lossless (default: 10)
|
||||
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
||||
rec_ar: set audio samplerate (default: 96000)
|
||||
rec_normalize: immediately start nvid after recording ends [set to enable]
|
||||
rec_compress: immediately start comp after recording ends [set to enable]
|
||||
|
||||
./avt comp / compress
|
||||
Compress a recording without losing any video quality and noticeable audio quality
|
||||
Usage: ./avt comp <file> [outfile]
|
||||
Environment variables:
|
||||
comp_crf: set crf, this should be greater than or equals to rec_crf (default: 10)
|
||||
comp_ac: set audio codec (default: libopus)
|
||||
comp_ba: set audio bitrate (default: 320k)
|
||||
comp_ar: set audio samplerate, this should be less than or equals to rec_ar (default: 96000)
|
||||
|
||||
./avt nvid / normalize
|
||||
Normalize and compress video & audio
|
||||
Normalize video & audio for backwards compatibility and lower file size
|
||||
Usage: ./avt nvid <file> [outfile]
|
||||
Environment variables:
|
||||
nvid_preset: set preset (default: veryslow)
|
||||
|
@ -38,6 +46,8 @@
|
|||
nvid_ba: set audio bitrate (default: 160k)
|
||||
nvid_ar: set audio samplerate (default: 48000)
|
||||
|
||||
avt will try to source ~/.avtrc if it exists. You have access to the findmonitor function in there.
|
||||
|
||||
# Dependencies
|
||||
|
||||
- `bash`
|
||||
|
|
|
@ -3,6 +3,29 @@
|
|||
# avt: ali's (h264) vid tool
|
||||
# https://gitlab.com/alifurkany/snippets/-/tree/main/shell/bash/avt
|
||||
|
||||
findmonitor() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
'
|
||||
return $?
|
||||
}
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
[ -e "$HOME/.avtrc" ] && . "$HOME/.avtrc"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
# DEBUG variable not in use yet
|
||||
[[ ${avt_debug+x} == "x" ]] && set -x && DEBUG=1
|
||||
|
||||
print_help() {
|
||||
cat <<EOF
|
||||
avt: ali's (h264) video tool
|
||||
|
@ -10,7 +33,7 @@ Usage: $0 rec|record
|
|||
$0 nvid|normalize
|
||||
$0 help
|
||||
Environment variables:
|
||||
avt_cl: enable opencl [set to enable]
|
||||
avt_debug: print every command before running [set to enable]
|
||||
|
||||
Commands:
|
||||
|
||||
|
@ -26,7 +49,16 @@ rec_vrate: replace -crf options
|
|||
rec_crf: set crf, use 0 for lossless (default: 10)
|
||||
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
||||
rec_ar: set audio samplerate (default: 96000)
|
||||
rec_normalize: immediately start nvid after recording ends [set to enable]
|
||||
rec_compress: immediately start comp after recording ends [set to enable]
|
||||
|
||||
$0 comp / compress
|
||||
Compress a recording without losing any video quality and noticeable audio quality
|
||||
Usage: $0 comp <file> [outfile]
|
||||
Environment variables:
|
||||
comp_crf: set crf, this should be greater than or equals to rec_crf (default: ${rec_crf:-10})
|
||||
comp_ac: set audio codec (default: libopus)
|
||||
comp_ba: set audio bitrate (default: 320k)
|
||||
comp_ar: set audio samplerate, this should be less than or equals to rec_ar (default: ${rec_ar:-96000})
|
||||
|
||||
$0 nvid / normalize
|
||||
Normalize video & audio for backwards compatibility and lower file size
|
||||
|
@ -41,23 +73,14 @@ nvid_profile: set profile (default: high)
|
|||
nvid_ac: set audio codec (default: libopus)
|
||||
nvid_ba: set audio bitrate (default: 160k)
|
||||
nvid_ar: set audio samplerate (default: 48000)
|
||||
|
||||
avt will try to source ~/.avtrc if it exists. You have access to the findmonitor function in there.
|
||||
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;
|
||||
}
|
||||
}
|
||||
')"})
|
||||
devices=(${rec_adev-"$(findmonitor)" "default"})
|
||||
# shellcheck disable=SC2206
|
||||
# remove empty elements from array
|
||||
devices=(${devices[@]})
|
||||
|
@ -71,7 +94,12 @@ foreach (@sinks) {
|
|||
audio_maps="$audio_maps -map $i:a"
|
||||
audio_filter="$audio_filter""[$i]"
|
||||
done
|
||||
audio_filter="$audio_filter amix=inputs=$i [merged]"
|
||||
if [[ "$i" -gt 1 ]]; then
|
||||
audio_filter="$audio_filter amix=inputs=$i [merged]"
|
||||
else
|
||||
an=
|
||||
echo "Audio recording disabled"
|
||||
fi
|
||||
|
||||
OUTPUTFILE="${1:-$HOME/Desktop/$(date +%F_%H-%M-%S).mkv}"
|
||||
echo "Saving to $OUTPUTFILE"
|
||||
|
@ -79,31 +107,43 @@ foreach (@sinks) {
|
|||
# shellcheck disable=SC2086
|
||||
ffmpeg -y -thread_queue_size 64 \
|
||||
-f x11grab -r "${rec_fps:-60}" -s "${rec_res:-1920x1080}" -i "${rec_display:-$DISPLAY}" \
|
||||
$pulse_inputs \
|
||||
-filter_complex "$audio_filter" \
|
||||
-c:a pcm_s16le -ar "${rec_ar:-96000}" \
|
||||
-c:v libx264rgb ${avt_cl+-x264opts opencl} -profile:v high444 -preset "${rec_preset:-ultrafast}" ${rec_vrate:--crf "${rec_crf:-10}"} -tune zerolatency -r ${rec_fps:-60} \
|
||||
-map 0:v $audio_maps -map '[merged]:a' \
|
||||
${an-$pulse_inputs} ${an+-an} \
|
||||
${an--filter_complex "$audio_filter"} \
|
||||
${an--c:a pcm_s16le -ar "${rec_ar:-96000}"} \
|
||||
-c:v libx264rgb -profile:v high444 -preset "${rec_preset:-ultrafast}" ${rec_vrate:--crf "${rec_crf:-10}"} -tune zerolatency -r ${rec_fps:-60} \
|
||||
-map 0:v $audio_maps ${an--map '[merged]:a'} \
|
||||
"$OUTPUTFILE"
|
||||
|
||||
EXITCODE=$?
|
||||
if { [[ "$EXITCODE" == 0 ]] || [[ "$EXITCODE" == 255 ]]; } && [[ "${rec_normalize+x}" == "x" ]]; then
|
||||
normalize "$OUTPUTFILE"
|
||||
if { [[ "$EXITCODE" == 0 ]] || [[ "$EXITCODE" == 255 ]]; } && [[ "${rec_compress+x}" == "x" ]]; then
|
||||
compress "$OUTPUTFILE"
|
||||
return $?
|
||||
else
|
||||
return $EXITCODE
|
||||
fi
|
||||
}
|
||||
|
||||
compress() {
|
||||
OUTPUTFILE="${2:-$1_comp.mp4}"
|
||||
echo "Saving to $OUTPUTFILE"
|
||||
|
||||
ffmpeg -y -thread_queue_size 64 \
|
||||
-i "$1" \
|
||||
-c:v libx264rgb -pix_fmt rgb24 -profile:v high444 -crf "${comp_crf:-${rec_crf:-10}}" -preset veryslow \
|
||||
-c:a "${comp_ac:-libopus}" -b:a "${comp_ba:-320k}" -ar "${comp_ar:-${rec_ar:-96000}}" \
|
||||
-map 0 \
|
||||
"$OUTPUTFILE"
|
||||
return $?
|
||||
}
|
||||
|
||||
normalize() {
|
||||
OUTPUTFILE="${2:-$1_n.mp4}"
|
||||
OUTPUTFILE="${2:-$1_nvid.mp4}"
|
||||
echo "Saving to $OUTPUTFILE"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
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} ${avt_cl+-x264opts opencl} -preset "${nvid_preset:-veryslow}" ${nvid_vrate:--crf "${nvid_crf:-19}"} \
|
||||
-i "$1" \
|
||||
-c:v libx264${nvid_rgb+rgb} -preset "${nvid_preset:-veryslow}" ${nvid_vrate:--crf "${nvid_crf:-19}"} \
|
||||
-pix_fmt "${nvid_pixfmt:-yuv420p}" -profile:v "${nvid_profile:-high}" \
|
||||
-c:a "${nvid_ac:-libopus}" -b:a "${nvid_ba:-160k}" -ar "${nvid_ar:-48000}" \
|
||||
-map 0 \
|
||||
|
@ -117,6 +157,11 @@ rec | record)
|
|||
record ${@:2}
|
||||
;;
|
||||
|
||||
comp | compress)
|
||||
# shellcheck disable=SC2068
|
||||
compress ${@:2}
|
||||
;;
|
||||
|
||||
nvid | normalize)
|
||||
# shellcheck disable=SC2068
|
||||
normalize ${@:2}
|
||||
|
|
Loading…
Reference in a new issue