1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ffmpeg + バッチファイルで画像を一括リサイズする

Last updated at Posted at 2022-11-17

Windows環境でバッチファイルとffmpegで画像をリサイズするコードのメモです

1. ffmpegのインストール

まだインストールしてない人は以下の手順でインストールできます
https://qiita.com/studio_haneya/items/ae44e39b5a389cf8cf6e

2. バッチファイルで画像をリサイズする

ファイル1つずつで良いなら以下のバッチファイルに画像ファイルをドラッグ&ドロップすればリサイズできます

%1がドロップしたファイルのフルPATH、%~dp0がバッチファイルのあるフォルダのPATH + ファイル名、%~x1がドロップしたファイルの拡張子なので、「d:/fuga/hoge.bat」に「d:/hoge/img.png」をドラッグ&ドロップした場合、%1が「d:/hoge/img.png」、%~dp0%~n1_%resolution%%~x1が「d:/fuga/img_1440.png」になります

以下ではアスペクト比固定で横のピクセル数を1440にするという指示にしています

hoge.bat(単独ファイルのみ)
set resolution=1440
ffmpeg -i %1 -vf "scale=%resolution%:-1" -q 2 %~dp0\%~n1_%resolution%%~x1

3. バッチファイルで複数画像をリサイズする

バッチファイルは引数すべてに対してfor文で順番に取得していくことが出来るので、以下のようにドロップしたファイルすべてについて順番に実行していくことができます

hoge.bat(複数ファイル対応版)
set resolution=1440
set folder=%~dp0

for %%i in (%*) do (
    ffmpeg -i %%i -vf "scale=%resolution%:-1" -q 2 -y %folder%%%~ni_%resolution%%%~xi
)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?