Thursday, May 16, 2013

Video in Kindle books, thanks to EPUB3

Yesterday, I wrote about how you can call external audio/video files in an EPUB3 document. This works brilliantly in iBooks and Readium, but so far, nowhere else. What happens when it doesn't work is actually pretty interesting. According to the spec, you can add a fallback message, and indeed a fallback photo or link. In this case, I've used the poster image as a fallback image.

<p>Does everyone have their own cat videos? I sure do. Here are Nighty and a very small Momo playing the box game.</p>
    <video controls="controls" poster="image/poster.jpg" width="384" height="276">
    <source src="http://www.elizabethcastro.com/epub/examples/catbox2.mp4" />
    <source src="http://www.elizabethcastro.com/epub/examples/catbox2.wvm" />
    <p><a href="http://www.elizabethcastro.com/epub/examples/catbox.mp4"><img id="poster" width="384" height="276" src="image/poster.jpg" alt="poster" /> Click to play the video</a> and then return to read the rest of the book. </p>
    </video>


The only problem is that Adobe Digital Editions is the only EPUB ereader that properly displays the fallback message.

Adobe Digital Editions - video fallback

But it's nice. If you click the link, your default browser opens, and the video plays.

Unfortunately, if you open the EPUB file on the NOOK, or in Kobo (even the Kobo for iOS app), or even if you open it in iBooks without internet access—and thus the video cannot be displayed—you get varying things—sometimes the poster image, sometimes controls but no video—but no fallback content.

Kobo - no fallback

Fallback leads to video for Kindle books

But what about Kindle? Suppose you take that EPUB3 file, and pass it through KDP, or Kindle Previewer, or KindleGen, which all do the same thing—convert an EPUB file to KF8/mobi. And yes, they work on EPUB3 files as well as EPUB2 files. Next, open that converted mobi file in a Kindle Fire.

The fallback text, photo, and link appear, and better yet, when you click the link, Kindle Fire sends you to the browser, and plays the video. When you're done, the back arrows take you back to the book.



If that's not enough, stick it on Dropbox, and open your Dropbox app on an iPad. Once it's been copied, click the Open in another application arrow (upper right corner) and choose Kindle for iOS. Again, the fallback text, photo, and link appear, and when you click them, the video plays. It's true that you get an error message, but I'm guessing there's a way to get around that, but regardless, the video plays anyway. As if it were in a special window inside the Kindle iOS app. And when you've finished watching the video, click Done, and you go right back to the book.




So let's sum up:

1. So far, you can only play an embedded video right on a page in an ebook in iBooks and NOOK. But B&N won't let self- and indie publishers add such books to Pub It!.

2. You can play external video files right on a page in an ebook only in iBooks.

3. The fallback text doesn't appear in NOOK or Kobo.

4. The fallback text does appear in ADE and—if you convert the EPUB3 file to KF8/mobi—it also appears in Kindle Fire and Kindle for iOS (perhaps other Kindles too?), and all of these let you play the fallback video in an external browser.

5. An added caveat: I haven't uploaded a book to KDP with a link to external video. I can't guarantee that such a thing is permitted.

6. This opens up a lot of possibilities.

You can download the mobi file here. And if you liked this post, consider subscribing to my blog so I have time to write more!

Tuesday, May 14, 2013

Linking to external video (and audio) in EPUB3

I forget when I first saw the option in the iBooks settings panel, but I know it was a long time ago. Enticingly, it said Online Content, and had an On/Off switch. And underneath was a short explanation: “Allow books to access publisher's content from the Internet.”

EPUB used to be a strictly closed affair; all of its content had to live within the EPUB package itself. But in EPUB3 an exception was made to allow remote access for audio and video elements only. These two things together could only mean one thing: that remote video was now possible in an ebook, at least on the iPad.

Why is it important to be able to access remote video and audio files? For starters, keeping your audio and video out of the EPUB can make your EPUB a lot smaller and much more agile. It will download much more quickly. On the other hand, in order to see that video, your reader is still going to have to download it at some point, and they might even do it multiple times, which can be a drag on your server.

