Showing posts with label pages. Show all posts
Showing posts with label pages. Show all posts

Wednesday, December 24, 2014

Video Bloat in Pages ePub Exports and How to Fix It

Pages 5.5.1 for MacOS X has an excellent ePub export option. That export option includes elements of ePub 3 such as embedded audio and video so Pages, being free with MacOS X, is a very attractive application for teachers at all levels who want to create eTextbooks containing rich media. However, there is a problem with Pages ePub video that this blog post will identify, document and provide solutions for. First, the problem statement.
Starting with Apple’s ePub template, we create a test project. To follow along, download the “ePub best practices” document from Apple’s “
Creating ePub files with Pages” support document, open it in Pages and do File > Save as template … which makes this template available to us now and in the future.
After we have the template saved, we add a 75 MB 1280 X 720 video with a duration of 5 minutes and 36 seconds (
download) to the still open Pages document. It now looks like this:

Video Quality Blog Post.001

The next step is to export this document as an ePub (File > Export To > ePub …). As we look at the output of this process in the Finder, we see that the ePub is about 280 MB despite the fact that the parent file, the Pages project, is only 80 MB in size. Here’s what that looks like:

Video Quality Blog Post.002

As far as I know, there is no application that can add useful data to source video. So, what is going on? Could this be an instance of unnecessary …

Video Quality Blog Post.003


… video bloat? The following delves into how to investigate that possibility. The first step in that investigation is to download ePub Zip Unzip so that we may peer inside the ePub file structure, find the video file and compare it with the original that was initially fed to Pages. This app has a very simple user interface that looks like this:

Video Quality Blog Post.004

The reality of an ePub file is that it is actually what is called a package file, a folder containing a variety of files that has been archived into a single file using the Zip compression algorithm. What ePub Zip Unzip does in this first step is simply to unzip the file into the folder it started out as. Once we have unzipped the ePub file, we can open this folder and examine its contents. Specifically, we’re interested in the video media because this is the only thing that we added to the Pages project beyond the template itself. Here is what we see:

Video Quality Blog Post.005


Clearly, we are looking at an instance of file bloat. The video file has grown more than 200 MB beyond its original size. This is not likely to be an improvement. To determine why this is so, we turn to another free, open source app called MediaInfo. Note that QuickTime X Player will also provide the most essential of this data but MediaInfo can provide additional data that is very useful to advanced users. Here’s what MediaInfo says about the original file:

Video Quality Blog Post.006

… and the video file exported by Pages:

Video Quality Blog Post.007


Here’s a table summarizing this analysis:


Video Quality Blog Post.008

The change in suffix from .mp4 to .m4v is inconsequential but the change in bit rate is key. The bit rate is 3.5 times greater than the source file! This is precisely what has inflated the file size. The formula for file size is bit rate times duration. So, will our readers benefit from this larger, longer to download file? Let’s see.


Link to full size version of this video: click here (opens in a new window)


Quite frankly, I see no improvement. Certainly not an improvement justifying an additional 200 MB in file size.

So that’s the problem. Now, how do we fix it? We already have some terrific clues. We have the ePub on the operating table and opened up so we can see and operate upon all of the internals. Why not try to replace the bloated video with the more efficient one that we started with. Here’s how:

First, we move the better file into the same location as the bloated version. Note that they have different names. This complicates things just a little bit. So copy the good video into the same folder as the bad video, like this:

Video Quality Blog Post.010


This is a simple drag and drop operation in the Finder. Next, we copy the full name of the bad video like so:


Video Quality Blog Post.011

Move the bad (bloated) file to the trash like so:


Video Quality Blog Post.012


Select and paste the name of the bad (bloated) file renaming the good file like so:

Video Quality Blog Post.013

Accept the change in the file suffix like so:

Video Quality Blog Post.014

Zip the folder back into an .ePub file like so:

Video Quality Blog Post.015

Enjoy the success of having reduced the file size of your ePub.

Video Quality Blog Post.016

Test the results in the iBooks.app to confirm that success.



Monday, September 27, 2010

