home   >   tutorials   >   stereomorph user guide   >   1 getting started   >   1.2 installing ffmpeg (for video)

1.2 Installing ffmpeg on Mac OS (only for video)

If you are only using StereoMorph with photographs (not video) then this section can be skipped. As of version 1.6, StereoMorph has some basic video-handling capabilities. This includes calibrating two video cameras using video files, rather than using a set of photographs or already extracted frames from each video.

R does not have native support for reading frames from video files. Thus, a codec library must be installed in order for StereoMorph to extract frames from video files. Once the codec is installed and accessible from the command line, all video handling can be done within R. This section will show you how to install the video codec library ffmpeg. Currently, these ffmpeg installation instructions are only suitable for Mac OS X.

1. Download the latest static build of ffmpeg for your operating system (less than 80 MB unzipped). On the ffmpeg download site you'll find links to the static builds under "Get the packages". For example, the most recent static build for Mac OS X can be downloaded here.

2. The downloaded static build should be a compressed folder. Unzip this folder. Inside you should see an executable named "ffmpeg" (and possibly also "ffprobe" and "ffserver", which we do not need). Move the ffmpeg executable to the "Downloads" folder.

3. We will now copy the ffmpeg file into "/usr/local/bin". The easiest way to do this is through Terminal. Open the Terminal app (for entering command line codes). Note that all of the following commands are bash script (not R code). These commands should be entered into Terminal (not into the R console).

In Terminal, navigate to the folder containing the ffmpeg file using the "cd" (change directory) command. Type "cd" followed by the file path to your Downloads folder. For example, the path on my system is "/Users/aaron/Downloads".

cd /Users/aaron/Downloads

Make sure that there is a bin folder "/usr/local/bin/" using the "mkdir" command (make directory). The "sudo" before mkdir simply adds extra permissions to the commands so that the codec library will be accessible to your system (you may be prompted to type in your password).

sudo mkdir /usr/local/bin/

If this returns a line that includes "File exists", then this folder already exists on your system.

Copy the ffmpeg file into /usr/local/bin using the "cp" command.

sudo cp ./ffmpeg /usr/local/bin

Set the access permissions to ffmpeg so that it can be called by R using the "chmod" command. The numeric code "755" specifies a permission level that allows ffmpeg to be called from R.

sudo chmod 755 /usr/local/bin/ffmpeg

4. To make sure that system can find the ffmpeg command, we'll add /usr/local/bin to the $PATH variable. This is a set of directories that the system looks in when searching for a command. Use the "cd" command (but without any path after it) to navigate to the home folder.

cd

Then use the "open" command to open the bash_profile.

open -e .bash_profile

If the bash_profile doesn't exist, you can create it using the following "touch" command and then use the open command.

touch .bash_profile

The bash_profile should open in TextEdit. Add a new line at the end of the document and paste in the following:

	export PATH="/usr/local/bin:$PATH"

5. Save the bash_profile and then close and re-open Terminal (this will refresh Terminal so that it reflects the changes in the bash_profile). In Terminal use the "echo" command to print the current $PATH variable.

echo $PATH

You should see "/usr/local/bin" between colons or at the beginning of the path followed by a colon.

We can now check that ffmpeg is properly installed by simply typing "ffpmeg" in Terminal. If ffmpeg has been properly installed and can be located on the system, this should print the version number, copyright and other configuration details.

ffmpeg