LoginSignup
101
100

More than 5 years have passed since last update.

連番静止画からタイムラプス動画を作る

Last updated at Posted at 2014-10-28

個人的なメモです。

コマンド

source0000.jpg から始まる連番の静止画から毎秒15フレームの動画ファイル video.mp4 を作る。

$ ffmpeg -f image2 -r 15 -i source%04d.jpg -r 15 -an -vcodec libx264 -pix_fmt yuv420p video.mp4

source0000.jpg から source9999.jpg までの静止画10000枚から毎秒15フレームの動画を作成。長さは(10000/15)秒=11分6秒2/3。
今回は視野固定カメラの静止画像から作成した。静止画は一枚40KB程度、動画は220MB程度(50%程度の圧縮ですね)。

ffmpeg オプション解説

-f image2

入力が jpeg 画像であることを明示。

-r 15(一つ目)

入力 静止画の更新を毎秒15フレームに指定。ここの数字を変更すればタイムラプス動画のフレームレートを変更できる。

-i source%04d.jpg

入力画像のファイル名形式を指定。 %04d は0埋めされた4桁数字(0000〜9999)の意味。

-r 15(二つ目)

出力 動画を毎秒15フレームに指定。入力フレーム数の整数倍であるべき(だと思う)。

-an

オーディオ無し。

-vcodec libx264

mp4 フォーマットでエンコーダを H.264 に指定。

-pix_fmt yuv420p

画像形式を YUV 形式で YUV420 に指定。jpeg をそのまま動画にすると YUV422 になり、Mac の QuickTime で再生できなかった。一般的な変換である YUV420 に変換した。
-vf format=yuv420p という書式もある。どちらが好ましいのか分からなかった。
(2019/1/10追記)が、Encode/H.264 – FFmpeg-pix_fmt yuv420p がエイリアスだ、と書いてあるので -vf format=yuv420p がいちおう正式なんでしょうね。とはいえ -vf もFFmpegのドキュメントに This is an alias for -filter:v と書いてあるので…まあ書きやすくて覚えやすいほうがいいよな。-pix_fmt yuv420p 使おう、うん。

video.mp4

出力ファイル名。 mp4 フォーマット。

ffmpeg ログ出力の一部

今回使った静止画のサイズは 720x480 。自動認識している。
使用した ffmpeg は Homebrew でインストールしたもの。

ffmpeg version 2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
  built on Oct 11 2014 01:46:03 with Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.4.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-librtmp --enable-openssl
  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.100 / 56.  1.100
  libavformat    56.  4.101 / 56.  4.101
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.100 /  5.  1.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, image2, from 'source%04d.jpg':
  Duration: 00:11:06.67, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg), 720x480, 15 fps, 15 tbr, 15 tbn, 15 tbc
  :(中略)
  Metadata:
    encoder         : Lavf56.4.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 720x480, q=-1--1, 15 fps, 15360 tbn, 15 tbc
    Metadata:
      encoder         : Lavc56.1.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
  :(後略)

注意点

101
100
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
101
100