Minor modifications

This commit is contained in:
2024-01-29 11:28:50 +01:00
parent cc71e4c758
commit 9e25501b41
5 changed files with 306 additions and 10 deletions

View File

@@ -994,6 +994,27 @@ mp42gif_function() { \
}
#+end_src
*** MP4 to GIF Loop
#+begin_src bash
mp42gifloop_function() { \
if command -v ffmpeg &> /dev/null; then
palette="/tmp/palette.png"
width=$(echo -e "auto" | rofi -i -dmenu -p "GIF width")
if [ "$width" = "auto" ]; then
filters="fps=15"
else
filters="fps=15,scale=$width:-1:flags=lanczos"
fi
# # Generate optimal pallette of colors
# ffmpeg -v warning -i "$filename_with_extension" -vf "$filters,palettegen" -y $palette
# Convert
ffmpeg -i "$filename_with_extension" -filter_complex "[0]reverse[r];[0][r]concat=n=2:v=1:a=0,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -y "$filename_without_extension.gif"
fi
}
#+end_src
*** MP4 remove sound
#+begin_src bash
mp4nosound_function() { \
@@ -1007,7 +1028,7 @@ mp4nosound_function() { \
#+begin_src bash
# Convert MP4 Files
mp42() { \
out_ext=$(echo -e "gif\nremove sound" | rofi -i -dmenu -p "Convert MP4 to")
out_ext=$(echo -e "gif\ngif loop\nremove sound" | rofi -i -dmenu -p "Convert MP4 to")
if [ -z "$out_ext" ]; then
exit;
@@ -1017,6 +1038,9 @@ mp42() { \
"gif")
mp42gif_function
;;
"gif loop")
mp42gifloop_function
;;
"remove sound")
mp4nosound_function
;;
@@ -1024,6 +1048,78 @@ mp42() { \
}
#+end_src
** AVI files
*** AVI to MP4
#+begin_src bash
avi2mp4_function() { \
if command -v ffmpeg &> /dev/null; then
ffmpeg -i "$filename_with_extension" -c:v copy -c:a copy "$filename_without_extension.mp4"
fi
}
#+end_src
*** AVI to GIF
#+begin_src bash
avi2gif_function() { \
if command -v ffmpeg &> /dev/null; then
palette="/tmp/palette.png"
mp4tmp="/tmp/avi2gif.mp4"
width=$(echo -e "auto" | rofi -i -dmenu -p "GIF width")
if [ "$width" = "auto" ]; then
filters="fps=15"
else
filters="fps=15,scale=$width:-1:flags=lanczos"
fi
ffmpeg -i "$filename_with_extension" -c:v copy -c:a copy -y "$mp4tmp"
# Generate optimal pallette of colors
ffmpeg -v warning -i "$mp4tmp" -vf "$filters,palettegen" -y $palette
# Convert
ffmpeg -v warning -i "$mp4tmp" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$filename_without_extension.gif"
fi
}
#+end_src
*** AVI to GIF loop
#+begin_src bash
avi2gifloop_function() { \
if command -v ffmpeg &> /dev/null; then
palette="/tmp/palette.png"
mp4tmp="/tmp/avi2gif.mp4"
ffmpeg -i "$filename_with_extension" -c:v copy -c:a copy -y "$mp4tmp"
ffmpeg -i "$filename_with_extension" -filter_complex "[0]reverse[r];[0][r]concat=n=2:v=1:a=0,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -y "$filename_without_extension.gif"
fi
}
#+end_src
*** Main function
#+begin_src bash
# Convert AVI Files
avi2() { \
out_ext=$(echo -e "gif\ngif loop\nmp4" | rofi -i -dmenu -p "Convert AVI to")
if [ -z "$out_ext" ]; then
exit;
fi
case "$out_ext" in
"gif")
avi2gif_function
;;
"gif loop")
avi2gifloop_function
;;
"mp4")
avi2mp4_function
;;
esac
}
#+end_src
** Case statement
#+begin_src bash
case "$in_ext" in
@@ -1039,6 +1135,9 @@ case "$in_ext" in
"pdf")
pdf2
;;
"avi")
avi2
;;
"mp4")
mp42
;;