Install ffmpeg on Mac OS X

FFmpeg is a great little program to help convert more or less any media format. I previously wrote an article how to install ffmpeg on the Raspberry Pi. This short tutorial will help you install ffmpeg on Mac, which is luckily a lot simpler!

The easiest way to install ffmpeg is to use HomeBrew a package manager for Mac. If you don’t have homebrew installed on your mac already, run the following command using terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once you have Homebrew installed, you can now simply install ffmpeg from terminal with the following command:

brew install ffmpeg

To install ffmpeg with specifical modules, instead of running the above command run below command or remove those modules you do not need:

brew install ffmpeg --with-chromaprint --with-fdk-aac --with-fontconfig --with-freetype --with-frei0r --with-game-music-emu --with-libass --with-libbluray --with-libbs2b --with-libcaca --with-libgsm --with-libmodplug --with-librsvg --with-libsoxr --with-libssh --with-libvidstab --with-libvorbis --with-libvpx --with-opencore-amr --with-openh264 --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-rubberband --with-sdl2 --with-snappy --with-speex --with-tesseract --with-theora --with-tools --with-two-lame --with-wavpack --with-webp --with-x265 --with-xz --with-zeromq --with-zim

Installing ffmpeg with h264 support on Raspberry Pi

The Raspberry Pi is a fantastic little computer for recording video. For about €50,- you can record in HD with full customizability and for as long as you want or have storage for. However, one issue is that the .h264 format it records in is hard to work with. It is therefore often important to convert videos to widely applicable formats like .mp4 to be able to view them properly and get the right meta information. For this I recommend the program FFmpeg.

Installing ffmpeg on a Raspberry Pi is not as simple as downloading an executable from the command line, but it is also not too difficult. Here are the steps:

Install h264 library

  1. Open a terminal window on the raspberrypi (or via SSH connection) and type in the following commands:
  2. Download h264 library: git clone --depth 1 http://git.videolan.org/git/x264
  3. Change directory to the x264 folder: cd x264
  4. Configure installation: ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
  5. Create the installation: make -j4
  6. Install h264 library on your system: sudo make install

Install ffmpeg with h264

  1. Change to home directory: cd ~
  2. Download ffmpeg: git clone git://source.ffmpeg.org/ffmpeg --depth=1
  3. Change to ffmpeg directory: cd ffmpg
  4. Configure installation: ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
  5. Make the installation: make -j4. Note this step will take a long time!
  6. Now finally run the installation: sudo make install

Note: If you are working with an older model of the raspberrypi (< 3 B+) then you may not have 4 cores available. You will then have to change make -j4 to make -j.

Convert h264 video

Now you are ready to convert a h264 video on your Raspberry Pi! Simply run the following command:

ffmpeg -i USER_VIDEO.h264 -vcodec copy USER_VIDEO.mp4

There are many options available and many other ways to convert h264 videos with ffmpeg, but this command is the quickest of all methods that I tested.

Simply store jupyter script as executable

To save a jupyter script as an executable .py script you can use the nbconvert command in terminal:

$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

Make sure to either cd into the directory where the ipynb file is located or to paste the complete path of the file.

But even better is to call the command directly in a jupyter notebook by prepending !, which will run bash code inside any jupyter script:

!jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

In this way you can save your .ipynb file to .py file in an easy and fast way and only when you need it, such as when pushing a commit to github, saving time compared to when using auto convert.

Learning a new skill: LaTeX

The last few weeks I delved into learning \LaTeX, a code language for more aesthetically pleasing article writing, especially in terms of mathematical formulas. As my research has increasingly been focused on the mechanisms underlying collective behaviour, for which I do a lot of mathematical computations, such an advanced yet simple text-editor is very helpful and overcomes the many pains I have with MS word!

(1)   \begin{equation*} v_i(t) = |\mathbf v_i(t)| = \sqrt{u_i^2(t)+w_i^2(t)}. \end{equation*}

(2)   \begin{equation*} \mathbf a_i(t)= \frac{\mathbf v_i(t+\Delta t) - \mathbf v_i(t)}{\Delta t} = \frac{\mathbf r_i(t+\Delta t) - \mathbf 2r_i(t)+\mathbf r_i(t-\Delta t)}{\Delta t^2}, \end{equation*}

(3)   \begin{equation*} \rho(t)=\frac{1}{n}\sqrt{\left( \sum_{i=1}^{n}\sin(\psi_i(t))\right)^2+\left( \sum_{i=1}^{n}\cos(\psi_i(t))\right)^2} \end{equation*}

It was quite a steep learning curve, but I managed to write my first paper with it last week. The great thing is that it is also possible to use \LaTeX in wordpress (which I used to create this website). It is also the standard language for drafting preprint articles, which is increasingly suggested and done in the biological sciences, thus a very relevant skill to learn.

How to create an interactive scientific plot online

In my previous post I showed a fully interactive online graph of one of the plots in my recent paper on leadership in sticklebacks. In this follow-up post I will explain how to easily create such an interactive plot yourself. To be able to do this you will need some experience with the R-language and ideally with ggplot2.

First create an account at plot.ly, which is free. After you have created your account, go to “settings” and click on “generate API key”. You will need your username and this key to link your account to R.

Now you have your account ready start-up R and set-up the R workspace:

Read further…