Rss

AAC export on Windows

It started with innocent request on the quicktime-java list for info on how to convert a QuickTime movie into an iPod-compatible format. The poster knew that some variant of MPEG-4 would work, but didn’t know how to get there.

Now, if you’ve looked at your export choices in QuickTime-capable apps, you might have noticed that over the last few years, Apple has added a new “Movie to iPod” movie exporter. Apps can call this pretty easily, and I said as much. But it reminded me of something I wanted to check back on, and so I started coding.

Everything was fine until I hit Windows. Anyways, here’s the code:


import quicktime.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.std.qtcomponents.*;
import quicktime.util.*;
import quicktime.io.*;

// import javax.swing.*;

public class ExportToIPod {

    public static void main (String[] arrrImAPirate) {
        try {
            // sorry for faux-main, but I need inner classes today
            new ExportToIPod();
        } catch (Exception e) {
            e.printStackTrace();
        System.exit (-1);
        }
    }

    public ExportToIPod () throws QTException, java.io.IOException {
        // open a movie
        QTSession.open();
        QTFile inFile =
            QTFile.standardGetFilePreview 
            (QTFile.kStandardQTFileTypes);
        OpenMovieFile omFile = OpenMovieFile.asRead (inFile);
        Movie movie = Movie.fromFile (omFile);

        // create QT callback
        IPodProgress ipodProgress = new IPodProgress();

        // create an iPod MovieExporter
        MovieExporter exporter =
            new MovieExporter (QTUtils.toOSType ("M4V "));
        exporter.setProgressProc (ipodProgress);
        QTFile outFile = new QTFile ("exported.m4v");
        if (outFile.exists())
            outFile.delete();
        outFile.createNewFile();
        exporter.toFile (outFile, movie, null, 0, movie.getDuration());
        System.out.println ("done");
        System.exit (0);
    }

    class IPodProgress implements MovieProgress {
        public int execute (Movie theMovie, int message,
                            int whatOperation, float percentDone)  {
            if (message == StdQTConstants4.movieProgressOpen) {
                System.out.println ("started");
            } else if (message ==
                       StdQTConstants4.movieProgressUpdatePercent) {
                System.out.println (((int) (100F * percentDone)) + "%");
            } else if (message == StdQTConstants4.movieProgressClose) {
                System.out.println ("close");
            }
            return 0; // noerr
        }
    }
}

This version contains a fix suggested by Andrea Barbieri to deal with a “file not found” on Windows when writing the exported movie (apparently, you need to create an empty file before attempting to write to it). This is also simplified from a final version that I posted to the list (and is currently in moderation hell, because it’s over Apple’s crazy-low limit of 12K), which used a GUI progress monitor that exposed annoying threading problems on Windows: the QuickTime callbacks in MovieProgress.execute() had to be put on Swing worker threads so they could legally set the ProgressMonitor’s value. That ended up being a lot more code that was beside the original point, and still only really worked right on the Mac. Sigh.

The real wonkiness of this is that when run on Windows, you don’t get audio, because the QuickTime Windows AAC exporter requires you to obtain a license from Dolby and then call a private API to unlock it (see Technical Q&A QA1347). The small developer can’t handle a five-figure licensing fee, but might be able to tell users that they need to get QT Pro on their own for $30 as a prerequisite. I’ve long thought that if Windows-based users pay $30 for QuickTime Pro, that should surely cover royalties for this codec, and it ought to unlock for all applications. The one thing I can imagine is happening behind the scenes is that Dolby’s license terms may define things in terms of applications, not libraries, so Apple can account for users of iTunes and QuickTime Player Pro, but can’t bear responsibility for third-party apps that might call into QuickTime.

Still, it’s a disappointment and a hassle, especially since Windows lacks an AppleScript-like scheme of programmatically getting the unblocked QuickTime Player to do the export for you.

Comment (1)

  1. […] grounds, another reason for secret APIs is legal entanglements. There was an example of this in one of my earliest blogs: Apple licensed AAC encoding for OS X and for its own apps on Windows (iTunes, QuickTime Player), […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.