Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Thursday, July 3, 2014

Time-lapse video on Linux using ffmpeg or avconv


I recently did a bit of a tutorial on creating a timelapse video from a series of images using free software for Windows. I did this because, many people still use it as their operating system. (Clearly they are unaware it's no longer the best choice.)

My primary OS is Linux and so I thought I would follow up that article with a simpler one on how to create a time-lapse video from images using avconv or ffmpeg on Linux.

Keeping things relatively simple, the avconv command would look something like this.

avconv -f image2 -r 25 -i DSC_%04d.jpg -vcodec libx264 timelapse.mp4


and for ffmpeg

ffmpeg -r 25 -i DSC_%04d.jpg -q:v 0 -s hd1080 -vcodec libx264 -crf 25 timelapse.mp4



I won't go into detail on the differences, suffice to say that avconv forked from ffmpeg and is now the default included in Ubuntu Linux. What you use really will come down to personal choice and distro availability.

To explain in a little more detail. For both commands, any arguments prior to the -i, are arguments for the input data. In the cases above the -f image2 tells avconv the input is in image format, whilst the -r 25 sets the input framerate at 25 frames per second.

Any arguments after the -i are output arguments. (With the exception of the input files specification which is part of the -i flag)

The input file name as shown above (DSC_%04d.jpg) tells the application to match any files starting with DSC_ and then containing 4 numerical digits before the extension. (DSC_1024.jpg, DSC_1025.jpg, DSC_1026.jpg .......)

If we were to use a %d instead of %04d, then it would look for input files in numerical sequence. (DSC_1.jpg, DSC_2.jpg, .... DSC_123.jpg, ... etc)

The %04d allows us to specify that there will always be 4 digits. For example: DSC_0001.jpg, DSC_0002.jpg....)

-vcodec is to set the video output codec. Unless you have a specific need to use something else I highly recommend using libx264

-crf 25 sets the output framerate to 25 frames per second. (I believe this is default anyway if not specified)

-q:v 0 is to set the video quality scale. 0 being excellent quality.

-s hd1080 is setting the resolution of the video to Full HD (1920x1080). -s hd720 should therefore be pretty self explanitory.

Finally, the filename.... I called it (very imaginatively) timelapse.mp4, but you can set whatever name you deem appropriate.

Please note, this is not taking into account any potential need to deflicker the images or anything else like that.

It is by no means an exhaustive list of options available to control either of these applications, but the available options are extensive so if you want more in-depth control I suggest you look at the documentation on the website or read the man page.

Additionally, I would highly recommend you put this into a bash script to make future timelapse creation much easier, and to help facilitate other functions such as deflickering prior to encoding, etc.

A simple bash script could be:

#!/bin/bash
if[-n "$1"] then ffmpeg -r 25 -i $1/DSC_%04d.jpg -q:v 0 -s hd1080 -vcodec libx264 -crf 25 $1/timelapse.mp4
else
ffmpeg -r 25 -i DSC_%04d.jpg -q:v 0 -s hd1080 -vcodec libx264 -crf 25 timelapse.mp4
fi


This is a simple example, it checks to see if you have passed a directory as the first argument and uses it, otherwise it assumes you are getting input and output from the current directory. It should be easy to expand upon this as required. This certainly saves you having to retype the command all the time and even helps prevent getting multiple copies of the script all over the place.

Remember to set it as executable (chmod +x your_script_filename)

Enjoy.

Monday, June 23, 2014

How to create a time lapse video with free software


What is a time lapse video?
It is a video created (most commonly) from a series of photographs taken over a period of time that speeds up the time, essentially making everything run in high speed. As such several hours worth of photographs can be condensed down into several minutes of video.

It is very effective for watching the changes of light or the movement of people and objects over the course of hours, days, weeks, months and sometimes even years. Some examples have been time lapse videos that cover the entire construction of buildings or the change in a landscape over a year highlighting the changes of season.

It can also be used to view a high speed video of food decomposing or crayons melting. I'm sure you get the idea.

Here is a short time lapse I did some time ago using webcam footage. Please note: This was done prior to me working out the method in this tutorial, using low quality webcam images. See the end for examples created using this method.


Getting starting


In order to effectively create a time lapse video you will need a camera. Really any camera will do, but unless it is capable of being controlled by a remote (DSLR) or has time lapse features built in already (GoPro) then it will be a very manual process and hard to manage.

