8
$\begingroup$

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.

$\endgroup$
6
  • 8
    $\begingroup$ 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? superuser.com/questions/624567/… $\endgroup$
    – Szabolcs
    Oct 6, 2014 at 11:01
  • $\begingroup$ (When I need to create a long animation with Mathematica, I prefer to export stills and assemble them into a video using other tools.) $\endgroup$
    – Szabolcs
    Oct 6, 2014 at 11:04
  • 4
    $\begingroup$ 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. $\endgroup$ Oct 6, 2014 at 11:05
  • $\begingroup$ @SimonWoods, probably you should put that as an answer? $\endgroup$
    – rhermans
    Oct 6, 2014 at 15:08
  • 1
    $\begingroup$ @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. $\endgroup$
    – Helium
    Oct 6, 2014 at 16:37

1 Answer 1

6
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ 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" $\endgroup$
    – Helium
    Oct 6, 2014 at 16:25
  • $\begingroup$ Do you have any idea how to fix it? $\endgroup$
    – Helium
    Oct 6, 2014 at 16:25
  • $\begingroup$ @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. $\endgroup$ Oct 6, 2014 at 17:00
  • $\begingroup$ Thanks Simon. I used the precompiled DLL and it solved the issue. $\endgroup$
    – Helium
    Oct 8, 2014 at 6:40
  • $\begingroup$ @Helium, that's good to know. I hope you find it useful. $\endgroup$ Oct 8, 2014 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.