Installing FFMPEG for Raspberry Pi


FFMPEG is one of those tools I use when I just want to quickly hack together a video and don’t need fancy things like editing, titles, or a user-interface. Compiling on a regular computer isn’t easy, but compiling for the Raspberry Pi takes a little more patience and care. I also wanted to include support for H264 video, which needs to be installed before compiling FFMPEG.

There are lots of examples on the web, but what worked for me was a combination of a few of them, so here’s what I did. Note many of these commands may require  sudo appended before (commands like git , ./configure, and make )

    Run the following commands, one at a time.
    Anything else you would like to install should be done now, before compiling FFMPEG. This includes MP3, AAC, etc.
    Add lines similar to the  --enable-libx264  for anything else installed above. This may take a REALLY long time, so be patient.

    As Malcshour notes, if you have a Model B+ you can use make -j4  instead of just make  to take advantage of all four cores!

    To test your new install, simply run the command ffmpeg . If you don’t get any errors, you’re all good. What did I do with my new tool? I built a bot that generates random guitar chords.


Setting Up Raspberry Pi To Run Bots


Where’s the server? It’s under the table next to the couch!

The Raspberry Pi can be used for lots of cool projects, but because it’s cheap, small, and consumes far less power than a regular laptop or desktop, it’s perfect for applications where a computer needs to be running constantly, such as a server for running Twitter bots!

I have seven bots running at the moment, tweeting things like art assignments, “would you rather?” questions, and links from a 1995 “internet directory” book. Most of them post once an hour at varying times during the hour, meaning I need to run them from a computer that is always on, 24/7. I had previously used a Mac Mini, but it felt wasteful to have such a powerful computer that consumed so much energy, just to post 140 characters to Twitter.

By way of comparison, here is the energy use of a 2012 Mac Mini and a Raspberry Pi Model B:


The Mac Mini also creates a lot of heat, even when not really doing anything. It’s average heat dissipation is 126 BTUs per hour, or the equivalent of 1/3 of a human!

Update: turning off video output (via RCA/HDMI) can save power consumption even more, especially for battery operation. Turn it off using the following command: /opt/vc/bin/tvservice -off, though it may not work on your device.

That’s enough convincing: let’s run some bots!

Continue reading “Setting Up Raspberry Pi To Run Bots”

Tutorial: Twitter Bots


UPDATE 9/14: A few things have changed for setting up a Twitter application since this tutorial was written. The main change is you will need a phone number to register your app. Most of this guide should be fairly close to the current system, though the screenshots may look a bit different.

Creating Twitter bots, automated text-generators that spew spam, poetry, and other things, can be a bit of a confusing process. This tutorial will hopefully get you through the tough bits and make bot-building possible!

For this tutorial I will be using Python, a language whose simplicity and natural syntax is great for working with text. However, this tutorial should be easily portable to your language of choice. I assume you know at least enough programming to write your own algorithmic text; if you need some help, I would suggest one of the myriad resources including Learn X in Y Minutes. Finally, this post is written from a Mac user’s perspective – if you use another OS and have suggestions or required different steps, my apologies and let me know so I can add them.

If your programming is not up to snuff, you might consider using IFTTT to trigger a Tweet. While the range of possible text is much more limited, you can easily do things like post a Tweet when tomorrow’s weather is forecasted to be nice or you like a video on Vimeo! (You can also use this as a backup for storing your bot’s awesome Tweets.)

You can view the source files used here, screenshots, and other miscellany for this tutorial on GitHub.

Continue reading “Tutorial: Twitter Bots”

Installing OpenCV on Mac

UPDATE: Mavericks users were likely frustrated for the last few weeks trying to install OpenCV. It appears the problem has been fixed, and these instructions should work without issue.

My previous post on installing OpenCV for Mac users is one of the most popular on this site (which is simultaneously surprising and fantastic). However, I recently switched from using MacPorts to Homebrew – users that need to migrate existing installs can check out this guide.

Still complicated but thoroughly do-able, here is how to install OpenCV on a Mac running Mountain Lion:

  1. Open Applications > Utilities > Terminal…
  2. Install Homebrew by typing the following into Terminal
  3. Run the command brew doctor to check for any errors
  4. While normal installations using Homebrew are very straightforward, for some reason OpenCV requires an extra step – you need to install an add-on called science:
  5. Then you can run the usual Homebrew command to install OpenCV:

    If this fails, it may be that you have ffmpeg installed – if so, try this instead:
  6. This may take several minutes, so be patient!
  7. Homebrew may tell you that you have to update  PYTHONPATH  – if so, open your favorite text editor, click File > Open… and hit command+shift+. to see hidden files
  8. Navigate up to your home folder and open the  .bash_profile  file – if it doesn’t exist, create it yourself
  9. Add the line suggested by Homebrew, probably something like:
  10. Save the file and close it – you may also have to exit Terminal and open it again
  11. Test by opening Python:

    Then try to import OpenCV:
  12. If you don’t get any errors, you’re all set! Now go enjoy a real beer!

Hope this helps! Problems, suggestions – leave them in the comments.

Easy Processing > Illustrator Export (bonus SVG export)

After a long time playing with ideas for an easy Processing to Illustrator tool that would allow fancy coding to be piped directly into Illustrator for further layout (and was vector-based the whole way through – no terrible rasterization allowed), I now have a really easy solution that doesn’t involve any fancy code, external libraries, or command-line nonsense.  The process:

1. Write your code as usual, but add PDF export


2. Run once and use File > Place… to insert the PDF into your AI document (do not simply open the document, as changes will not be reflected) — NOTE: be sure “Link” is clicked when placing


3. The resulting PDF, placed into the document as a single unit


4. Make changes in Processing and re-save the pdf – here we reduce the number of lines from 1,000 to 10


5. Back in AI, you will be prompted to update the pdf – easy!  No need to ask it, simply moving between programs updates your work


6. Awesome, done.

A dead end for this process was SVG export from Processing, which is not super easy (surprisingly).  Here’s my hack that uses Inkscape’s command line tools:

Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion

A video still created programmatically; thousands of these can be combined into video using the ffmpeg library – faster and cleaner than a clunky Final Cut project

UPDATE 2: I ran into an error trying to install ffmpeg using these instructions yesterday.  However, installing using MacPorts worked like a charm! I suggest following the instructions for installing LAME first, then use MacPorts to install ffmpeg using the following command:

UPDATE: Having switched recently to Lion, the install below didn’t quite work.  With a small tweak, it appears to be ok – see below for details.

Well, it might not be Lion (doing live musical performance with my laptop makes me leary of new operating systems) but after finding little recent info on installing ffmpeg on a Mac, I’ve put together this basic outline.  For someone who isn’t great at installing libraries using Terminal, it wasn’t completely straightforward, but it works!  You will need the Apple Developer Tools to make this work (so far as I can tell).

UPDATE: I did a fresh install of XCode and had to do one small addition to get everything to compile.  For details, see this post.

This tutorial is based on the tutorial by Stephen Jungels, with some explanation and consolidation targeted at noobs (like myself).  Definite hat tip, Stephen!

The basic steps are as follows, full details after the break:

  1. Install Git
  2. Download LAME
  3. Download ffmpeg
  4. Find or create folder to install to
  5. Install LAME
  6. Install ffmpeg
  7. Test

Continue reading “Installing ffmpeg (and LAME) on Mac Snow Leopard and Lion”