From eb147aa3c7f3bbbd3fba3f256d3366253d5b627f Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 11 Mar 2025 15:52:12 +0100 Subject: bash: Add function for converting video to gif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- .bashrc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to '.bashrc') diff --git a/.bashrc b/.bashrc index 34b6995..76ff96a 100644 --- a/.bashrc +++ b/.bashrc @@ -142,6 +142,21 @@ alias random_string="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head - # Cargo environment. source_maybe "$HOME/.cargo/env" +# Convert the given video into GIF. I have tested this with webM and it appears +# to work fine. This is just a wrapper for ffmpeg, but oh boy it's hard to +# remember anything ffmpeg-related... +# +# It accepts two parameters: scale (defaults to 320); and fps (defaults to 10). +# +# Taken from some random answer from StackOverflow, no longer remember from. If +# you see this and recognize it: thanks! and just give me a ping for +# acknowledging you. +video2gif() { + ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png" + ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif + rm "${1}.png" +} + ## # RISC-V -- cgit v1.2.3