Posts Tagged ‘Mac OS X’

Splitting and Extracting MPEG video files with MEncoder

Monday, January 2nd, 2012

One of the nice things about MythTV is that it lets me save any broadcast as an unencrypted, DRM-free mpeg file.

I recently found out how to use MEncoder to split and trim those mpeg files into single or multiple clips.

MEncoder is a good tool to use because it’s free (as in both freedom and beer), and runs on all major platforms (there are even pre-built binaries for Mac OSX).

MEncoder has two command line options, -ss and -endpos, which let you define the start or end position of the clip you want to extract.

Unfortunately, the default command doesn’t work with mpeg files.

The work-around is to convert the mpeg file to avi format first:

$ mencoder original.mpeg -ovc lavc -oac lavc -o original.avi

Then, create a copy starting or ending at a given point in time, defined as hour:minute:second using either the -ss or -endpos options.

For example, to extract a clip from the 17 minute 50 second mark to the 57 minute 47 second mark from a one-hour file, these two commands will do the trick:

$ mencoder -ss 00:17:50 -oac copy -ovc copy original.avi -o clip_start.avi
$ mencoder -endpos 00:39:57 -oac copy -ovc copy clip_start.avi -o clip.avi

Note that the -endpos was recalculated for the second command as 39:57, not 57:47.

That’s because the clip_start.avi file is 17 minutes and 50 seconds shorter than the original, and so we need to recalculate the clip end position in terms of the new length.

The file clip.avi contains the clip from 17:50 to 57:47 extracted from the original file, and we can discard the intermediate clip_start.avi file.

It takes two commands because MEncoder seems to ignore the second -ss or -endpos option it finds, and uses just the first one.

It would be nice if it would just let us do this instead:

$ mencoder -ss 00:17:50 -endpos 00:57:47 -oac copy -ovc copy original.avi -o clip.avi

 

A quick guide to DIY animated videos

Friday, December 9th, 2011

Now that TeamWork.io is out in public beta, I wanted to see how difficult it would be to make an intro video, similar to what Google did for its Voice service.

The idea is based on the observation that most people don’t read web pages and would rather watch a video than skim even a brief description.

So with no background in video animation (and no cash to pay anyone to do it for me), I set out to see how far I could get on my own, using free software tools.

I wrote a script consisting of a few frames of stop-motion animation, which I thought would be the simplest to do.

The script starts with someone planning a project, surrounded by a few gantt charts and similar project management paraphernalia. Soon, though, the various charts and forms he needs to process multiply until he’s overwhelmed, and the screen fades to black.

From out of the darkness, a bright light emerges, and the TeamWork.io logo emerges.

That’s just part one. The next step would be to explain how it works, but part one was enough on its own to keep me busy for a while.

Fortunately, there are several free tools available for this kind of production.

Free as in Beer

I started with GIMP, the GNU community’s answer to PhotoShop.

GIMP let me create all the images I needed for part one: the charts and forms smothering our hero are easily done incrementally, by just adding more junk on top and saving each edit as a separate file.

Going from dark to light was also fairly simple, since GIMP has a nice selection of effects filters, one of which, Supernova, let me create a small sunburst in the middle of the black field, then expand it slowly, until the field was white.

Looking back at the first draft, I see that I rushed it a bit too much, but that is a problem with stop-motion: updating changes frame-by-frame is tedious, and there’s always the risk of jumping ahead too much in any given snapshot.

Next, I used Pencil to put the individual frames together with sound and create a single movie file.

Pencil is capable of exporting to QuickTime’s .mov format at a default 851×715 screen resolution, so to keep things simple, I made all my GIMP images 851 pixels wide by 715 pixels tall.

It’s not an ideal aspect ratio for YouTube, though, and I noticed black filler bands on both sides after uploading, but it doesn’t get in the way of comprehending the video.

Pencil also let me add a soundtrack and preview the entire composition of moving frames and sound, but somewhat annoyingly, it didn’t export with sound.

This is a long-time bug, apparently, but I was able to get around it using MEncoder (more on that later).

Finally, I used the speech synthesizer built in to Mac OSX to produce the voice-over.

Say, a free tool for capturing the Mac’s Text-to-Speech output as a file, was invaluable for this task.

Say produces .aiff format sound files, which can be imported as-is into Pencil.

As nice as it is to write a script and have it turned into speech immediately, the sound of a computer-generated voice-over is less than ideal.

“Alex”, by far the best-sounding of the synthesized voices, still came out clunky and awkward.

It seems for the final video I need to bite the bullet and use a real human voice.

The Final Draft Cut

Once I was happy with the sequence of still frames in Pencil, and I made sure the sound synched (more or less) with the video, I created a .mov file of the project.

I could play the .mov file in QuickTime, but, as noted earlier, there was no sound.

That’s where MEncoder comes in, since it’s able to add a sound layer to any video file, using a single command line instruction:

$ mencoder pencil-output.mov -o final.avi \
  -ovc copy -oac copy -audiofile sound.mp3

The only hitch is that it didn’t work with my .aiff file, so I had to convert it to .mp3 format first.

Fortunately, ffmpeg makes this easy:

$ ffmpeg -i sound.aiff -f mp3 -ab 192 \
  -ar 44100 sound.mp3

Here’s the first draft in all its (10 seconds of) glory:

Fun with LILO and rEFIt: Resolving Boot Errors After an Upgrade

Sunday, May 9th, 2010

When debian is the only OS running on a machine, running apt-get update and apt-get upgrade works well.

Under my Mac/Debian dual boot setup, though, upgrading has always been something of a crap shoot.

The most recent problem was this error, after an upgrade and a reboot:

