Amish Brothers Time-lapse with Guide

This is a time-lapse video of my development of Amish Brothers for Ludum Dare 26. The video footage was taken from my Twitch.tv stream.

Generating a time-lapse video from a Twitch.tv stream is not a trivial task. I will describe the process that I used to create this video. This is only a suggested method, and I do not suggest, promote, or advocate any of the software packages described below. Use all software at your own risk.

First, you will need all of your Twitch.Tv video clips. These can be downloaded from http://bashtech.net/twitch/download.php . You will need to connect your twitch.tv account with your username and password. I believe the authentication is through Twitch.tv, so it should be safe, but don’t hold me to that. To be on the safe side, make sure your Twitch.Tv password is unique from any other passwords that you use.

Then start pressing the Next button until you get to the videos that you want to use for your time lapse. If you’re like me, you named these videos something like Ludum Dare. Now for the monotonous part, start downloading each of the video streams into a folder of your choosing. These videos will be saved in FLV format. Unfortunately, this site provides your videos in 30 minute chunks, so there may be numerous video files to download. If you are clever, you can probably script a process to speed up the download process using a web file grabber like wget or curl.

Download and install the VLC video player from http://www.videolan.org/vlc/ .

VLC can be used to generate snapshots of an FLV video as specified frame intervals using a command like the one below from a Windows command prompt.

> vlc C:ludumdaremyvideo.flv --rate=1 --video-filter=scene --vout=dummy --start-time=1 
--stop-time=1800 --scene-format=png --scene-ratio=24 --scene-prefix=snap 
--scene-path=C:ludumdarescreens vlc://quit

This tells VLC to generate a snapshot every 24 frames for the first 1800 seconds (30 minutes). This works okay, but the stream has to completely play through the entire 30 minutes to take the snapshots. Therefore, it will take the total amount of casting time to grab all of the snapshots for the time-lapse video. This method could take hours for to grab all the snapshots out of the stream videos.

Note: The path to VLC must be in your PATH environment variable. This can be done in a command prompt using a command such as the one below. Change the value accordingly for your VLC installation.

set PATH=%PATH%;C:Program Files (x86)VideoLANVLC

To make this process more efficient, we only want to play the video at the points where we will capture a snapshot. This can be accomplished by changing the start-time and stop-time values. When specifying those values, VLC will start generating snapshots at that number of seconds into the clip. However, there is an apparent bug which makes VLC also generate a snapshot at the beginning of the video as well.

Now to generate all of the snapshots, we will need to execute VLC setting the start-time parameter to the value of the position where the snapshot should be taken. Repeat this process by incrementing the start-time parameter by the interval between frames in seconds. I set the stop-time to the start-time + 1, since we only want to capture one frame at that time. Be careful to make scene-ratio the value of the frames per second for the cast, so that only one snapshot is taken for the one second interval. In most cases, that value will probably be 24 frames per second for Twitch.tv.

I chose to take one frame every 30 seconds for my Amish Brothers time lapse video. I scripted this process in Ruby, so that it automatically calls VLC with the correct time parameters. This made the total time to generate the snapshots for a 30 minute video 60 seconds (2 snapshots generated for each minute of footage at one second each), but maybe a little longer due to some overhead of starting and stopping VLC.

That is good, but I had 37 videos to process, which is still tedious. With a little more scripting, I was able to loop through all of the FLV files that I had downloaded into my video directory. After the script is complete, it puts all of the PNG image files in the “screens” directory. However, there is that bug in VLC that generates an image at the start of the video, so with a simple DOS delete command I removed all of the “*00001.png” files, leaving only the correct snapshots remaining in the directory.

Below is the Ruby code for generating the snapshots with VLC.

USE AT YOUR OWN RISK AND ONLY IF YOU KNOW WHAT YOU ARE DOING!

iFramesPerSecond = 25
iSecondInterval = 30
iFrameCounter = 1
Dir.foreach('.') do | strFile |
  if (strFile =~ /.flv/)
    iStartTime = 1
    while (iStartTime < 30 * 60)
      strFrame = "%05d" % iFrameCounter
      strCommand = "vlc #{strFile} --rate=1 --video-filter=scene --start-time=#{iStartTime} 
