Converting GIFs to Video

I’m still working on the digital picture-frame.  The frame downloads animated GIFs from the internet onto a Raspberry Pi and displays them on a screen.  The GIF should loop for a period of time before move onto the next image.  The script currently pulls the top-ten animated gifs from Reddit’s GIFs forum.  For an example, I am using this image, pulled at random:

Downloaded from Reddit
Downloaded from Reddit

I am having severe performance issues displaying the GIFs on the Raspberry Pi, and it seems my best option is to convert the GIF to a video format.  I want to play the video in a loop – and hopefully the Raspberry Pi can handle video better than the animated GIFs.  Installing ffmpeg on the Raspberry Pi was trivial.  I am loving package managers these days.

$ apt-get install ffmpeg

I tried to convert the GIF files directly to an AVI, but the videos were all coming out one frame.  I found some discussions online showing I should convert the Gif into component frames – then convert the frames to video.  I ran:

$ convert 0.gif out%05d.jpg

The command separated the GIF into components, but only the first frame looked right.  The rest of the frames contained severe artifacts like this:

8th Frame with bad artifacts
8th Frame with severe artifacts

I used the -coalesce flag to correct the issue, and the frame came out without any severe artifacts.

$ convert -coalesce 2.gif out%05d.jpg
8th Frame without severe artifacts
8th Frame without severe artifacts

I ran ffmpeg on the resulting JPG frames with an AVI output.

$ ffmpeg -r 25 -i out%05d.jpg -y -an test.avi

The video runs smoothly in VLC on my PC.  You can see the results here.

Still to do:

  • Bake the GIF -> Video conversion into the ruby script
  • Write the display script to loop the video on the Raspberry Pi
  • Dynamically change the frame-rate depending on the properties of the GIF

Raspberry Pi Animated Gif Picture Frame

I’ve been toying with building a digital picture frame for a couple of years.  I bought my Raspberry Pi for this project in August 2012, but I never built it.  A couple of weeks ago, I was talking to my friend Camron about the project, and we decided to work on it together.

I wanted the frame to work like an appliance – plug it in, play images.  Camron wrote most of the code before I got there.  We had two programs:

  • A ruby script which automatically download animated gifs from a source and places them in a directory.
  • Play the gifs on a screen using Gifsicle

We installed Arch Linux on the Raspberry Pi, but we couldn’t get Gifsicle to find an X session to display the gifs.  We decided to dump Arch and flashed the SD drive with Raspbian.  Raspbian boots into the window manager directly, so we were able to play the gifs.

Unfortunately, the Raspberry Pi was running at 100% CPU, and the gifs were very choppy.  Camron wrote a little HTML file with some JavaScript to play the gifs in a browser.  The gifs ran a little smoother, but it wasn’t great.  Anything form Reddit’s high quality gifs crashed the browser.

I’ve seen a Raspberry Pi used as a media player, so I know the hardware can handle a little video, but big gifs without any hardware help don’t seem viable.  I have a couple more things to try – optimizing the gifs, finding an alternate gif player, transcoding the gifs to video.

Update:  It seems Twitter is already doing gif to mp4 transcoding.

Rails Development: Mac vs Linux

My employer recently upgraded my work laptop to a late-model Macbook Pro. I maintain an internal Rails application with a colleague, and we needed to setup our development environments on the new machines. We went through the process of installing RVM, Ruby, Postgres, and supporting software. Building the environment took us more than a day after all was said and done. We ran into one issue after another – nothing we couldn’t solve with a little Googling – but it was still a lot of incremental steps.

At the same time, I am working on a small hobby project and needed to build a from-scratch Rails 4 application. I was going to install the server on my personal Windows computer. At the same time, I’ve been working on a separate Raspberry Pi project. The Raspberry Pi sits on my network, so I decided to install the rails server on the RasPi instead of my Windows machine. The Linux installation was easy, and almost everything worked on the first try.

The Macbook Pro is ubiquitous in Rails development circles, and I’ve been developing Rails on my Mac for a couple of years. I always assumed the ubiquity of Macs was due to the ease of environmental management on the Mac compared to Linux. I’m starting to believe the opposite. The installation on Linux was painless compared to the Mac install. I haven’t used much linux in a number of years, and I was barely proficient when I was a regular user. I am shocked by how easy package management has become. I installed RVM, Ruby 2.1, and Rails without any hassle. The installation was not fast, but I believe this is because I was compiling source on my wimpy RaspberryPi. As RVM said:

this may take a while depending on your cpu(s)...