bash scripts

This commit is contained in:
Lucas Faber authored and Lucas Vivohost committed 2026-09-14 09:20:47 +02:00
1 parent 7ed4fc67d5
commit 7db38ae9f4
25 files changed
+2375

No files matched your search

+183
View File
@@ -0,0 +1,183 @@
#!/bin/bash
set -e
usage(){
printf "Usage:
-i <file>\tInfo
-av <file>\tChange Audio and Video Codec
-v <file>\tChange Video Codec
-a <file>\tChange Audio Codec
-s <file>\tRemove Subtitles
-rm <file>\tRemove First Audio
-subs <file>\tEmbed subtitles
-dir_down\tDownsize all files in dir to 1920x1080
-find\tFind files from file and resize
-d <file>\tDownsize input video
-filter <file> filter video file\n"
}
if [ $# -lt 2 ]; then
echo "Too few arguments <file> <part of filename to remove>"
else
if [ -d "$2" ] || [ ]; then
echo "Argument is directory"
input_dir=$2
elif [ -f "$2" ]; then
echo "Argument is file"
input=$2
else
echo "Argument $2 doesnt exist"
exit
fi
if [ "$1" == "-av" ]; then
ffmpeg -i "$input" -vcodec mpeg4 -acodec mp3 -preset veryslow -qp 0 "_$input"
elif [ "$1" == "-s" ]; then
ffmpeg -i "$input" -sn -c copy "_$input"
elif [ "$1" == "-a" ]; then
ffmpeg -i "$input" -vcodec copy -acodec mp3 -preset veryslow -qp 0 "_$input"
elif [ "$1" == "-v" ]; then
ffmpeg -i "$input" -vcodec mpeg4 -preset veryslow -qp 0 -acodec copy "_$input"
elif [ "$1" == "-rm" ]; then
ffmpeg -i "$input" -map 0 -map -0:a:0 -c copy -y "_$input";
# mv "_$file" "$file";
echo $input
elif [ "$1" == "-i" ]; then
ffmpeg -i "$input"
elif [ "$1" == "-d" ]; then
ffmpeg -i "$input" -c:v libx264 -crf 27 "${input%%.*}_downsize.${input##*.}"
elif [ "$1" == "-subs" ]; then
#for file in *${input}; do ls "subs/$(echo $file | rev | cut -f2- -d'.' | rev).srt" ; done
for file in *${input}; do
ls "$(echo $file | rev | cut -f2- -d'.' | rev).srt"
ffmpeg -i "$file" -f srt -i "$(echo $file | rev | cut -f2- -d'.' | rev).srt" -c copy -c:s mov_text "_$file"
mv "_$file" "$file"
done
elif [ "$1" == "-frame" ]; then
ffmpeg -ss 00:00:05.01 -i myvideo.avi -frames:v 1 myimage.jpg
elif [ "$1" == "-cut" ]; then
ffmpeg -ss 00:00:02 -i GMT20210112-071517_Vorlesung-_1920x1220.mp4 -to 01:28:49 -c copy output.mp4
elif [ "$1" == "-dir-down" ]; then
echo "Resize all files in ${input_dir}"
if [ ! -d "${input_dir}/comp" ];then
mkdir "${input_dir}/comp"
fi
for file in ${input_dir}/*; do
if [ -f "${file}" ]; then
#echo ${file%.*} ${file##*.} ${file##*/}
ffmpeg -i "${file}" -vf scale=1920x1080 "${input_dir}/comp/${file##*/}" 2>/dev/null 1>&2
fi
done
elif [ "$1" == "-find" ]; then
echo "Find files in ${input_dir}"
if [ ! -d "${input_dir}/comp" ];then
mkdir ${input_dir}/comp
fi
while read -r line; do
file=$(find . -name "$line")
if [ -f "${file}" ]; then
#echo ${file%.*}
#echo ${file%/*}
#echo ${file##*.}
ffmpeg -i "${file}" -vf scale=1920x1080 "${input_dir}/comp/${file##*/}"
fi
done<$3
echo "Converted all files in ${input_dir}"
elif [ "$1" == "-file2mp3" ]; then
codec=$3
find "${input_dir}" -name "*$codec" -print0 | while read -d $'\0' file; do
#echo $file
echo ${file%.*}
#ffmpeg -i "$file" -sample_fmt s16 -ar 48000 "${file%.*}_.flac"< /dev/null
#mv "${file%.*}_.flac" "$file"
ffmpeg -i "$file" -vn -ar 44100 -ac 2 -b:a 192k "${file%.*}.mp3"< /dev/null
#ffmpeg -i "$file" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%.*}.mp3"< /dev/null
done
elif [ "$1" == "-filter" ]; then
#!/usr/bin/env bash
file="$2"
selected_stream="$3"
file_new="${file%.*}_processed.${file##*.}"
if [[ -z "$file" ]]; then
echo "Usage: $0 input_file [audio_stream_index]"
exit 1
fi
# Get list of audio streams
mapfile -t streams < <(
ffprobe -v error -select_streams a \
-show_entries stream=index:stream_tags=language \
-of json "$file" |
jq -r '.streams[] | "\(.index),\(.tags.language // "unknown")"'
)
stream_count=${#streams[@]}
if [[ "$stream_count" -eq 0 ]]; then
echo "No audio streams found."
exit 1
fi
echo "Found $stream_count audio stream(s)."
# If not provided, prompt when multiple exist
if [[ -z "$selected_stream" ]]; then
if [[ "$stream_count" -eq 1 ]]; then
selected_stream="${streams[0]%,*}"
echo "Using only audio stream: $selected_stream"
else
echo "Available audio streams:"
i=0
for s in "${streams[@]}"; do
idx="${s%,*}"
lang="${s#*,}"
echo "[$i] stream_index=$idx language=${lang:-unknown}"
((i++))
done
read -rp "Select audio stream index (ffmpeg stream index): " selected_stream
fi
fi
echo "Processing audio stream: $selected_stream"
ffmpeg -i "$file" \
-map 0:v -c:v copy \
-map 0:a:"$selected_stream" \
-filter_complex "[0:a]highpass=f=100,\
acompressor=threshold=-22dB:ratio=4:attack=10:release=150,\
equalizer=f=2500:t=q:w=1:g=5,\
equalizer=f=4000:t=q:w=1:g=4,\
deesser=i=0.4:f=0.25,\
alimiter=limit=0.95,\
dynaudnorm=f=200:g=15[a]" \
-map "[a]" -c:a libvorbis \
"$file_new"
echo "Done: $file_new"
else
usage
exit
fi
fi
#Uncompatible Videocodecs:
# mpeg4 (DX50 / 0x30355844)
#h264 (High) (avc1 / 0x31637661)
#Uncompatible AUdiocodecs:
#Multiple Audiolines
#Subtitles
# ffmpeg -i $input -sn -vcodec copy -acodec copy
#Keep Audio/Video Settings
# ffmpeg -i $input -acodec copy -vcodec copy
#delete audio trach 0:1
#for file in *avi ; do ffmpeg -i "$file" -map 0:0 -map 0:2 -acodec copy -vcodec copy "New_$file"; mv "New_$file" "$file"; done
#ffmpeg -ss 00:00:00 -i Stargate.mp4 -to 02:09:39 -c copy output.mp4
# Embed Subtitles
#for file in Subs/.*srt; do ffmpeg -i "$file" "$(echo $file | sed 's/srt/ass/g')"; done
#for file in *avi; do ffmpeg -i "$file" -vf ass="Subs/$(echo $file | sed 's/avi/ass/g' | sed 's/S01E/s01e/g')" "New1_$file" ;done