This is because you need hundreds of photos over a period of time. Standing with a compact camera and pushing the shutter button every 5 seconds for 3 hours isn't really my idea of fun. Not only that but it also opens it up to wobble and distorsions in the images which will affect the quality of the video.

So, ideally you want a GoPro or a DSLR with an intervalometer. ( A remote capable of opening the shutter repeatedly with a set interval). The manual control of the DSLR will also help with exposing the photo correctly.

Find a composition


Find a place suitable for capturing an interesting time lapse. It may be the crowds of people walking through a city, or perhaps a sunrise or sunset. I will leave that part to you to determine. Once you've found your composition, take photos.... lots of them. The more photos you have, the longer the video clip will be.

Taking the shots


The interval you use between shots is up to you but as a general rule, the quicker/shorter the interval the more smooth the end result will be as there is less time passing between each capture. The longer the interval the more jumpy the end result will be as there is a larger period of time passing between each image.

Having said that. While an interval of a couple of seconds will be very smooth, it will also be the slowest in terms of time advancing in the end result. You might compress 2 hours down to a 20 seconds for example. Whereas an interval of 15 seconds between shots might result in the 2 hours of images compressing down to 5 seconds.*

* I just made those figures up. I'm too lazy to calculate it. It's to try and explain the concept.

Image quality


Image quality is really up to you. If you have the gear, and the time or you want the best possible outcome then I suggest shooting RAW. If you can only do JPEG then that's going to be okay as well.

I am not going to get into the actual procedure of batch processing hundreds or thousands of images but suffice to say it is possible to make some adjustments to the first image and apply those same adjustments to the rest of the sequence using software like Raw Therapee.

(Feel free to comment below and let me know if you are interested in a tutorial on Batch Image Processing using RAW Therapee)

Import the files


I have just copied the time lapse images from the camera into a folder for the video and then into an images subfolder. (In my case I was shooting RAW and did a quick batch process so my final images are in a converted folder as we need them as JPEG to encode to video.)



To make it easy for the encoding software it is ideal to have the images in a numbered sequence. This can be done by selecting all the images (Ctrl + A) then right clicking the first image and choosing rename. Call it timelapse or whatever you want. The operating system will then rename the images in a numbered sequence as below.



Making the video

Here is where the magic happens, but first, if you don't have it already, go and download VirtualDub. It is a small download for a very powerful application.


When you first run the VirtualDub application you will see a dull gray screen.



We will start by loading our image sequence by clicking File -> Open Video File or Ctrl+O
Navigate to the directory containing your image sequence from earlier. Select the first image of the sequence which should end with the number 1 and make sure Automatically load linked segments is checked.


Once loaded you will (depending on size of images) see part of the image in the empty gray area. Something like this.


If you Right Click the image and select 25% (or whatever works) for your screen size you should notice it will resize to be more suitable. You can go ahead and do the same on the right hand side of the screen as well.


If you haven't guessed it already we have panels for input and output.

Next, we want to add some filters and adjust the frame rate of the video to be suitable.

The first filter we want to add is the Resize filter which will enable us to specify the size of the video output. For a high definition video you could choose 1920 x 1080

Click Video -> Filters (or Ctrl + F)
Click Add
Select the resize filter and add it
In the options dialog you can set the size of the output video. I recommend setting the aspect ratio as per the screenshot below to 16:9 and then you can set the absolute size about and it will remain constrained to that aspect ratio.



Secondly I would suggest downloading the MSU Deflicker filter from here. It can be installed by unzipping it into the plugins directory under your VirtualDub directory. (It does require VirtualDub to be restarted)

If you choose to do this it can help compensate from flickering that can be caused by slightly different exposures from image to image. Well worth doing, especially if your camera was in something other than full manual mode.



Add it with the default settings to begin with. I've found them to be quite suitable for most cases.

You should have noticed after the resize filter, the change in the output panel on the main screen. However, there is another thing we need to do before we encode the video.

We need to set the frame rate. 25 frames per second is a good starting point. I recommend starting there and if you don't like the output after that you can adjust it up or down to suit the look you feel is best.

Select Video -> Frame Rate or (Ctrl+R)


Leave the bottom half of the framerate options as they are, just select Change frame rate to (fps):  and set your desired frame rate.

Now, we are almost done. You should have something that looks a bit like this. (Obviously with your images, not mine)


Before we go ahead and encode the video we are going to want to setup some sort of compression, we do this by selecting a codec to use for the video. Select Video -> Compression or (Ctrl + P)

