From 50b701c60a878d46f80a194e5806351d77d52414 Mon Sep 17 00:00:00 2001 From: nodemixaholic Date: Sun, 18 Feb 2024 16:52:15 +0000 Subject: [PATCH] Update 'sampeg.sh' --- sampeg.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/sampeg.sh b/sampeg.sh index 770ed9c..4ec6021 100644 --- a/sampeg.sh +++ b/sampeg.sh @@ -2,7 +2,7 @@ # Function to check if NVENC is supported check_nvenc_support() { - if ffmpeg -hide_banner -encoders | grep -q "h264_nvenc"; then + if ffmpeg -hide_banner -encoders 2>/dev/null | grep -qE "(nvenc|cuda)"; then echo "NVENC encoding supported" return 0 else @@ -99,6 +99,56 @@ remove_silence() { echo "Silence removed successfully" } +# Function for picture-in-picture +picture_in_picture() { + input_main="$1" + input_pip="$2" + output="$3" + x_scale="$4" + y_scale="$5" + x_position="$6" + y_position="$7" + if check_nvenc_support; then + ffmpeg -i "$input_main" -i "$input_pip" -filter_complex "[1:v]scale=$x_scale:$y_scale [pip]; [0:v][pip]overlay=$x_position:$y_position" -c:v h264_nvenc -preset medium -crf 23 -c:a aac -b:a 128k "$output" + else + ffmpeg -i "$input_main" -i "$input_pip" -filter_complex "[1:v]scale=$x_scale:$y_scale [pip]; [0:v][pip]overlay=$x_position:$y_position" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k "$output" + fi + echo "Picture-in-picture applied successfully" +} + +# Function for image stabilization +image_stabilization() { + input="$1" + output="$2" + if check_nvenc_support; then + ffmpeg -i "$input" -vf vidstabdetect=shakiness=10:accuracy=15:result=transform.trf -f null - + ffmpeg -i "$input" -vf vidstabtransform=input="transform.trf" -c:v h264_nvenc -preset medium -crf 23 -c:a aac -b:a 128k "$output" + else + ffmpeg -i "$input" -vf vidstabdetect=shakiness=10:accuracy=15:result=transform.trf -f null - + ffmpeg -i "$input" -vf vidstabtransform=input="transform.trf" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k "$output" + fi + echo "Image stabilization applied successfully" +} + +# Function to record screen with optional webcam and microphone +record_screen() { + output="$1" + webcam_flag="$2" # true or false + microphone_flag="$3" # true or false + webcam_device="/dev/video0" + microphone_device="default" + webcam_input="" + microphone_input="" + if [[ "$webcam_flag" == "true" ]]; then + webcam_input="-f v4l2 -i $webcam_device" + fi + if [[ "$microphone_flag" == "true" ]]; then + microphone_input="-f alsa -i $microphone_device" + 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 @@ -112,6 +162,9 @@ display_help() { echo " $0 trim-end " echo " $0 scale [resolution]" echo " $0 remove-silence " + echo " $0 picture-in-picture " + echo " $0 image-stabilization " + echo " $0 record-screen " } # Main script @@ -173,6 +226,27 @@ while [[ $# -gt 0 ]]; do fi remove_silence "$2" "$3" ;; + picture-in-picture) + if [[ $# -ne 8 ]]; then + echo "Usage: $0 picture-in-picture " + exit 1 + fi + picture_in_picture "$2" "$3" "$4" "$5" "$6" "$7" "$8" + ;; + image-stabilization) + if [[ $# -ne 3 ]]; then + echo "Usage: $0 image-stabilization " + exit 1 + fi + image_stabilization "$2" "$3" + ;; + record-screen) + if [[ $# -lt 2 ]]; then + echo "Usage: $0 record-screen " + exit 1 + fi + record_screen "$2" "$3" "$4" + ;; help) display_help exit 0