Another reason to host video or audio remotely is to give access to multiple formats of the file. EPUB3 has the capability of looking through a series of links and only using the one that works best in a given ereader. Including multiple versions of a video file in an EPUB file would result in unnecessary bloat. (Of course, this is a bit of a moot point in a world in which video and audio in EPUB mostly works in iBooks, but that is changing with Readium, and surely with newer ereaders. The fact that there is no agreed upon codec for video is also an important factor.)

Finally, if the video is hosted remotely, that means you can update it at any time. Note, however, that you must be careful to maintain the same link that exists in the EPUB file.

The code

So how do you do it? I've tried a bunch of different techniques in the last few months, but couldn't make it work. Today, while reading Matt Garrish and Markus Gylling's EPUB 3 Best Practices, I discovered that they have figured it out. It's not complicated at all, I should have figured it out too :)

The code is very straightforward and not that much different from embedding video files right in an EPUB document.

1. First, in the HTML document (mine's called outvideo.xhtml), create the video element as usual, obviously using the proper URL for the src attribute:

<video controls="controls" poster="image/poster.jpg" width="384" height="276">
<source src="http://www.elizabethcastro.com/epub/examples/catbox.mp4" />
<source src="http://www.elizabethcastro.com/epub/examples/catbox.wvm" />
</video>


Although the controls attribute isn't required, I recommend it. Otherwise, your reader won't be able to start (or stop) your video. Also note that I was playing around with WebM video, but wasn't really able to get it to work. But I haven't given up yet.

2. In the content.opf file, you have to do two things: list your video in the manifest as if you'd included it in the EPUB document, and then declare that the HTML file that contains the video points to an external resource.

a. First, we'll manifest the video.

<item id="vid" href="http://www.elizabethcastro.com/epub/examples/catbox.mp4" media-type="video/quicktime" />

b. Next, in the manifest of the HTML file that contains the video, declare that you're using an external resource:

<item id="outvideo" href="outvideo.xhtml" media-type="application/xhtml+xml" properties="remote-resources" />

And that's all there is to it. What does it look like?

If your reader has the Online Content option in iBook preferences Off, all they'll see is the poster image:

Online Content Off

If your reader has Online Content On, they'll be asked if they want to access your online content. It's good that they have a choice, since they may want to wait to download videos until they have wifi available.

Access online content?

Finally, once they click the Allow button, the video will download and become available.

External video - working

Keep in mind again, that if they no longer have connection to the Internet, the video will stop being available (even if they never close the book or leave iBooks)

External resources - no internet

It works in Readium too:

Online content in Readium

You can download the example file here.

Wednesday, May 1, 2013

Controlling spreads in EPUB3 Fixed Layout

EPUB 3's spread settings should allow you to decide when individual documents are placed next to each other on a 'synthetic' spread in a book. For example, you might want to show two consecutive pages in a spread if the device is held in landscape orientation but individually if it's held in a portrait orientation. According to the spec, that's possible. In real life, on real devices, it's not.

Let's look at the different options, since they're not very self-explanatory.

First, you can find a quick overview on this earlier article about EPUB 3 fixed layout.

EPUB 3 has three important fixed layout rendition properties, layout, spread, and orientation. The first is the one that determines if an EPUB 3 document is fixed layout or not. So, if you want a fixed-layout book, you'll add the following code to the meta section of your opf file.

<meta property="rendition:layout">pre-paginated</meta>

And if you want a flowing book, you'll leave it out to use the default value of reflowable. Can you mix fixed layout and flowing pages in a single book? Theoretically, yes, by adding the property to individual pages in the spine section, but unfortunately not in the real world. At least not yet.

The spread property determines when pages should be placed next to each other in a 'synthetic' spread. The default is for the first page to be shown by itself on the right, and each two pages after that to be shown opposite each other in a spread. With EPUB 3's spread options, you can choose to have pages always be shown independently (none), only when the device is in landscape mode (landscape), only when the device is in portrait mode (portrait), in both orientations (both), or just use the automatic settings of the reading device (auto).

So, for example, here's what it looks like in iBooks if you choose none. Each page is shown in its own spread.

rendition:spread-- none in iBooks

Unfortunately, iBooks doesn't support any of the other options, which would be very welcome. You might have a fixed-layout book that looks great in two-page spreads in landscape orientation, but that is too small in portrait view. By choosing landscape, you could force the spread in landscape, but allow for the individual pages to fill the device in portrait as well. Hopefully some day in the future.

There are additional page-spread properties that you can apply to individual pages (in the spine section) to indicate that a page should always be shown on the left side of a spread or on the right side of a spread. But I have not been able to get them to work in iBooks either.

It does work in Readium, though. Notice how the Introduction page here has been forced to display on the left, which both leaves the previous page by itself (not shown), and pulled the subsequent page next to it:

Forced left hand page

Readium doesn't seem to support any of the other spread options. No matter what I choose, it always initially shows a single page, and then if I change the options in the Settings box, it shows two.

The third property is orientation. This is how you force a book to always be displayed in one orientation or another, regardless of the way the reading device is held. The choices are landscape, portrait, and auto, and the first two options constrain the display to the given orientation.

So, if you choose auto, the book rotates with the reading device. Here's what it looks when held horizontally:

Landscape orientation iBooks

And here's what it looks like if it's rotated to a portrait orientation:

Auto orientation with device held vertically

But if you choose either landscape or portrait, then no matter how the reader holds the device, the book will always be shown in that orientation. Here's a book with the landscape orientation chosen, with the device being held vertically:

landscape forced




Tuesday, April 30, 2013

Getting rid of faux pages and binding in iBooks

Apple's iBooks has been accepting EPUB3 documents for some time, which means they can now benefit from EPUB3 features. One of those features is whether or not the binding should be displayed, which in iBooks takes the form of a faux spine:

Faux binding in iBooks

To make the faux spine disappear, you simply have to add this line to the <meta> section of your opf file (in an EPUB 3 fixed layout file):

<meta property="ibooks:binding">false</meta>

And as long as you have version 3.1 or later of iBooks, the faux binding (and the faux pages at the edges) disappear:

No faux binding in iBooks

Note, however, that if you designed your pages to fit perfectly in a landscape-oriented iOS device, the disappearance of the faux pages will make your book slightly more narrow, and you will have some empty gray space as shown above.

(Thanks to Jean-Michel Dentand for reminder to update to new version of iBooks!)

Thursday, April 11, 2013

How much did you sell on the Apple iBookstore?

Did you get a whole new slew of Apple iTunes Connect reports yesterday in your email inbox?

Inbox

I did. They're pretty useless. Each one simply reminds me to go download the full report from iTunes Connect. And I get a separate one for each currency in which I've sold books. It would be nice if I just got a single email, perhaps detailing which currencies.

So, then you head over to iTunes Connect. I always go first to Sales and Trends, only to remember, a few glacial seconds later, that I have to download the reports from Payments and Financial Reports. Click the Earnings Tab and you'll see a long list of documents to download, one for each currency and for each month. Ugh.

iTunes Earnings 1Q2013

As you can see, my earnings on the iBookstore are paltry. Good thing I sell books elsewhere! This is certainly due to a combination of my books being very niche categories (extreme EPUB and Catalonia!) but I'm certainly willing to lay some blame at Apple's door. I wish they would beef up the iBookstore and make it a place that was friendly to book buyers. They do a number of things right: being available in the largest number of countries, creating the best ereader software (iBooks), and more, but the store just isn't up to snuff. It needs search desperately. It needs reviews, and ways to share, and comment. Anyways.

When you click those download buttons in the right column, you get gzipped files (who knows why!?) for each individual period. Before you proceed, count up the ones in the list and count the ones you downloaded just to make sure you haven't missed any. (I always miss a couple.) Then, double-click each one to unzip. I wish, oh I wish, that I could choose the period myself! Maybe I want a single period, maybe I want all the data for a year.

When you open the files up in a text editor, you'll see that they are partly a tab delimited collection of sales data, but with totals at the end.

Apple report file

That first line contains the field titles, and the second line is a sales record. If there were more sales records, there would be additional lines. Each field is separated with a tab (shown here by a triangle). Those sums at the end will mess up my database, so I eliminate them.

But this data on its own is not that interesting. What I want is to be able to compile the sales data from each currency and indeed each month into a single report. This is where FileMaker comes in.

I created a database with FileMaker into which I can import Apple's files, and then generate reports that tell me how many books I've sold, and which months and countries I've sold them in. If you're a subscriber, you'll have received a free download link.

Before importing, remember to make a backup of the FileMaker database, and to have removed the total lines from the Apple reports, as described above. If your fields have accented characters, I also recommend saving them with a Mac Roman character encoding. It's a hassle, but it will ensure that those characters are properly read into FileMaker.

Then choose File > Import Records > File in FileMaker. Choose an Apple report and click Open.

Import Field Mapping

In the Import Field Mapping box, first make sure that each of the Field Titles matches the corresponding Field in the database. Click Add new records, and also Don't import first record (contains field names), since that is precisely the case with the Apple records. Then click Import.

You will see that a record is created for each title that has been sold in that currency,during that period.

Import all of the new Apple sales record files. The hardest part of this step is not importing the same file twice! (I've tried saying the name of the file out loud—paying attention to the two-letter key at the end of the code—and also looking at the just-imported file in FileMaker just before choosing the new one. Maybe this is easier for some people?)

Once you've got all the data in my FileMaker database, the rest is easy. I've got automated scripts for creating lists, as shown here.

Scripts

Here are some samples. Note that they're very simple, and they don't have titles. This is because there are only three layouts that serve the eight lists. But they work.

For example, here's what the list "By Currency, Title, Country, Period" looks like. This first page corresponds to first page of the sales in Australian Dollars, but has summaries for each period, for each country, and for each title. With currencies that are used in multiple countries, like the euro, the country section is more interesting.

AppleSales2012

And here is the report created with the Script "By Title, Period, Currency":

AppleSales2012

This page corresponds to the sales of a single title, with summaries for each period, and for each currency. Notice that only the estimated conversion to dollars is subtotaled, since it wouldn't make sense to sum different currency amounts.

And so on. I'm not a FileMaker developer, so I'm sure if you are, you could do this more beautifully. But it works, and indeed gives a much clearer and more complete view of your Apple iBookstore sales. I'm happy to share the database (without my data, obviously) to all my subscribers for free. Or you can buy it separately for $5. Use at your own risk!

Apple's new monthly and yearly reports

As so often happens, just as I was writing this blog post, I got an email from iTunes Connect letting me know that the Sales and Trends module of iTunes Connect had been improved. And that now I could download sales data for the whole year. I was very excited, but alas, it has a major flaw: if you download a yearly report, it doesn't give you the date for each sale; for example, all of the 2012 sales are are marked "December 31, 2012". So if you want a very summarized view of your sales, it might be helpful, but it's not sufficient for my purposes.

The one thing that is in those monthly reports through the Sales and Trends module that you won't find in the Payments and Financial Reports section is data about how many free books you're giving away. That is essential information if you're using free books as a hook to get people to look at your books for sale. I don't have a database set up for that yet (mostly because it would require downloading each monthly report from the Sales module), but I hope to offer that to you in the future.

How do you find those reports? It took me a while, and I even called the iTunes Connect hotline to ask for help (1-877-206-2092 in the US, and there are numbers in other countries as well). They answered almost immediately, but unfortunately said that they didn't know how to do it either! After I rummaged around a bit more, I figured it out:

Start in the Sales and Trends module. Click the Sales tab in the upper-right corner of the window.

iTunes Connect-Sales

Next, click the date and choose monthly, yearly, and then the actual month or year you're interested it.

iTunes Connect-yearly

Then click Download. And you get one of those marvelous g-zipped files, that when unzipped is a tab-delimited set of data (distinct from those downloaded from Payments and Financial Reports.

What could Apple do better?

What I want is a single place where I can choose the period (from all my sales, to monthly, yearly or whatever I want), and then export all the data at once, in a single file. And I want all the data: which book, how many copies, which country, which currency, and on which date. It's not hard. Lots of other distributors offer such tools.

More of my books