EBDA is big; kernel setup stack overlaps LILO second stage

This solution was closest to my situation, and although the advice was helpful, I managed to fix mine with fewer steps:

  1. Boot the Mac partition (which, fortunately, was still working)
  2. Run Terminal, and use the diskutil list command to find out where Linux was installed on hard drive (in my setup, it was /dev/sda3)
  3. Reboot, this time with the Debian install disc I used to install Debian originally
  4. Choose Advance Options -> Rescue Mode -> Shell mounted on /dev/sda3 (this saved me the effort of doing all the mounting described in steps 1 through 5 of the ubuntu forum solution)
  5. Inspect /etc/lilo.conf (it looked correct, so I didn’t make and edits)
  6. Update lilo: /sbin/lilo -v
  7. Reboot (my mistake was doing this from the rescue mode shell, when I should have exited and rebooted out of the installer)

This time, when I chose Linux from the rEFIt menu, the kernal loaded normally (/dev/sda3 was scanned because of an improper unmount, or lack thereof, but fsck did its job without incident), and my linux partition was usable again.

Web Video Downloading Made Easy

Friday, March 19th, 2010

Just over a year of using Mac OS X (albeit in dual mode with Debian), and I continue to be surprised by how simple and well thought-out its features are.

In this case, I was happy to see how simple downloading web video is (especially when the site hosting the video doesn’t want you doing so).

Eric Ripert’s web site has a terrific series of recipe videos, such as this one, for preparing red snapper fillet:

Red Snapper Fillet Recipe Video

Unfortunately, there is no video download option.

That’s where Safari comes to the rescue.

If I visit the site in Safari, all I have to do is start playing the video, then open Safari’s Activity Window, either by choosing it in the Window menu bar, or simultaneously pressing the Command-Option-a keys:

Safari's Activity Window

The video will be the largest file (usually) in the list, in FLV format.

With that file selected, holding down the Option key (and if you’re using a PC keyboard without keys remapping for OS X, remember that the Alt key means Option) and double-clicking will automatically start downloading the file:

Video downloading

The great thing about this technique is that it will work for most video sites on the web.

DRM-Free DVD Player & Ripper on Mac OS X

Sunday, September 20th, 2009

MPlayer is a terrific DRM-free multimedia player.

It also contains Mencoder, which is a great tool for ripping dvds (among other things).

Mac Ports has two versions available, MPlayer and mplayer-devel but neither of them built properly on my Mac (OS version 10.5.8).

Fortunately, the pre-built binaries at this site worked beautifully.

After downloading and unzipping them, I moved the two binary files, mplayer and mencoder, into /opt/local/bin so they appear in the default command-line path.

Since Apple’s built-in DRM-enforcing DVD player is set to startup when a DVD is inserted, I changed the default action in the System Preferences under Media Preferences to be “Ignore” for the “When you insert a video DVD” option.

Now, I can play any DVD track with mplayer in Terminal, like this:

mplayer dvd://[track number]

MPlayer also supports other playback options like subtitles, etc. (docs related to DVD playback are here).

Ripping a DVD track is more complex, but the docs have good examples to follow.

I wrote this shell script to simplify the process:

#!/bin/sh

# source for mencoder options:
# http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
# (using 11.8.5.2. NTSC DVD example)

if [ $# -eq 2 ]
then 
  mencoder dvd://$1 -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
    -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 \
    -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 \
    -o $2.mpg
else
  echo "mencoder_dvd_rip.sh [dvd track number] [output filename]"
fi

So to rip track 0 of a DVD (which is usually the main movie track), all I have to do is this in Terminal:

 mencoder_dvd_rip.sh 0 movie

How to Install Debian as a Dual-Boot (with Mac OS X) on the Mac Mini

Monday, February 16th, 2009

Update: March 31, 2013 — I’ve since ditched this setup in favor of running ubuntu with a lightweight window manager under VirtualBox instead.


Inspired by this how to guide, I recently installed Debian 5.0 (a.k.a. “Lenny“) on a new Mac Mini.

My experience was basically the same, with a few key differences (highlighted):

  • Started MacOS X
  • Ran BootCamp (my version of OS X already had BootCamp installed), and created a 32 gb sized partition for “Windows” (BootCamp assumes the partition is for XP). As per the original instructions, I quit BootCamp when it prompted for the Windows XP CD.
  • Downloaded and installed rEFIt. Piece of cake.
  • Downloaded and burned the i386 netinst CD version of “Lenny“.
  • Put the netinst CD into the drive and rebooted; the next time the Mini started, I saw the rEFIt menu.
  • At the rEFIt menu, I scrolled to the “partition map tool” and, as suggested, copied the GPT partition map into the MBR. It left me with three partitions:
    1. Boot
    2. Mac OS X
    3. Empty (where Linux is going to go)
  • Exited the partition map tool and booted Linux from CD; the familiar Debian install screen appeared. Two critical steps followed.
  • At Debian’s disk partition step, I chose “manual” (using any other option would have given the Debian installer the all-clear to wipe out Mac OS X from the hard drive). Here I re-sized partition #3 to 31 gb, and created a fourth partition of 1 gb for swap. The final table was:
    1. Boot
    2. Mac OS X
    3. ext3 mounted as “/” with the bootable flag on
    4. swap
  • The installer continued, but when it prompted me to install GRUB, I hit “Go Back” and installed LILO instead (the original guide says install GRUB and then edit it manually; I simply could not get that to work, so I tried LILO instead, and LILO worked), allowing LILO to write to the Master Boot Record (MBR)
  • After the Debian install finished, I rebooted, and saw the rEFIt menu offered two choices: start Mac OS X or Linux