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 nvid|normalize
|
||||||
./avt help
|
./avt help
|
||||||
Environment variables:
|
Environment variables:
|
||||||
avt_cl: enable opencl [set to enable]
|
avt_debug: print every command before running [set to enable]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
./avt rec / record
|
./avt rec / record
|
||||||
Record screen and audio in very high quality
|
Record screen and audio in very high quality
|
||||||
Usage: ./avt rec [output directory]
|
Usage: ./avt rec
|
||||||
Enviroment variables:
|
Enviroment variables:
|
||||||
rec_out: set output file (default: $HOME/Desktop/$(date +%F_%H-%M-%S).mkv)
|
rec_out: set output file (default: $HOME/Desktop/$(date +%F_%H-%M-%S).mkv)
|
||||||
rec_fps: set framerate (default: 60)
|
rec_fps: set framerate (default: 60)
|
||||||
|
@ -21,11 +21,19 @@
|
||||||
rec_crf: set crf, use 0 for lossless (default: 10)
|
rec_crf: set crf, use 0 for lossless (default: 10)
|
||||||
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
||||||
rec_ar: set audio samplerate (default: 96000)
|
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
|
./avt nvid / normalize
|
||||||
Normalize and compress video & audio
|
Normalize video & audio for backwards compatibility and lower file size
|
||||||
Usage: ./avt nvid <file> [outfile]
|
Usage: ./avt nvid <file> [outfile]
|
||||||
Environment variables:
|
Environment variables:
|
||||||
nvid_preset: set preset (default: veryslow)
|
nvid_preset: set preset (default: veryslow)
|
||||||
|
@ -37,6 +45,8 @@
|
||||||
nvid_ac: set audio codec (default: libopus)
|
nvid_ac: set audio codec (default: libopus)
|
||||||
nvid_ba: set audio bitrate (default: 160k)
|
nvid_ba: set audio bitrate (default: 160k)
|
||||||
nvid_ar: set audio samplerate (default: 48000)
|
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
|
# Dependencies
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,29 @@
|
||||||
# avt: ali's (h264) vid tool
|
# avt: ali's (h264) vid tool
|
||||||
# https://gitlab.com/alifurkany/snippets/-/tree/main/shell/bash/avt
|
# 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() {
|
print_help() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
avt: ali's (h264) video tool
|
avt: ali's (h264) video tool
|
||||||
|
@ -10,7 +33,7 @@ Usage: $0 rec|record
|
||||||
$0 nvid|normalize
|
$0 nvid|normalize
|
||||||
$0 help
|
$0 help
|
||||||
Environment variables:
|
Environment variables:
|
||||||
avt_cl: enable opencl [set to enable]
|
avt_debug: print every command before running [set to enable]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
|
@ -26,7 +49,16 @@ rec_vrate: replace -crf options
|
||||||
rec_crf: set crf, use 0 for lossless (default: 10)
|
rec_crf: set crf, use 0 for lossless (default: 10)
|
||||||
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
rec_adev: space separated pulseaudio source devices (default: default and first running monitor)
|
||||||
rec_ar: set audio samplerate (default: 96000)
|
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
|
$0 nvid / normalize
|
||||||
Normalize video & audio for backwards compatibility and lower file size
|
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_ac: set audio codec (default: libopus)
|
||||||
nvid_ba: set audio bitrate (default: 160k)
|
nvid_ba: set audio bitrate (default: 160k)
|
||||||
nvid_ar: set audio samplerate (default: 48000)
|
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
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
record() {
|
record() {
|
||||||
# shellcheck disable=SC2206
|
# shellcheck disable=SC2206
|
||||||
devices=(${rec_adev:-"default" "$(pactl list sinks | perl -e '
|
devices=(${rec_adev-"$(findmonitor)" "default"})
|
||||||
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
|
# shellcheck disable=SC2206
|
||||||
# remove empty elements from array
|
# remove empty elements from array
|
||||||
devices=(${devices[@]})
|
devices=(${devices[@]})
|
||||||
|
@ -71,7 +94,12 @@ foreach (@sinks) {
|
||||||
audio_maps="$audio_maps -map $i:a"
|
audio_maps="$audio_maps -map $i:a"
|
||||||
audio_filter="$audio_filter""[$i]"
|
audio_filter="$audio_filter""[$i]"
|
||||||
done
|
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}"
|
OUTPUTFILE="${1:-$HOME/Desktop/$(date +%F_%H-%M-%S).mkv}"
|
||||||
echo "Saving to $OUTPUTFILE"
|
echo "Saving to $OUTPUTFILE"
|
||||||
|
@ -79,31 +107,43 @@ foreach (@sinks) {
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
ffmpeg -y -thread_queue_size 64 \
|
ffmpeg -y -thread_queue_size 64 \
|
||||||
-f x11grab -r "${rec_fps:-60}" -s "${rec_res:-1920x1080}" -i "${rec_display:-$DISPLAY}" \
|
-f x11grab -r "${rec_fps:-60}" -s "${rec_res:-1920x1080}" -i "${rec_display:-$DISPLAY}" \
|
||||||
$pulse_inputs \
|
${an-$pulse_inputs} ${an+-an} \
|
||||||
-filter_complex "$audio_filter" \
|
${an--filter_complex "$audio_filter"} \
|
||||||
-c:a pcm_s16le -ar "${rec_ar:-96000}" \
|
${an--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} \
|
-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 -map '[merged]:a' \
|
-map 0:v $audio_maps ${an--map '[merged]:a'} \
|
||||||
"$OUTPUTFILE"
|
"$OUTPUTFILE"
|
||||||
|
|
||||||
EXITCODE=$?
|
EXITCODE=$?
|
||||||
if { [[ "$EXITCODE" == 0 ]] || [[ "$EXITCODE" == 255 ]]; } && [[ "${rec_normalize+x}" == "x" ]]; then
|
if { [[ "$EXITCODE" == 0 ]] || [[ "$EXITCODE" == 255 ]]; } && [[ "${rec_compress+x}" == "x" ]]; then
|
||||||
normalize "$OUTPUTFILE"
|
compress "$OUTPUTFILE"
|
||||||
return $?
|
return $?
|
||||||
else
|
else
|
||||||
return $EXITCODE
|
return $EXITCODE
|
||||||
fi
|
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() {
|
normalize() {
|
||||||
OUTPUTFILE="${2:-$1_n.mp4}"
|
OUTPUTFILE="${2:-$1_nvid.mp4}"
|
||||||
echo "Saving to $OUTPUTFILE"
|
echo "Saving to $OUTPUTFILE"
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
ffmpeg -y \
|
ffmpeg -y \
|
||||||
${nvid_cl+-hwaccel opencl} -i "$1" \
|
-i "$1" \
|
||||||
${nvid_cl+-init_hw_device opencl=ocl -filter_hw_device ocl} \
|
-c:v libx264${nvid_rgb+rgb} -preset "${nvid_preset:-veryslow}" ${nvid_vrate:--crf "${nvid_crf:-19}"} \
|
||||||
-c:v libx264${nvid_rgb+rgb} ${avt_cl+-x264opts opencl} -preset "${nvid_preset:-veryslow}" ${nvid_vrate:--crf "${nvid_crf:-19}"} \
|
|
||||||
-pix_fmt "${nvid_pixfmt:-yuv420p}" -profile:v "${nvid_profile:-high}" \
|
-pix_fmt "${nvid_pixfmt:-yuv420p}" -profile:v "${nvid_profile:-high}" \
|
||||||
-c:a "${nvid_ac:-libopus}" -b:a "${nvid_ba:-160k}" -ar "${nvid_ar:-48000}" \
|
-c:a "${nvid_ac:-libopus}" -b:a "${nvid_ba:-160k}" -ar "${nvid_ar:-48000}" \
|
||||||
-map 0 \
|
-map 0 \
|
||||||
|
@ -117,6 +157,11 @@ rec | record)
|
||||||
record ${@:2}
|
record ${@:2}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
comp | compress)
|
||||||
|
# shellcheck disable=SC2068
|
||||||
|
compress ${@:2}
|
||||||
|
;;
|
||||||
|
|
||||||
nvid | normalize)
|
nvid | normalize)
|
||||||
# shellcheck disable=SC2068
|
# shellcheck disable=SC2068
|
||||||
normalize ${@:2}
|
normalize ${@:2}
|
||||||
|
|
Loading…
Reference in a new issue