#Bostontech: 2014 by the numbers

With the year coming to a close we decided to take a look back at how the Boston startup community did. It was another awesome year for the community and the numbers definitely echo that sentiment. We’d like to extend a big congratulations to the companies that went public or were acquired in 2014 and here’s to a great 2015!

Friday Links: Obama codes, MSFT <3 BTC, and hacked k-cups

It rained, it snowed, but hey it’s Friday! Grab some beers and snack on some links.

Video: Video effects with avcon and ImageMagick

A couple of months ago I was at Firebrand Saints and started wondering how the effects that they run on their videos work. At Firebrand, their main bar has a few flat screen TVs showing cable channels you’d expect but every now and then one of the TVs will start displaying the video through a filter. So as you’re sitting at the bar you’ll notice Sportcenter go from regular video to what looks like Sportcenter put through a pixelated filter. Unfortunately, the fall got a bit busy and I forgot to jot this down but it recently came back to me while watching the Family Guy - Take On Me skit.

So how do you programmatically apply effects to video? After some searching around, it seems like the preferred way to do this is to convert the video to a series of images, apply the effects, and then encode the images back to a video. Since we’re on Linux the weapons of choice for this are libav (ffmpeg fork) and ImageMagick. Additionally, I used youtube-dl to grab some source video from YouTube.

Playing around with manipulating videos and images is pretty CPU intensive so I decided to do this on a c3.xlarge. Once you have a machine up, just run the following to get everything setup:

sudo apt-get update
sudo apt-get install libav-tools imagemagick python-pip python-dev build-essential
sudo pip install --upgrade youtube_dl
sudo mkdir /mnt/videos
sudo chown ubuntu:ubuntu /mnt/videos
cd /mnt/videos/

Now, snag yourself a video from YouTube:

youtube-dl https://www.youtube.com/watch?v=nfWlot6h_JM

Next, you’ll want to extract the audio and then the individual frames from the video:

mkdir frames
avconv -i Taylor\ Swift\ -\ Shake\ It\ Off-nfWlot6h_JM.mp4 -c:a copy -vn -y audio.aac
avconv -i Taylor\ Swift\ -\ Shake\ It\ Off-nfWlot6h_JM.mp4 -r 30 -f image2 frames/%05d.png

And now for the fun part - time to apply some effects to the image! As an fun first pass I ran the “paint” transform across the images. PS. Remember how we launched on that c3.xlarge? Well now we can run the transforms in parallel with xargs:

cd frames
find *.png | xargs -n 1 -P 4 -i mogrify -resize 50% {}
cd ../
mkdir -p target/frames
find frames/*.png | xargs -n 1 -P 4 -i convert {} -paint 5 target/{}

Finally, you’ll need to encode the images back together into a video format of your choice:

avconv -f image2 -i frames/%05d.png -c:v h264 -crf 1 -r 24 -i audio.aac painedVideo.mp4

Here’s a clip of the video I ended up with:

So what else can you do with this? Well that’s the awesome part! An image manipulations you can do programmatically (ImageMagick, NodeJS, etc.) you can apply to your video.

Perhaps some Mystery Science Taylor Swift?

Unfortunately this adventure has left me with more questions than answers:

  • How do you apply filters to a video in real time?
  • Would it be possible to integrate this into a rooted (or stock) Chromecast?
  • Could you build something to support user interactivity? Maybe with Canvas/nodeJS?

I’d love any thoughts, input, or ideas!

Friday Links: A pg essay, new reCAPTCHA, and marketing inspiration

It’s Friday, you did it! To bootstrap your weekend we’ve got some kickass links from the last week.