0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コマンドプロンプトでカレントディレクトリのPNGファイルをJPEGファイルに変換する

Posted at

空白入りファイル名の処理に注意

FFmpegはPNGファイルをJPEGファイルに変換する機能がある。コマンドプロンプトで一括処理をさせることも可能。
ただしワイルドカードで入力指定はできない。

これではエラーになる
ffmpeg -i *.png *.jpg

コマンドプロンプトのバッチファイルでファイル名を取得、自動処理させることにした。

conv.bat
@echo off
for %%f in (*.png) do (
  ffmpeg -i "%%~nf.png" "%%~nf.jpg"
)

2行目のPNGファイル名取得はよいとして、問題は拡張子を除いた部分をどう取り出すかである。

こちらのサイトや

Microsoft公式のドキュメントも参考に

%%と変数名の間に~nを入れることで解決。

なお、ファイル名部分は引数をダブルクォーテーションで括らないと空白の入ったファイル名が出てきた時点でエラーとなるため、両方ともダブルクォーテーションで括る必要がある。

Windows PowerShellを用いればもっとスマートにできると思うが、未だコマンドプロンプトを多用する旧人類的なやり方で紹介した。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?