FFMPEGを使うことで、動画を連番の静止画像にバラして出力することができます。
今回は動画の各フレームを、よく使われる画像フォーマットであるJPG、PNG、BMPにして連番静止画として出力する方法を確認してみたいと思います。
FFMPEGの実行バイナリファイルの入手に関しましては、もし入手方法がわからないという方がいらっしゃいましたら、以下の記事を参考にしてみてください。
FFMPEGで動画から連番静止画を出力する方法
動画をPNG形式の連番静止画に変換する方法
以下のコマンドで、入力動画を連番PNG画像に変換できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i input.mp4 -vcodec png output_png\output_%06d.png
ポイントは以下の通りです。
- 入力動画を「input.mp4」の位置に指定します
- PNG形式で出力する場合は「-vcodec png」を指定します
- 出力画像のファイルパス及びファイル名を最後に記述します。「output_png\output_%%06d.png」の場合、output_pngフォルダ内に、0で詰めた6桁の数字の連番静止画として画像が出力されます。すなわち、画像はoutput_000001.png, output_000002.png, output_000003.pngのような名前の順番で出力されます。
- 「output_png」フォルダがないと正常に出力されない可能性があるので注意してください。

動画をJPG形式の連番静止画に変換する方法
以下のコマンドで、入力動画を連番JPEG画像に変換できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i input.mp4 -vcodec mjpeg output_jpg\output_%06d.jpg
PNGとの違いは「-vcodec mjpeg」を指定する箇所となります。
動画をBMP形式の連番静止画に変換する方法
以下のコマンドで、入力動画を連番BMP画像に変換できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i input.mp4 -vcodec bmp output_bmp\output_%06d.jpg
PNGとの違いは「-vcodec bmp」を指定する箇所となります。
まとめ
今回は、FFMPEGで動画を連番静止画に出力する方法を確認しました。FFMPEGを使えば、さまざまな形式の連番静止画を出力することができます。