A blog about VFX, scripting, van renovation, and some other gubbins.

@henloco

Encoding an image sequence to video

Published 5th February 2019 by Henry

The only good way to do this seems to be via the command line. In this circumstance I have about 5000 frames stored as png image files which are named sequentially xxxxx_0000.png, xxxxx_0001.png, xxxxx_0002.png etc.

  1. Download FFMPEG
  2. Copy the binary FFMPEG.exe to the folder with the sequence, then in a command prompt enter the following:
  3. ffmpeg -f image2 -framerate 30 -i [filename]_%04d.png -c:v h264_nvenc -preset slow -qp 18 -pix_fmt yuv420p [outputname].mp4

A few notes:

  • Assuming Windows is used here, but this should also work for Linux and Mac.
  • I have an nVidia card so I used their codec (h264_nvenc) but you may want to use libx264 instead.
  • If your image sequence filenames have a different number of leading zeros, change the regex pattern from %04d to something else, such as %02d for 2.
  • Change [filename] to whetever you images are named as before the regex
  • Change [outputname] to your desired output filename

Adding the option -vf scale=1920:1080 will scale the video on the fly.

Once you’ve output a video, it can be scaled using the following examples:

  • ffmpeg -i [inputname].mp4 -vf scale=1920:1080 [inputname]_1920_1080.mp4
  • ffmpeg -i [inputname].mp4 -vf scale=1280:720 [inputname]_1280_720.mp4

For h265 encoding using nVidia hardware acceleration, try something like:

  • ffmpeg -hwaccel cuvid -f image2 -i [filename]_%04d.png -framerate 30 -pix_fmt p010le -c:v hevc_nvenc -preset slow -rc vbr_hq -b:v 6M -maxrate:v 10M -c:a aac -b:a 240k [outputname].mp4

To start from a different frame, use the start_number parameter:

  • ffmpeg -hwaccel cuvid -f image2 -start_number 0300 -i [INPUTNAME]_%04d.png -framerate 30 -pix_fmt p010le -c:v hevc_nvenc -preset slow -rc vbr_hq -b:v 6M -maxrate:v 10M -c:a aac -b:a 240k [OUTPUTNAME].mp4

Adding audio is simple:

  • ffmpeg -i [VIDEO].mp4 -i [AUDIO].mp3 [OUTPUT].mp4

Seamless Looping

To create a looping video, split the video into two halves and then use a filter to blend them together. This example assumes the video is 3600 frames long:

  • ffmpeg -f image2 -framerate 60 -i %04d.png -c:v h264_nvenc -preset slow -qp 18 -pix_fmt yuv420p -frames:v 1800 video_1.mp4
  • ffmpeg -f image2 -framerate 60 -start_number 1800 -i %04d.png -c:v h264_nvenc -preset slow -qp 18 -pix_fmt yuv420p video_2.mp4
  • ffmpeg -i video_1.mp4 -i video_2.mp4 -filter_complex “[0]fade=t=out:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va0];[1]fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS[va1];[va0][va1]overlay[outv]” -map [outv] -crf 10 video_loop.mp4

More

Previous

Insulating the luton box

Next

Advanced MatCap Material

Leave a Reply

Your email address will not be published. Required fields are marked *