--stop-time=#{iStartTime + 1} --vout=dummy --aout=dummy --scene-format=png 
--scene-ratio=#{iFramesPerSecond - 1} --scene-prefix=#{strFrame}f 
--scene-path=.\screens vlc://quit"
      puts "Running #{strCommand}"
      system(strCommand)
      iFrameCounter += 1
      iStartTime += iSecondInterval
    end
   end
 end

Next, I went through my snapshot directory and removed unneeded images, such as when I was eating or away on a bathroom break.

Now I needed to put the snapshots back together in a video file. Some people have recommended Chronolapse, but I tried it and the video quality was really poor and there were no options to increase the quality. Therefore, I used VirtualDub (http://virtualdub.org/), which can also make a video out of image files.

The only problem with VirtualDub is that it expects the filenames to be in sequential order (0001.png, 0002.png, 0003.png, etc), and the filenames generated by VLC can only be specified by a prefix, and it gives each file an unchangeable ending, which is based on the frame number. To resolve this, I wrote another Ruby script which looped through all my snapshot images and renamed them to sequential file names. I’m not sure if the files are looped through by lexicographical order or timestamp order by default, but it worked so I’m not complaining.

USE AT YOUR OWN RISK AND ONLY IF YOU KNOW WHAT YOU ARE DOING!

iFile = 1
Dir.foreach('.') do | strFile |
  if (strFile =~ /.png/)
    strNewName =  "%05d" % iFile
    strNewName += ".png"
    puts "Old: #{strFile} New: #{strNewName}"
    File.rename(strFile, strNewName)
    iFile += 1
  end
end

Now all of my images are in the directory in sequential order by file name. The images can be imported into VirtualDub by selecting File > Open Video File and selecting the first image. It will automatically add all of the other images in the directory. I also added an audio track using some of the music from my game, by selecting Audio > Audio from other file. It is important to note that VirtualDub will not loop your audio, so I had to manually loop the audio myself by extending the audio track in Audacity.

Finally, I added a credits screen at the end, which seemed to be more trouble than it was worth. There is no way to slow down or copy frames in Virtual Dub, so I had to make another video file containing my credits, and then used File > Append AVI segment to add it to the end.

Now I just needed to encode the video, but it turned out to be about 5 Gigs in size, which I believe is too big for YouTube. This was fixed by selecting Video > Compression from the VirtualDub menu. It gives a few different compression methods. I didn’t really have a clue as to which one is best, so I just selected Microsoft Video 1. It reduced the size to around 400 Megs, so it did the job.

Finally, I previewed the video and uploaded to YouTube. It seemed to a be a lot of trouble just to make a time-lapse video, but this was my method since I didn’t not use a screen capture program and I didn’t want to spend a lot of money on a professional video package.

 

References:

http://wiki.videolan.org/How_to_create_thumbnails

http://code.google.com/p/chronolapse/

http://support.twitch.tv/discussion/2391/frequently-asked-questions

How to make a good timelapse

https://wiki.videolan.org/VLC_command-line_help

Amish Brothers Complete

Who are more minimalist than the Amish? Welcome to Amish Brothers where you play as Brother Jebidiah, who must return all of the farmyard animals to the barn. Ten levels of sheep catching action!

amishbrothers03

This is my first game created in Unity. The development environment has a little bit of a learning curve, but once I got the hang of it most of it made sense. I really like Unity’s ability to import Blender (.blend) models directly into the project. This is something that I have been fighting with in XNA for over six months. The biggest trick was figuring out that I had to select the “Legacy” option under the model’s “Rig” settings. Getting the models to rotate the correct way was also a bit of a challenge, since rotating at the incorrect place will cause the movement vector to change as well.

It was a really enjoyable experience creating all of the assets for the game. All of the models were created in Blender. The music was me playing the guitar with touch-up done in Audacity. The sheep sound was also me, with some pitch and speed distortion in Audacity.

I’m really anxious to hear what people think of the game. I’ll admit that it isn’t the most complex game, but I think it appropriately fits the “minimalism” theme of this Ludum Dare competition.

amishbrothers01

Play the game here: Amish Brothers

Contact me @GaTechGrad on Twitter