Update 'sampeg.sh'
This commit is contained in:
parent
64ebc8aadf
commit
15815c5db6
1 changed files with 103 additions and 20 deletions
119
sampeg.sh
119
sampeg.sh
|
@ -1,19 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
# SaMpeg version
|
||||
SAMPEG_VER="2.2024b"
|
||||
SAMPEG_VER="2.2024c"
|
||||
|
||||
# Function to check if NVENC is supported
|
||||
check_nvenc_support() {
|
||||
if ffmpeg -hide_banner -encoders 2>/dev/null | grep -qE "(nvenc|cuda)"; then
|
||||
if [ -e "/dev/nvidia0" ]; then
|
||||
echo "NVENC encoding supported"
|
||||
return 0
|
||||
else
|
||||
echo "No NVIDIA GPU detected. NVENC encoding not supported."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "NVENC encoding not supported"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Function to generate concat.txt from a folder
|
||||
generate_concat_file() {
|
||||
folder="$1"
|
||||
|
@ -133,45 +139,124 @@ image_stabilization() {
|
|||
echo "Image stabilization applied successfully"
|
||||
}
|
||||
|
||||
# Function to record screen with optional webcam and microphone
|
||||
# Function to record screen with optional webcam and microphone as picture-in-picture
|
||||
record_screen() {
|
||||
screen_resolution=$(xrandr | awk '/ primary/{getline; print $1}')
|
||||
output="$1"
|
||||
include_webcam="$2"
|
||||
include_microphone="$3"
|
||||
mic="$4"
|
||||
include_audio="$5"
|
||||
audio_speakers="$6"
|
||||
|
||||
# Set default webcam and microphone devices
|
||||
webcam_device="/dev/video0" # Default webcam device
|
||||
microphone_device="$(arecord -l | grep -oP '(?<=card ).*(?=:)' | head -n 1)" # Default microphone device
|
||||
if [[ "$include_webcam" == "true" ]]; then
|
||||
webcam_input="-f v4l2 -i $webcam_device"
|
||||
else
|
||||
microphone_device="$mic" # Default microphone device
|
||||
|
||||
# Set up inputs for webcam and microphone if included
|
||||
webcam_input=""
|
||||
microphone_input=""
|
||||
if [[ "$include_webcam" == "true" ]]; then
|
||||
webcam_input="-f v4l2 -thread_queue_size 64 -i $webcam_device"
|
||||
fi
|
||||
if [[ "$include_microphone" == "true" ]]; then
|
||||
microphone_input="-f alsa -i hw:$microphone_device"
|
||||
else
|
||||
microphone_input=""
|
||||
if [[ ! "$mic" == "" ]]; then
|
||||
microphone_input="-f pulse -i $mic -ac 2"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set up audio output options
|
||||
audio_output=""
|
||||
if [[ "$include_audio" == "true" ]]; then
|
||||
if [[ ! "$audio_speakers" == "" ]]; then
|
||||
audio_output="pulse -i $audio_speakers 128k -ac 1"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine screen capture method based on display server
|
||||
if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
|
||||
# Wayland screen capture
|
||||
ffmpeg -f x11grab -thread_queue_size 450 -video_size "$screen_resolution" -framerate 24 -i "$DISPLAY" $webcam_input $microphone_input \
|
||||
-filter_complex "[0:v][1:v]overlay=10:10" \
|
||||
$audio_output \
|
||||
-r 24 -preset ultrafast \
|
||||
"$output"
|
||||
else
|
||||
# X11 screen capture
|
||||
ffmpeg -f x11grab -thread_queue_size 450 -video_size "$screen_resolution" -framerate 24 -i :0.0 $webcam_input $microphone_input \
|
||||
-filter_complex "[0:v][1:v]overlay=10:10" \
|
||||
$audio_output \
|
||||
-r 24 -preset ultrafast \
|
||||
"$output"
|
||||
fi
|
||||
ffmpeg -f x11grab -video_size 1920x1080 -framerate 30 -i :0.0 $webcam_input $microphone_input -c:v h264_nvenc -preset medium -crf 23 -c:a aac -b:a 128k "$output"
|
||||
echo "Screen recorded successfully"
|
||||
}
|
||||
|
||||
# Function to display help message
|
||||
display_help() {
|
||||
toilet SaMpeg
|
||||
echo "Version $SAMPEG_VER"
|
||||
# Function to display the SaMpeg header
|
||||
display_header() {
|
||||
toilet -f pagga -F gay "SaMpeg"
|
||||
echo "The video fusing interface."
|
||||
echo "Powered by FFmpeg."
|
||||
echo "------------"
|
||||
}
|
||||
|
||||
# Function to display the command list
|
||||
display_commands() {
|
||||
echo "Usage:"
|
||||
echo " $0 generate-concat-file <folder> <output>"
|
||||
echo " Generates a concat.txt file from a folder containing video files."
|
||||
|
||||
echo " $0 combine-using-concat-file <concat_file> <output> [resolution]"
|
||||
echo " Combines video clips using the concat file and scales them to the specified resolution."
|
||||
|
||||
echo " $0 crop <input> <output> <width> <height> <x_position> <y_position>"
|
||||
echo " Crops a video clip to the specified dimensions and position."
|
||||
|
||||
echo " $0 trim-beginning <input> <output> <start_time>"
|
||||
echo " Trims the beginning of a video clip starting from the specified time."
|
||||
|
||||
echo " $0 trim-end <input> <output> <end_time>"
|
||||
echo " Trims the end of a video clip ending at the specified time."
|
||||
|
||||
echo " $0 scale <input> <output> [resolution]"
|
||||
echo " Scales a video clip to the specified resolution."
|
||||
|
||||
echo " $0 remove-silence <input> <output>"
|
||||
echo " Removes parts of the video clip without audio."
|
||||
|
||||
echo " $0 picture-in-picture <input_main> <input_pip> <output> <x_scale> <y_scale> <x_position> <y_position>"
|
||||
echo " Places a smaller video (picture-in-picture) onto a larger video."
|
||||
|
||||
echo " $0 image-stabilization <input> <output>"
|
||||
echo " $0 record-screen <output> [include_webcam] [include_microphone]"
|
||||
echo " Stabilizes the video to reduce shaking."
|
||||
|
||||
echo " $0 record-screen <output> [include_webcam] [include_microphone] [mic] [include_audio] [audioout]"
|
||||
echo " Records the screen with optional webcam, microphone, and desktop audio."
|
||||
echo " [include_webcam]: true/false, [include_microphone]: true/false, [mic]: microphone device, [include_audio]: true/false, [audioout]: audio output device."
|
||||
|
||||
echo " $0 set-brightness <input> <output> <brightness_value>"
|
||||
echo " Adjusts the brightness of the video. The value ranges from 0 to 1."
|
||||
|
||||
echo " $0 set-hue <input> <output> <hue_value>"
|
||||
echo " Adjusts the hue of the video. The value ranges from 0 to 1."
|
||||
|
||||
echo " $0 set-contrast <input> <output> <contrast_value>"
|
||||
echo " Adjusts the contrast of the video. The value ranges from 0 to 1."
|
||||
|
||||
echo " $0 help"
|
||||
echo " Displays this help message."
|
||||
}
|
||||
|
||||
|
||||
# Function to display help message
|
||||
display_help() {
|
||||
display_header
|
||||
display_commands
|
||||
echo "------------------"
|
||||
echo Your possible output device:
|
||||
pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2 | grep ".monitor"
|
||||
echo Your possible input devices:
|
||||
pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2 | grep -v ".monitor"
|
||||
}
|
||||
|
||||
# Main script
|
||||
|
@ -249,7 +334,7 @@ while [[ $# -gt 0 ]]; do
|
|||
;;
|
||||
record-screen)
|
||||
if [[ $# -lt 2 ]]; then
|
||||
echo "Usage: $0 record-screen <output> [include_webcam] [include_microphone]"
|
||||
echo "Usage: $0 record-screen <output> [include_webcam] [include_microphone] [mic] [include_audio] [audioout]"
|
||||
exit 1
|
||||
fi
|
||||
record_screen "$2" "$3" "$4"
|
||||
|
@ -259,8 +344,6 @@ while [[ $# -gt 0 ]]; do
|
|||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: $option"
|
||||
display_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue