8

Well, my question is this: Is that possible to make time-lapse movies with Mathematica?

Here is some more explanation:

Watch this YouTube video that is a wonderful example of time-lapse movies. Time-laps movies are made by taking a photo every few seconds and attaching the photos together to make a movie which is played at say 30 fps. I have taken 180 JPEG photos with my digital camera. I wonder if I can use Mathematica to convert them into a 6 sec movie. Normally, this should be an easy job using the following two lines of code:

frames = Import /@ FileNames["*.JPG", "/path/to/folder/"];
Export["/path/to/folder/export.avi", frames]

But, because the total size of the images is too large (~1.2GB), I get the following error:

No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry.

I get this error when loading the pictures, so the export process has not yet began.

Is there any easy way to fix this issue? e.g., loading only a few pictures at a time.

Helium
  • 4,059
  • 24
  • 41
  • 8
    I think that Mathematica is really not the right tool for the job. There are many programs out there that can create a video out of a series of stills, why don't you try them? http://superuser.com/questions/624567/ffmpeg-create-a-video-from-images – Szabolcs Oct 06 '14 at 11:01
  • (When I need to create a long animation with Mathematica, I prefer to export stills and assemble them into a video using other tools.) – Szabolcs Oct 06 '14 at 11:04
  • 4
    I agree with Szabolcs that using other software will be the easiest route. If you insist on using Mathematica and are on Windows, you could try my video import/export package from here. It writes frames one by one so you need only have one frame in memory at a time. You can't export to AVI though, only WMV or MP4. – Simon Woods Oct 06 '14 at 11:05
  • @SimonWoods, probably you should put that as an answer? – rhermans Oct 06 '14 at 15:08
  • @rhermans, done. – Simon Woods Oct 06 '14 at 15:29
  • 1
    @Szabolcs: The reason I want to use Mathematica is that I failed to use free tools such as ffmpeg and avconv. I thought there might be a simple way to use Mathematica to get the job done since my project is relativly small. Anyways, I agree with you that Mathematica is not the best tool. Aside from the speed and memory issues, sophisticated time-lapse software does a lot of interframe processing for shake reduction and exposure compensation to improve the output video. – Helium Oct 06 '14 at 16:37

1 Answers1

6

If you're using Windows you can use my MathMF package (see here). It is designed for frame-by-frame import and export of video files. The code would then look something like this:

frames = FileNames["*.JPG", "C:\\Users\\Simon\\Desktop\\test images"];

<< MathMF`    

MFInitSinkWriter["C:\\Users\\Simon\\Desktop\\test.wmv", 300, 300]    
Scan[MFSendFrame @ Import[#] &, frames]    
MFFinaliseSink[]

A limitation is that you can only write MP4 and WMV files, not AVI.

Simon Woods
  • 84,945
  • 8
  • 175
  • 324
  • Thanks Simon for the answer. I have VS 2013 installed, but I get the following error: CreateLibrary::cmperr: "Compile error: "C:\ Program Files (x86)\ Windows Kits \ 8.0\ include \ um \ propvarutil.h(20) : fatal error C1083: Cannot open include file: 'shlwapi.h': No such file or directory" – Helium Oct 06 '14 at 16:25
  • Do you have any idea how to fix it? – Helium Oct 06 '14 at 16:25
  • @Helium, googling "missing shlwapi.h" suggests you might need to install/repair the Windows SDK. On my system shlwapi.h is present in both C:\Program Files (x86)\Windows Kits\8.0\Include\um and C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include. Alternatively you could try using the pre-built MathMF DLL. – Simon Woods Oct 06 '14 at 17:00
  • Thanks Simon. I used the precompiled DLL and it solved the issue. – Helium Oct 08 '14 at 06:40
  • @Helium, that's good to know. I hope you find it useful. – Simon Woods Oct 08 '14 at 08:07
  • Surely that's useful. As I mentioned in my comment below the question, if the camera shakes, you need a shake reduction algorithm too. This was not the case for me. I used a fixed tripod to take the shots. My other concern was performance, but I can say I am quite happy with the performance of your library. I don't have any other program for comparison but I think because your library is just a wrapper for windows API (written in C/C++ and tuned for performance) it's pretty fast. – Helium Oct 09 '14 at 06:17