Batch Converting Image Files: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== `ffmpeg` == Use `ffmpeg`. If `ffmpeg` is not available on the command line, install with `brew install ffmpeg`. == Batch convert `webp` to `jpg` == <syntaxhighlight lang=bash> $ for i in *.webp; do ffmpeg -i "$i" "{i%.webp}.jpg"; done </syntaxhighlight> == Batch convert `png` to `jpg` and scaling images proportionally == The `scale=1024:-1` tells ffmpeg to scale the images to 1024 pixels wide. The height will be scaled proportionally. To scale to a consistent h...") |
No edit summary Tag: wikieditor |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | == Converting file formats == | ||
Use `ffmpeg`. | Use `ffmpeg`. | ||
| Line 5: | Line 5: | ||
If `ffmpeg` is not available on the command line, install with `brew install ffmpeg`. | If `ffmpeg` is not available on the command line, install with `brew install ffmpeg`. | ||
== Batch convert `webp` to `jpg` == | === Batch convert `webp` to `jpg` === | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
| Line 11: | Line 11: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Batch convert `png` to `jpg` and scaling images proportionally == | Find and convert webp files recursively: | ||
<syntaxhighlight lang=bash> | |||
$ find . -iname '*.webp' -exec bash -c 'ffmpeg -y -i "$1" "${1%.*}.jpg"' _ {} \; | |||
</syntaxhighlight> | |||
=== Batch convert `png` to `jpg` and scaling images proportionally === | |||
The `scale=1024:-1` tells ffmpeg to scale the images to 1024 pixels wide. The height will be scaled proportionally. To scale to a consistent height of 800 pixels, `scale=-1:800`. | The `scale=1024:-1` tells ffmpeg to scale the images to 1024 pixels wide. The height will be scaled proportionally. To scale to a consistent height of 800 pixels, `scale=-1:800`. | ||
| Line 18: | Line 24: | ||
$ for i in *.png; do ffmpeg -i "$i" -vf scale=1024:-1 "converted/${i%.*}.jpg"; done | $ for i in *.png; do ffmpeg -i "$i" -vf scale=1024:-1 "converted/${i%.*}.jpg"; done | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Batch renaming files == | |||
Use `rename` which can be installed with `brew install rename`. | |||
In the following example, the `-n` option indicates "dry run" for testing purposes. The `-e` option indicates the regex pattern that should be applied. | |||
<syntaxhighlight lang=bash> | |||
$ for i in *.png; do rename -n -e 's/foo(\d\d)_/bar$1/g'; done | |||
</syntaxhighlight> | |||
== See also == | |||
* [[Converting Video Files]] | |||
Latest revision as of 16:51, 17 December 2023
Converting file formats[edit]
Use ffmpeg.
If ffmpeg is not available on the command line, install with brew install ffmpeg.
Batch convert webp to jpg[edit]
$ for i in *.webp; do ffmpeg -i "$i" "{i%.webp}.jpg"; done
Find and convert webp files recursively:
$ find . -iname '*.webp' -exec bash -c 'ffmpeg -y -i "$1" "${1%.*}.jpg"' _ {} \;
Batch convert png to jpg and scaling images proportionally[edit]
The scale=1024:-1 tells ffmpeg to scale the images to 1024 pixels wide. The height will be scaled proportionally. To scale to a consistent height of 800 pixels, scale=-1:800.
$ for i in *.png; do ffmpeg -i "$i" -vf scale=1024:-1 "converted/${i%.*}.jpg"; done
Batch renaming files[edit]
Use rename which can be installed with brew install rename.
In the following example, the -n option indicates "dry run" for testing purposes. The -e option indicates the regex pattern that should be applied.
$ for i in *.png; do rename -n -e 's/foo(\d\d)_/bar$1/g'; done