The dialog that opens will list the various codecs available on your system that VirtualDub is able to use. I personally have been using Xvid (which, if not in the list can be downloaded here)

You can use whichever suits you best.


For Xvid you can adjust the options to keep the file size reasonable without losing too much quality to the compression. The screenshot above shows the settings I last used on the videos I will have at the end.

Alright... still with me?

The final step is to encode the video. To do this we select File -> Save as AVI or (F7)

Choose a location to save the video to and give it a name.

Then wait for the encoding to finish and once it has, you can open the folder where you saved it and play the video to view the final result.

Here is an example of a couple of short time lapse clips I created using this method described above. In these videos the photographs were taken using my Nikon D5100 DSLR in RAW mode and batch processed with a preset from Raw Therapee prior to then creating the time lapse using VirtualDub.



Hope this helps get you started making time lapse videos. If you wan't, feel free to comment below with a link to your video.

Sunday, October 6, 2013

Survarium Graphics Quality Bad? Not in my book



For those of you who have been living under a rock, or just aren't into gaming, Survarium is an up and coming project by Vostok Games. The team consists of many of those developers and artists responsible for the S.T.A.L.K.E.R series of games. It's set to be a free to play first person shooter with multiple game modes and incorporating also, a storyline that the players can solve and progress the story behind the game. I won't go into more details on that now because I want to focus this article primarily on criticism of the games graphics that came up with their latest video release which you can watch below.
The video was released to give a bit of a game-play demo of the PvP game mode. Keep in mind that the game is still in alpha stages and as they always say when releasing these videos... this was made with an early version of the game and does not represent the final quality. (Or something to that effect).



If you put aside the criticisms over the animations, which, to be honest, aren't that bad, but I would expect them to be improved by the actual release. The other criticism that came up was the quality of the graphics, with someone suggesting it looks like sometime from many years ago.



If you pause the video and look at some of the scenes presented you might even agree that the graphics are bad. Watching this video, I think saying that the graphics look like something years old is a bit harsh, but I don't think that Vostok Games do themselves any favors by releasing videos of this sort of quality. Yes, Youtube is likely partially to blame, but my guess is that this video was pretty compressed before it was uploaded to Youtube, which, in all likelyhood, has compressed it further. I say this mostly because even watching in the highest quality, the screens still come out like this.



These images were all captured from that video running in the highest quality available.




I can't help but notice that Survarium is continuing the S.T.A.L.K.E.R tradition of firing tracer rounds from the firearms.




What is this sniper even aiming at? In the video you can see the movement, but it's hard to make out the targets.


Now. Please don't get me wrong with this post. It is not intended to bash up Vostok, or to make you think the graphics suck. In fact. I have proof that the graphics are not this bad. Vostok games was kind enough to provide this image below taken from a location in the game which they have revealed to us in the past : The Chemical Plant.
(You should be able to click on the image to see a bigger version.)




Survarium : Chemical Plant
 
Bearing in mind the game is still in alpha and there is a lot of work to be done between where they are now, and where they will be at release, I'd say this is pretty damn impressive. Sure, if you really look at it, there is some parts that could have rendered a little better. The windows in the building at the back right for instance. It's a small case of the level of detail code which I dare say is a long way from where it will be. The vision distance is impressive, the quality of the details such as grass, trees and clutter rendered is better (IMHO) that other recent high profile games.

I know that I am pretty impressed by this, and it's certainly a big step up from the quality of the recently released video. I think this proves the videos less that impressive quality was a result of motion blur from the camera movement and the video being encoded to a highly compressed format prior to upload. If you really want to checkout some of the quality of this game, even before it's out of alpha stage then I really encourage you to checkout the media (screenshots) section of the games website. (http://survarium.com/en/page/screenshots)

I'm convinced that this image I've shared here isn't the best of what they've already released, and there is certainly more impressiveness to come. Hopefully we'll see some more high res game-play videos in the near future.

You know what I'm really hoping for, and maybe it's just the nerd/programmer in me, but if you remember the tech spec videos the S.T.A.L.K.E.R team released where they showed scenes from the game and talked about the rendering and engine features. (http://www.youtube.com/watch?v=Eoq-VmR21WA for example.) I want to see that done for Survarium, but that will likely have to wait till all the engine capabilities and features are decided.

Go checkout the info on the Survarium website, because, chances are there is something new that you haven't seen before. (http://survarium.com/en/page/introduction)