Skip to main content
Known Participant
December 19, 2022
Answered

Inserting a Youtube video into an EPub

  • December 19, 2022
  • 2 replies
  • 4027 views

I have created an enhanced epub with five videos embedded in the iframe, and the book works fine for a few readers. However, when I run epubcheck, it gives me an error as epub standards are set not to accept iframe. Many suggest using 

<video></video>

However, since the Youtube video is not addressed as .MP4, the system inserts its controls, and the video does not display. 

I have tried and added these lines to the content.opf for each video;

<item id="content_001"  href="content_001.xhtml" media-type="application/xhtml+xml" properties="remote-resources"/>
<item id="content_iframe"  href="https://www.youtube.com/embed/qlMuzbjMASo" media-type="text/html"/>

However, I still get the following error:

ERROR (RSC-006) at "ABC.epub/OEBPS/ABC.xhtml" (line 14, col 215):
Remote resource reference is not allowed; resources must be placed in the OCF.

Does anyone have any ideas on how to get rid of this error?

This topic has been closed for replies.
Correct answer rayek.elfin

Thank you. It seems like you have the correct answer. As soon as I moved the files as MP4 to my server, at least the errors disappeared. However, there is still something missing, as the videos do not play.


@James Gifford—NitroPressis correct in stating that the <iframe> tag should be avoided.

 

That said, YouTube videos can be embedded simply by copying the shared iframe code, although it is not part of the official epub standard, and there is no garantuee it will play in any given epub reader.

 

The <video> tag is an option. The following code will work in Thorium Reader:

 

<video id="video01" width="1280" height="720" preload="auto" controls="true">
<source src="https://mydomain.com/video/myvideo.mp4" />
</video>

 

It loads locally in Thorium from the supplied web address.

However, it does not load in Calibre's ePub viewer, even though the video player and its controls are displayed.

 

Calibre's ebook viewer does not support the licensed MP4 format, which is why it cannot play those files.

Encoding the video to webm/VP8 resolves this, and it plays in both readers. To do this, use a tool like Handbrake to transcode an existing mp4 to webm. The code changes to:

 

<video id="video01" width="1280" height="720" preload="auto" controls="true">
<source src="https://mydomain.com/video/myvideo.webm" />
</video>

 

See for codec support in epub: https://idpf.org/epub/30/spec/epub30-publications.html#note-video-codecs

 

webm/VP8 is considered the safest choice. But there is no garantuee that any given epub reader will display your videos, of course:

  • some readers refuse to load external online content
  • some readers do not support videos at all
  • some readers may only support one of the two codecs (either mp4 or webm)

 

Another potential issue with this approach: not everyone reading your book may be online. From my own experience, I am almost never online when reading an epub while traveling. It means that video content cannot be loaded and displayed. My wife is the same: almost always offline while reading epubs.

 

Then there is the problem of link rot. If you rely on external links for your book content, it is a given that content will disappear at some point in a few years time.

 

An alternative solution is to provide the reader with a link in your epub to a webpage that plays the video. Advantages are:

  • you leave it up to the reader to decide whether to view the video at a time convenient to them when they are online
  • When the reader taps/clicks the link in the epub, their preferred browser opens the link. All browsers, including mobile ones, will play your video - it will just work because browser have great support for video. (Unlike epub readers which is still the Wild West in a sense).
  • easier to secure your content.

 

As for your videos not playing: check that you have lowercase letters, no spaces, and no special characters in your file names. Ensure the videos are encoded to webm/VP8.

 

Which ebook readers are you targeting? Which have you tested?

2 replies

Derek Cross
Community Expert
Community Expert
December 19, 2022

Depending on your budget, it might be worth having a look at in5, an InDesign plugin (at extra cost):
https://ajarproductions.com

James Gifford—NitroPress
Legend
December 19, 2022

Honestly, I'd say the right approach for the OP is a simple web page. While it doesn't "package" as a standalone document, an HTML/CSS page can be a highly sophisticated presentation with almost unlimited design and embedded content, which will present on almost any modern browser on any platform or device.

 

"Books" aren't always the right medium. 🙂

 

foaad61Author
Known Participant
December 19, 2022

Youtube isn't a video source - it's a full service video player, designed to allow embedding only in specific ways that maintain the profits. You may need to put your videos on a media server.


This is a great idea. However, the issue is the iframe in ePub, not where to host the videos.

James Gifford—NitroPress
Legend
December 19, 2022

I am not sure EPUB, at the standards level, is built to manage embedded video.

 

While you can often hack in HTML features, as you've done with iframe, it won't pass validation and will work only erratically in viewers.

 

While EPUB is 'packaged web page,' it doesn't quite work like, well, a web page. Remote resources just aren't part of the package. (That is, it has to be a package.)