Skip to content

feat(snippets/bash): add media/ffmpeg-image-processor #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions snippets/bash/media/ffmpeg-image-processor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: FFmpeg Image Processor
description: Process multiple images at once using FFmpeg.
author: mishieck
tags: ffmpeg,image-processing
---

```bash
#!/bin/bash

process_images() {
filenamePattern='(.+)\.[a-zA-Z]+$'
filenames="$1" # NOTE: Quoted list or glob
outputExtension=$2 # PNG, JPEG, WEBP, etc
options=$3 # ffmpeg options

for filename in $filenames; do
if [[ $filename =~ $filenamePattern ]]; then
inputName=${BASH_REMATCH[1]}
outputFilename="$inputName.$outputExtension"
ffmpeg -i $filename $options $outputFilename
fi
done
}

process_images "$@"

# Usage:
chmod +x ./ffmpeg-image-processor.bash # Make the file executable
./ffmpeg-image-processor.bash 'image-1.png image-2.png' webp # Outputs: image-1.webp image-2.webp

# Given a folder with 'image-1.png image2.png'
./ffmpeg-image-processor.bash './*.png' webp '-compression_level 60' # Outputs: image-1.webp image-2.webp, with 60% compression
```