Creating extensions for MediaCoder

From MediaCoderWiki

Jump to: navigation, search

Contents

Basics

Background

As you may or may not know, all of MediaCoder’s settings are organized in the form of a tree. A string in the form of “overall.audio.encoder” can locate a specific setting as a node in the tree. When you changing settings in the user interface, you are changing the values of the nodes in the preference tree. Different transcoding applications require different sets of settings to be changed from their defaults. Despites of bugs in MediaCoder and its dependencies, the most troublesome thing you are facing with is to make every settings correct. A common way to save this trouble is to keep settings in preset file, which MediaCoder already supports since very long ago. But I think there is other ways that can be more interesting.

After several revisions, the extension interface is almost finalized. So the documenting work is beginning. It will, of course, be expanded to provide richer features from MediaCoder.

What is an extension

Firefox is a software I’m fond of, not for its speed or its appearance, but its architecture. It has a relatively small core which accomplishes the most basic features of a browser and everything else is done by its extensions. Actually the user interface you see when you open Firefox is built on the core with XML (or XUL), JavaScript and CSS, which are all scripting or markup languages. This makes it and functions built on it easy to become cross-platform. I was inspired by this and decided to implement an extension mechanism, more like that of Firefox, but in the transcoder field. The extension mechanism is built on top of Firefox, which provided the support for HTML rendering, JavaScript scripting and XML transformation. The following is the screenshot of an extension.

extension.png

What can an MediaCoder extension do

MediaCoder extension is mainly for provide a customized user interface for a typical transcoding application. For example, the Archos extension is designed to make transcoding for Archos AV series PMP easily, while the x264 setup extension is provide users with a friendly interface to tune parameters of x264. An extension can retrieve and change all the settings of MediaCoder. Moreover, it can send commands like "start playing", "start transcoding" to MediaCoder, as well as obtain information and statistics from MediaCoder. Actually it can do even more, as its built on Firefox, JavaScript can be used to implement complex logic and behaviors. Flash can be used to form a friendly and fancy user interface. Internet connectivity can be easily accessed. In a word, every web related techniques can be used in MediaCoder extension.

What you need

Things related with extension are XML, XSLT, HTML/XHTML and JavaScript. Of course, in order to make an extension, you need to know how to setup MediaCoder for a transcoding application. This sounds complex, but the hard part is already done. What is exposed to extension developers, is a friendly and simple interface, which even does not require any programming skills. Of course, if you have some web authoring knowledge, things will be even easier.

All you need to create an extension is a text editor (notepad will do). Of course, as we will need to create and edit some XML files, a good XML editor is preferred. If you want the extension to be fancy, a WYSIWYG HTML/CSS editor may be needed.

Getting started

I will try to explain how to create an extension from a user’s aspect instead of mine. We will go through the procedures by creating a very simple extension, say an extension that can convert your audio files or (audio track of) video files to AAC files. Please note that I assume you are using MediaCoder 0.6.0 build 3306 or later versions.

You can find all the extension files in “extension” folder of “htdocs” folder in the folder where you put/install MediaCoder. One extension is corresponding to one folder. MediaCoder will automatically look for valid extensions in that folder. To create an extension, first create a sub-folder with the short name (will be used as ID, you will be able to specify the full name of it somewhere else) of your extension in “extension” folder. For example, we create a “aacmaker” sub-folder.

Extension files

Generally An extension will have several usual files. They are:

  • extension.xml - the major extension file which stores configuration and basic settings of the extension
  • an XSL file (optional) - XML stylesheet file which transforms extension.xml to viewable HTML
  • one or more HTML files (optional)
  • one or more JavaScript files (optional)

extension.xml

As you may have seen in other extension folders, they all have a file named extension.xml. This file contains all the basic information about the extension and is used by MediaCoder to identify the extension. You can use your favorite editor to create this file. Our extension.xml has following lines initiallly.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="extension.xsl"?>
<extension>
  <name>AAC Maker</name>
  <version>0.1</version>
  <window width="500" height="400"/>
</extension>

I believe this is quite self-explaining. Please note the second line. This defines the XSLT for our extension.xml, which means all visual stuff will be defined in extension.xsl.

extension.xsl

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="extension.xsl"?>
<extension>
  <name>AAC Maker</name>
  <version>0.1</version>
  <window width="500" height="400"/>
</extension>

Links

[to be continued]


Personal tools