With the Pages application (part of Apple's iWork suite), we can now easily include audio and video in our ePub-based eBooks. These advanced eBooks are viewable only in the iBooks application on an iPad, iPhone or iPod touch but these iOS devices are selling like hotcakes so that's OK for now. The others will catch up eventually.

However, easy as it is to include audio and video in an ePub using Pages, we still have to exercise care in preparing these media files for our eBooks. It's is quite easy to create a video file that won't play back properly or at all and we don't want to inflict that kind of experience on our readers.

Obviously, Flash is out so we are talking about files that are in an MPEG-4 or QuickTime container. But that's not all. We also have to make sure that the CODEC used for the video track is H.264 and the CODEC used for the audio track is AAC. In addition to that, we must take care to keep the data rate, expressed in bits per second, below certain threshold values. Here, for example, are the
technical specifications for the iPad. Read the sections on "Audio playback" and "TV and video" to get the general idea. No need to study or memorize these, just get the flavor and we'll move on.

These specifications are all aimed at accommodating the requirements of the firmware chips in most mobile devices that decompress and display video. Using dedicated and specialized firmware is far more efficient than decompressing video in software. This yields superior performance and a good video experience.

So, with all of these specifications, it should be easy to get things wrong, right? No, that's not the case. There are lots of virtually foolproof ways to make sure that the audio and video you include in an ePub file will play back properly in iBooks on an iOS device, currently the only venue where this kind of media can be played back in an ePub file.

There are two general scenarios that will determine how best to proceed: whether we are creating the media from scratch or repurposing extant media. Let's examine both cases.

Creating and exporting media from scratch. This is easiest scenario but has the most variations. If you are creating video with or without an audio track, always export using the iPhone preset (480x360 ). This will usually keep the data rate below one megabit per second which will perform very well on any iOS device. There are many applications that create video. Similarly, audio-only applications have iPhone presets. Here's a screencast medley of popular MacOS X apps that export video and audio that will be playable in the iBooks app on iOS devices.



Repurposing extant media. There are several good approaches to this task depending upon the characteristics of the source video. The general goal is to convert the source file into a 480x360 H.264/AAC file in an MPEG-4 or QuickTime container. Source files can be almost anything (Flash, DVD, Windows Media, AVI and so on) but you may need to extend your MacOS X system with extra QuickTime components in order to handle all of these. Here is a short list of the most important QuickTime components to add:

Perian (free) Formats supported: AVI, DIVX, FLV, MKV, GVI, VP6, and VFW
Flip4Mac WMV ($29) Formats supported: Windows Media video and audio

Here is a list of applications that are useful in repurposing non-MPEG-4 files to the proper iPhone specs:

Handbrake 0.9.4 (free) Converts DVDs to MPEG-4, including iPhone output.
Miro Video Converter 2.2 (free) Converts almost anything to MPEG-4, including iPhone output.
CosmoPod ($12) Downloads and converts YouTube and other Flash video to MPEG-4 iPhone output.
QuickTime X Player (free) Converts anything it can play (see components above) to iPhone format.
MacOS X Automator
Movie Services (free) Converts andy QuickTime movie to iPhone format.

Here's a screencast medley of these applications at work repurposing video that will be playable in the iBooks app on iOS devices.



Tuesday, August 31, 2010

Apple's iWork Suite is composed of three applications: Pages, a word processor and page layout application, Keynote, a slide show app like Powerpoint and Numbers, a spreadsheet app like Excel. Microsoft Office (Word, Powerpoint, Excel, etc.) is also available to MacOS X users. The essential difference is that iWork is focused on elegance and ease-of-use whereas Microsoft Office is focused on power, cross-platform compatibility, feature parity and so on.

An update to the iWork suite late last week included a new export option for Pages. The Pages app can now export a document as an .epub file, the predominant standard for eBooks. While there have been other WYSIWYG editors for producing ePub documents such as Sigil and eCub, Pages is the first mainstream commercial application to support ePub export. What's more, Pages is somewhat ahead of the standard by enabling the inclusion of audio and video media in an ePub document.

In addition to the Pages update, Apple has provided this support page which describes a number of ePub best practices and includes a link to download a very helpful sample file that can be used as a template or a source from which the proper ePub styles may be imported. I used it as a template by saving that file with a different name and then replacing the content with my own.

The key to creating a properly formed ePub document is to select the appropriate Pages Section types (Title Page, TOC, Forward, Chapter, etc.) and use the appropriate Paragraph Styles as you insert the content.

Here's a brief tour of the Pages template showing how Sections and Paragraph Styles are used to define the structure (cover, TOC, chapters, etc.) of the exported ePub file. First, we look at the template as Apple provided it and then with a different file name and different content.