mirror of
https://github.com/dewomser/dolphin-context-convert.git
synced 2026-03-13 17:17:18 +01:00
Update ffmpegconvert.sh
Adding images to context menu
This commit is contained in:
parent
84c3dba108
commit
1675a24b54
1 changed files with 41 additions and 18 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
input_file="$1"
|
||||
output_extension="$2"
|
||||
input_format="$3"
|
||||
filename=$(basename -- "$input_file")
|
||||
filename_noext="${filename%.*}"
|
||||
|
||||
|
|
@ -12,8 +13,13 @@ else
|
|||
output_file="${filename_noext}.${output_extension}"
|
||||
fi
|
||||
|
||||
lossy=("mp3" "aac" "ogg" "wma" "m4a")
|
||||
lossless=("flac" "alac" "wav" "aiff")
|
||||
alossy=("mp3" "aac" "ogg" "wma" "m4a")
|
||||
alossless=("flac" "alac" "wav" "aiff")
|
||||
ilossy=("jpg" "gif" "webp")
|
||||
ilossless=("png" "bmp" "tiff" "eps" "raw" "ico" "tga")
|
||||
superlossless=("psd")
|
||||
alllossy=( "${alossy[@]}" "${ilossy[@]}" )
|
||||
alllossless=( "${alossless[@]}" "${ilossless[@]}" )
|
||||
|
||||
# dont overwrite a file
|
||||
if [ -e "$output_file" ]; then
|
||||
|
|
@ -21,9 +27,9 @@ if [ -e "$output_file" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Check for conversion between lossy and lossless and show a warning
|
||||
# Check for conversion between alossy and alossless and show a warning
|
||||
input_extension="${filename##*.}"
|
||||
if [[ " ${lossy[@]} " =~ " ${input_extension} " ]] && [[ " ${lossless[@]} " =~ " ${output_extension} " ]]; then
|
||||
if [[ " ${alllossy[@]} " =~ " ${input_extension} " ]] && [[ " ${alllossless[@]} " =~ " ${output_extension} " ]]; then
|
||||
zenity --question --text="WARNING: Converting from a lossy to a lossless format.\n\nQuality will NOT improve.\n\nCompression artifacts will be present.\n\nThis betrays the point of lossless formats.\n\nPRESERVATIONISTS WILL WEEP.\n\nContinue?" \
|
||||
--ok-label="Continue" --cancel-label="Cancel" --default-cancel --icon-name="warning"
|
||||
if [ $? -ne 0 ]; then
|
||||
|
|
@ -32,7 +38,7 @@ if [[ " ${lossy[@]} " =~ " ${input_extension} " ]] && [[ " ${lossless[@]} " =~ "
|
|||
fi
|
||||
fi
|
||||
|
||||
if [[ " ${lossless[@]} " =~ " ${input_extension} " ]] && [[ " ${lossy[@]} " =~ " ${output_extension} " ]]; then
|
||||
if [[ " ${alllossless[@]} " =~ " ${input_extension} " ]] && [[ " ${alllossy[@]} " =~ " ${output_extension} " ]]; then
|
||||
zenity --question --text="WARNING: Converting from a lossless to a lossy format.\n\nQuality will NOT be preserved.\n\nCompression artifacts will be PERMANENTLY introduced.\n\nCONVERTING BACK TO LOSSLESS WILL NOT UNDO THIS.\n\nContinue?" \
|
||||
--ok-label="Continue" --cancel-label="Cancel" --default-cancel --icon-name="warning"
|
||||
if [ $? -ne 0 ]; then
|
||||
|
|
@ -41,20 +47,37 @@ if [[ " ${lossless[@]} " =~ " ${input_extension} " ]] && [[ " ${lossy[@]} " =~ "
|
|||
fi
|
||||
fi
|
||||
|
||||
# ffmpeg cmd changes based on ext
|
||||
if [[ " ${lossy[@]} " =~ " ${output_extension} " ]] || [[ " ${lossless[@]} " =~ " ${output_extension} " ]]; then
|
||||
if [ "$output_extension" == "alac" ]; then # alac is still a special babyboy
|
||||
ffmpeg -i "$input_file" -acodec alac "$output_file" 2>&1 &
|
||||
else
|
||||
ffmpeg -i "$input_file" -q:a 1 -map a "$output_file" 2>&1 &
|
||||
if [[ " ${superlossless[@]} " =~ " ${input_extension} " ]]; then
|
||||
zenity --question --text="WARNING: This file is not only lossless, but contains\nadditional data such as layer information.\nConversion will discard this information.\n\nCONVERTING BACK TO LOSSLESS WILL NOT UNDO THIS.\n\nContinue?" \
|
||||
--ok-label="Continue" --cancel-label="Cancel" --default-cancel --icon-name="warning"
|
||||
if [ $? -ne 0 ]; then
|
||||
kill $ZENITY_PID
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
ffmpeg -i "$input_file" -q:a 1 "$output_file" 2>&1 &
|
||||
fi
|
||||
FFMPEG_PID=$!
|
||||
|
||||
|
||||
if [[ " $input_format " == " audio " ]] || [[ " $input_format " == " video " ]]; then
|
||||
# ffmpeg cmd changes based on ext
|
||||
if [[ " ${alossy[@]} " =~ " ${output_extension} " ]] || [[ " ${alossless[@]} " =~ " ${output_extension} " ]]; then
|
||||
if [ "$output_extension" == "alac" ]; then # alac is still a special babyboy
|
||||
error_output=$(ffmpeg -i "$input_file" -acodec alac "$output_file" 2>&1) &
|
||||
else
|
||||
error_output=$(ffmpeg -i "$input_file" -q:a 1 -map a "$output_file" 2>&1) &
|
||||
fi
|
||||
else
|
||||
error_output=$(ffmpeg -i "$input_file" -q:a 1 "$output_file" 2>&1) &
|
||||
fi
|
||||
else
|
||||
if [[ " $input_format " == " image " ]]; then
|
||||
error_output=$(convert "$input_file" "$output_file" 2>&1) &
|
||||
fi
|
||||
fi
|
||||
|
||||
CONVERT_PID=$!
|
||||
|
||||
# i hate zenity tbh
|
||||
( while kill -0 $FFMPEG_PID 2> /dev/null; do
|
||||
( while kill -0 $CONVERT_PID 2> /dev/null; do
|
||||
echo "# Converting\n$filename\nto\n$output_file"
|
||||
sleep 1
|
||||
done
|
||||
|
|
@ -62,15 +85,15 @@ FFMPEG_PID=$!
|
|||
|
||||
# check if cancelled
|
||||
if [ $? -eq 1 ]; then
|
||||
kill $FFMPEG_PID
|
||||
kill $CONVERT_PID
|
||||
rm -f "$output_file"
|
||||
zenity --error --text="Conversion canceled. Target file deleted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check exit statuses
|
||||
wait $FFMPEG_PID
|
||||
wait $CONVERT_PID
|
||||
if [ $? -ne 0 ]; then
|
||||
zenity --error --text="An error occurred during conversion."
|
||||
zenity --error --text="An error occurred during conversion:\n\n$error_output"
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue