move avt to it's own repo

This commit is contained in:
Ali Furkan Yıldız 2023-01-12 20:06:06 +03:00
parent c149d1b32d
commit badb3e2a86
4 changed files with 3 additions and 258 deletions

View file

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

View file

@ -1,12 +0,0 @@
# 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

View file

@ -1,63 +1 @@
# avt: ali's (h264) video tool
avt: ali's (h264) video tool
Usage: ./avt rec|record
./avt comp|compress
./avt nvid|normalize
./avt help
Environment variables:
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
Enviroment variables:
rec_display: set x11 display (default: $DISPLAY)
rec_out: set output file (default: ~/Desktop/$(date +%F_%H-%M-%S).mkv)
rec_fps: set framerate (default: 60)
rec_res: set resolution (default: 1920x1080)
rec_preset: set preset (default: ultrafast)
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_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 video & audio for backwards compatibility and lower file size
Usage: ./avt nvid <file> [outfile]
Environment variables:
nvid_preset: set preset (default: veryslow)
nvid_vrate: replace -crf options
nvid_crf: set crf value (default: 19)
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: 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.
# Dependencies
- `bash`
- `ffmpeg`
- `perl`
- `pactl`
# Requirements
This assumes you use X11, PipeWire and pipewire-pulse.
You also need a pretty fast disk and a lot of free space to record with this tool with the default settings. Consider increasing [`rec_crf`](https://trac.ffmpeg.org/wiki/Encode/H.264#crf) or choosing a slower [`rec_preset`](https://trac.ffmpeg.org/wiki/Encode/H.264#Preset) if you don't have those.
# Moved to [alifurkany/avt](https://gitlab.com/alifurkany/avt)

View file

@ -1,181 +0,0 @@
#!/usr/bin/env bash
# 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
Usage: $0 rec|record
$0 comp|compress
$0 nvid|normalize
$0 help
Environment variables:
avt_debug: print every command before running [set to enable]
Commands:
$0 rec / record
Record screen and audio in very high quality
Usage: $0 rec
Enviroment variables:
rec_display: set x11 display (default: \$DISPLAY)
rec_out: set output file (default: ~/Desktop/$(date +%F_%H-%M-%S).mkv)
rec_fps: set framerate (default: 60)
rec_res: set resolution (default: 1920x1080)
rec_preset: set preset (default: ultrafast)
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_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
Usage: $0 nvid <file> [outfile]
Environment variables:
nvid_preset: set preset (default: veryslow)
nvid_vrate: replace -crf options
nvid_crf: set crf value (default: 19)
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: 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-"$(findmonitor)" "default"})
# 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
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"
# shellcheck disable=SC2086
ffmpeg -y -thread_queue_size 64 \
-f x11grab -r "${rec_fps:-60}" -s "${rec_res:-1920x1080}" -i "${rec_display:-$DISPLAY}" \
${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_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_nvid.mp4}"
echo "Saving to $OUTPUTFILE"
# shellcheck disable=SC2086
ffmpeg -y \
-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 \
"$OUTPUTFILE"
return $?
}
case "$1" in
rec | record)
# shellcheck disable=SC2068
record ${@:2}
;;
comp | compress)
# shellcheck disable=SC2068
compress ${@: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 $?