diff --git a/home/console/ffmpeg.nix b/home/console/ffmpeg.nix index efc3228..c89788a 100644 --- a/home/console/ffmpeg.nix +++ b/home/console/ffmpeg.nix @@ -11,7 +11,7 @@ }; config = lib.mkIf config.modules.terminal.ffmpeg.enable { - home.packages = [pkgs.ffmpeg]; + home.packages = with pkgs; [ffmpeg librsvg]; programs.nushell.extraConfig = '' # Extract the audio track from a video as mp3 @@ -77,9 +77,23 @@ input: string # path to the source image format: string # target format/extension, e.g. "webp" ] { - let out = ($input | str replace -r '\.[^.]+$' $".($format)") - ffmpeg -i $input -y $out + if ($input | str lowercase | str ends-with ".svg") { + ff-svg $input 1024 + } else { + let out = ($input | str replace -r '\.[^.]+$' $".($format)") + ffmpeg -i $input -y $out + } } + + # Rasterize an SVG to a square PNG of the given size (in pixels) + def ff-svg [ + input: string # path to the source SVG + size: int # width/height in pixels + ] { + let out = ($input | str replace -r '\.[^.]+$' ".png") + rsvg-convert -w $size -h $size -o $out $input + } + # Shrink an image or gif's file size, using the best strategy per format def ff-shrink [ input: string # path to the source image or gif