Difference between revisions of "Java/Java Media Framework"

From Apache OpenOffice Wiki
Jump to: navigation, search
(JMF Configuration)
(Download)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
On Linux and other Unix-like system,  
+
On Linux and other Unix-like systems,  
OpenOffice.org requires to install the <b>Java Media Framework</b> in order to play sound and video.
+
OpenOffice.org requires to install the <b>Java Media Framework (JMF)</b> in order to play sound and video.
  
This page explains how to install the <b>Java Media Framework</b> and configure it for OpenOffice.org.
+
This page explains how to install the <b>Java Media Framework</b> and how to configure it for OpenOffice.org.
  
= Download =
+
== Download ==
  
 
First we will download the required software. In the following examples, we suppose you download it to the usual directory (on Linux, it's named /home/user/Download [replace 'user' with your user name], although it may vary according to your locale - in Spanish, for example, it's /home/user/Descargas).
 
First we will download the required software. In the following examples, we suppose you download it to the usual directory (on Linux, it's named /home/user/Download [replace 'user' with your user name], although it may vary according to your locale - in Spanish, for example, it's /home/user/Descargas).
  
Download the <b>JMF Performance Pack</b> for Linux from Sun's site:
+
Download the <b>JMF Performance Pack</b> for Linux from Oracle's site:
  
http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/download.html
+
http://www.oracle.com/technetwork/java/javase/download-142937.html
  
 
Do not choose the *.zip version, but the *.bin (the latest is named <b>jmf-2_1_1e-linux-i586.bin</b>).
 
Do not choose the *.zip version, but the *.bin (the latest is named <b>jmf-2_1_1e-linux-i586.bin</b>).
  
And download also the <b>JMF MP3 Plugin</b>, if you are interested in mp3 support (a quite common format nowadays). You can find it also in Sun's site:
+
And download also the <b>JMF MP3 Plugin</b>, if you are interested in mp3 support (a quite common format nowadays). You can find it also in Oracle's site:
  
http://java.sun.com/javase/technologies/desktop/media/jmf/mp3/download.html
+
http://www.oracle.com/technetwork/java/javase/download-137625.html
  
= Installation =
+
== Installation ==
  
In this section we explain how to install the JMF. Instead of following the guidelines given in Sun's site, we try show a more simple way.
+
In this section we explain how to install the JMF. Instead of following the guidelines given in Sun's site, we try to show a more simple way.
First we give the instructions to install the software for the current user only. If you are interested in installing the JMF system-wide, follow the same instructions, you will only need to add then a few extra steps.
+
First, we give the instructions to install the software for the current user only. If you are interested in installing the JMF system-wide, follow the same instructions, you will only need to add then a few extra steps.
  
== Single user ==
+
=== Single user ===
  
=== Java Media Framework ===
+
==== Java Media Framework ====
  
 
We suppose you have downloaded the required software in /home/user/Download.
 
We suppose you have downloaded the required software in /home/user/Download.
Line 65: Line 65:
  
 
The license text will be displayed on your terminal screen.
 
The license text will be displayed on your terminal screen.
Scroll down the license by pressing enter, until you reach the agreement question:
+
Scroll down the license by pressing Enter, until you reach the agreement question:
  
 
<pre>
 
<pre>
Line 72: Line 72:
  
 
Type <code>yes</code> to accept it.
 
Type <code>yes</code> to accept it.
You will be asked with two more question. Answer <code>no</code> to them:
+
You will be asked with two more questions. Answer <code>no</code> to them:
  
 
<pre>
 
<pre>
Line 127: Line 127:
 
Next step is installing the mp3 plug-in, if you want support for mp3 files.
 
Next step is installing the mp3 plug-in, if you want support for mp3 files.
  
=== JMF MP3 plug-in ===
+
==== JMF MP3 plug-in ====
  
 
Change the current directory to the place where you downloaded the plug-in zip file (latest version is named <b>javamp3-1_0.zip</b>):
 
Change the current directory to the place where you downloaded the plug-in zip file (latest version is named <b>javamp3-1_0.zip</b>):
Line 165: Line 165:
 
</source>
 
</source>
  
=== JMF Configuration ===
+
==== JMF Configuration ====
  
 
Once moved to our home directory, we are ready to launch the JMStudio, test the configuration, and add the mp3 plug-in.
 
Once moved to our home directory, we are ready to launch the JMStudio, test the configuration, and add the mp3 plug-in.
Line 181: Line 181:
 
[[Image:OOo_JavaMediaFramework_JMStudio.png|none|thumb|200px| Java Media Studio]]
 
[[Image:OOo_JavaMediaFramework_JMStudio.png|none|thumb|200px| Java Media Studio]]
  
Select the menu File - Preferences to open the JMF Registry Editor.
+
Select the menu '''File > Preferences''' to open the JMF Registry Editor.
In the "Capture device" tab, there may be at least the JavaSound audio capture. If not, press "Detect Capture Devices". Problems in this area may be related to your hardware and/or operating system, you should contact their support in case of troubles.
+
In the '''Capture device''' tab, there may be at least the JavaSound audio capture. If not, press '''Detect Capture Devices'''. Problems in this area may be related to your hardware and/or operating system, you should contact their support in case of troubles.
  
In the "Plugins" tab, select "Codec"; enter <code>com.sun.media.codec.audio.mp3.JavaDecoder</code>. Press "Add", and then "Commit".
+
In the '''Plugins''' tab, select '''Codec'''; enter <code>com.sun.media.codec.audio.mp3.JavaDecoder</code>. Press '''Add''', and then '''Commit'''.
  
  
 
[[Image:OOo_JavaMediaFramework_JMFRegistry.png|none|thumb|650px| JMF Registry Editor]]
 
[[Image:OOo_JavaMediaFramework_JMFRegistry.png|none|thumb|650px| JMF Registry Editor]]
  
If nothing went wrong, close the JMF Registry Editor, and you could play an mp3 audio file.
+
If nothing went wrong, close the JMF Registry Editor. You could now play an mp3 audio file.
 
But if a "JMF Registry Error" window pops up displaying an error message ("Could not add item"), and the terminal outputs "java.lang.ClassNotFoundException", then you must close the JMStudio and set some environment variables, then restart the JMStudio and add the mp3 codec as explained above:
 
But if a "JMF Registry Error" window pops up displaying an error message ("Could not add item"), and the terminal outputs "java.lang.ClassNotFoundException", then you must close the JMStudio and set some environment variables, then restart the JMStudio and add the mp3 codec as explained above:
  
Line 203: Line 203:
 
If you have followed these steps, you should be able to configure now OpenOffice.org to use the JMF. Notice that if you want the JMF to be accessible for other (Java) applications, like web applets, you should set some environment variables. Read the following section for instructions.
 
If you have followed these steps, you should be able to configure now OpenOffice.org to use the JMF. Notice that if you want the JMF to be accessible for other (Java) applications, like web applets, you should set some environment variables. Read the following section for instructions.
  
== Multi-user ==
+
=== Multi-user ===
  
 
If you want to install the JMF system-wide, so that it is available for every user, follow the same steps as above, and move the <code>~/JMF-2.1.1e</code> folder from your home to a system-wide location. We will choose <code>/opt</code>. Notice that setting up the JMF will require then root privileges.
 
If you want to install the JMF system-wide, so that it is available for every user, follow the same steps as above, and move the <code>~/JMF-2.1.1e</code> folder from your home to a system-wide location. We will choose <code>/opt</code>. Notice that setting up the JMF will require then root privileges.
Line 231: Line 231:
 
</source>
 
</source>
  
Change <code>JAVA_HOME</code> to the location of the JRE (or JDK). Later we'll talk about <code>fobs4jmf.jar</code>. Note that every <code>export</code> command must be in only one line; if the Wiki engine changes that when laying out this page, please write your <code>/etc/profile.d/java.sh</code> removing the extra line breaks if you copy and paste from here.
+
Change <code>JAVA_HOME</code> to the location of the JRE (or JDK). Later we will talk about <code>fobs4jmf.jar</code>. Note that every <code>export</code> command must be in only one line; if the Wiki engine changes that when laying out this page, please write your <code>/etc/profile.d/java.sh</code> removing the extra line breaks if you copy and paste from here.
  
 
After rebooting your system, every user could type <code>jmstudio</code> from the command line to launch the JMStudio, with no need to this from the installation directory (<code>/opt/JMF-2.1.1e/bin/</code>).
 
After rebooting your system, every user could type <code>jmstudio</code> from the command line to launch the JMStudio, with no need to this from the installation directory (<code>/opt/JMF-2.1.1e/bin/</code>).
  
  
= OpenOffice.org Configuration =
+
== OpenOffice.org Configuration ==
  
Before being able to use the Java Media Framework to reproduce audio and video in OpenOffice.org, you must add the JMF library folder to the class path of the Java Virtual Machine launched by OpenOffice.org. You do so with the dialog under Tools - Options:
+
Before being able to use the Java Media Framework to reproduce audio and video in OpenOffice.org, you must add the JMF library folder to the class path of the Java Virtual Machine launched by OpenOffice.org. You do so with the dialog under '''Tools > Options''':
  
[[Image:OOo_JavaMediaFramework_Tools_Options_Java.png|none|thumb|600px| Tools - Options dialog - Java settings.]]
+
[[Image:OOo_JavaMediaFramework_Tools_Options_Java.png|none|thumb|600px| Tools > Options dialog, Java settings.]]
  
  
Line 253: Line 253:
  
  
After restart, you should be able to play audio and sound supported by JMF. You can try playing one of the sound from the gallery:
+
After restart, you should be able to play audio and sound supported by JMF. You can try playing one of the sounds from the gallery:
  
  
 
[[Image:OOo_JavaMediaFramework_GalleryMediaPlayer.png|none|thumb|700px| Media Player]]
 
[[Image:OOo_JavaMediaFramework_GalleryMediaPlayer.png|none|thumb|700px| Media Player]]
  
= Troubleshooting =
+
== Troubleshooting ==
  
 
If you get an error similar to the following:
 
If you get an error similar to the following:
Line 324: Line 324:
 
Press ESC to stop inserting, and type <code>:wq</code> to write the changes and quit.
 
Press ESC to stop inserting, and type <code>:wq</code> to write the changes and quit.
  
= Extending JMF =
+
== Extending JMF ==
  
 
Sun's Java Media Framework comes with support for few formats. You can extend it by installing Fobs4JMF, which is a JMF wrapper for the popular ffmpeg, it can play the most common formats and codecs (ogg, mp3, m4a, divx, xvid, h264, mov, avi, etc):
 
Sun's Java Media Framework comes with support for few formats. You can extend it by installing Fobs4JMF, which is a JMF wrapper for the popular ffmpeg, it can play the most common formats and codecs (ogg, mp3, m4a, divx, xvid, h264, mov, avi, etc):

Revision as of 09:42, 3 August 2010

On Linux and other Unix-like systems, OpenOffice.org requires to install the Java Media Framework (JMF) in order to play sound and video.

This page explains how to install the Java Media Framework and how to configure it for OpenOffice.org.

Download

First we will download the required software. In the following examples, we suppose you download it to the usual directory (on Linux, it's named /home/user/Download [replace 'user' with your user name], although it may vary according to your locale - in Spanish, for example, it's /home/user/Descargas).

Download the JMF Performance Pack for Linux from Oracle's site:

http://www.oracle.com/technetwork/java/javase/download-142937.html

Do not choose the *.zip version, but the *.bin (the latest is named jmf-2_1_1e-linux-i586.bin).

And download also the JMF MP3 Plugin, if you are interested in mp3 support (a quite common format nowadays). You can find it also in Oracle's site:

http://www.oracle.com/technetwork/java/javase/download-137625.html

Installation

In this section we explain how to install the JMF. Instead of following the guidelines given in Sun's site, we try to show a more simple way. First, we give the instructions to install the software for the current user only. If you are interested in installing the JMF system-wide, follow the same instructions, you will only need to add then a few extra steps.

Single user

Java Media Framework

We suppose you have downloaded the required software in /home/user/Download. Open a terminal (in the Gnome desktop it is called gnome-terminal, in KDE it is the Konsole), and change the current directory to the place where you downloaded the software:

[user@localhost ~]$ cd  Download

Create a new directory to unpack the software. We name it JMF:

[user@localhost Download]$ mkdir JMF

Copy the JMF Performance Pack binary in that directory (it is better to work with a copy of the downloaded file, because there may be problems during the installation, as several users have reported).

[user@localhost Download]$ cp jmf-2_1_1e-linux-i586.bin JMF/jmf-2_1_1e-linux-i586.bin

Change the working directory to JMF:

[user@localhost Download]$ cd JMF

Now change the file mode to make it executable:

[user@localhost JMF]$ chmod +x jmf-2_1_1e-linux-i586.bin

And execute the "installer" (you don't need root privileges because it will only unpack the files in the current directory, instead of installing them):

[user@localhost JMF]$ ./jmf-2_1_1e-linux-i586.bin

The license text will be displayed on your terminal screen. Scroll down the license by pressing Enter, until you reach the agreement question:

Do you agree to the above license terms? [yes or no]

Type yes to accept it. You will be asked with two more questions. Answer no to them:

Permit recording from an applet? (see readme.html) [yes or no]
no

Permit writing local files from an applet? (recommend no, see readme.html) [yes or no]
no

After answering to these questions, the unpacking process will start.

At this point, you may get an error similar to the following:

Unpacking...
tail: cannot open `+309' for reading: No such file or directory
Extracting...
./install.sfx.25050: line 1: ==: No such file or directory
./install.sfx.25050: line 3: syntax error near unexpected token `)'

If so, please refer to the "Troubleshooting" section below.

The JMF will try to find the devices in your system. Don't panic if you get some messages telling that it couldn't open some devices:

java.lang.Error: Can't open video card 1
java.lang.Error: Can't open video card 2
java.lang.Error: Can't open video card 3
java.lang.Error: Can't open video card 4
java.lang.Error: Can't open video card 5
java.lang.Error: Can't open video card 6
...

The important thing is that it finds your sound card (and video card, in case you have one). You can check this later from within the JMStudio, installed with the JMF.

If everything went good, the JMF should be unpacked in /home/user/Download/JMF/JMF-2.1.1e/.

Now we can move the JMF folder to a permanent location in our home directory:

[user@localhost Download]$ mv JMF/JMF-2.1.1e ~/

Finally, we can remove the temporal folder:

[user@localhost Download]$ rm -rf JMF

Next step is installing the mp3 plug-in, if you want support for mp3 files.

JMF MP3 plug-in

Change the current directory to the place where you downloaded the plug-in zip file (latest version is named javamp3-1_0.zip):

[user@localhost ~]$ cd  Download

Create a new directory to unpack it. We name it JAVAMP3:

[user@localhost Download]$ mkdir JAVAMP3

Extract the zip file inside this new folder:

[user@localhost Download]$ unzip javamp3-1_0.zip -d JAVAMP3/
Archive:  javamp3-1_0.zip
  inflating: JAVAMP3/copyright.txt
  inflating: JAVAMP3/license.txt
   creating: JAVAMP3/lib/
   creating: JAVAMP3/lib/ext/
  inflating: JAVAMP3/lib/ext/mp3plugin.jar

Then copy the plug-in Java Archive (mp3plugin.jar) inside the JMF folder, together with the other JARs (/home/user/JMF-2.1.1e/lib/):

[user@localhost Download]$ cp JAVAMP3/lib/ext/mp3plugin.jar ~/JMF-2.1.1e/lib/

Finally, we can remove the temporal folder:

[user@localhost Download]$ rm -rf JAVAMP3

JMF Configuration

Once moved to our home directory, we are ready to launch the JMStudio, test the configuration, and add the mp3 plug-in.

To launch the JMStudio, type the following:

[user@localhost Download]$ cd ~/JMF-2.1.1e/bin/
[user@localhost ~]$ ./jmstudio


You will see a window like the following:

Java Media Studio

Select the menu File > Preferences to open the JMF Registry Editor. In the Capture device tab, there may be at least the JavaSound audio capture. If not, press Detect Capture Devices. Problems in this area may be related to your hardware and/or operating system, you should contact their support in case of troubles.

In the Plugins tab, select Codec; enter com.sun.media.codec.audio.mp3.JavaDecoder. Press Add, and then Commit.


JMF Registry Editor

If nothing went wrong, close the JMF Registry Editor. You could now play an mp3 audio file. But if a "JMF Registry Error" window pops up displaying an error message ("Could not add item"), and the terminal outputs "java.lang.ClassNotFoundException", then you must close the JMStudio and set some environment variables, then restart the JMStudio and add the mp3 codec as explained above:

user@localhost:~/JMF-2.1.1e/bin$ ./jmstudio 
java.lang.ClassNotFoundException
user@localhost:~/JMF-2.1.1e/bin$ export JMFHOME=/home/user/JMF-2.1.1e
user@localhost:~/JMF-2.1.1e/bin$ export CLASSPATH=$JMFHOME/lib/jmf.jar:$JMFHOME/lib/mp3plugin.jar:$CLASSPATH
user@localhost:~/JMF-2.1.1e/bin$ export LD_LIBRARY_PATH=$JMFHOME/lib:$LD_LIBRARY_PATH
user@localhost:~/JMF-2.1.1e/bin$ ./jmstudio

If you have followed these steps, you should be able to configure now OpenOffice.org to use the JMF. Notice that if you want the JMF to be accessible for other (Java) applications, like web applets, you should set some environment variables. Read the following section for instructions.

Multi-user

If you want to install the JMF system-wide, so that it is available for every user, follow the same steps as above, and move the ~/JMF-2.1.1e folder from your home to a system-wide location. We will choose /opt. Notice that setting up the JMF will require then root privileges.

Open a terminal, type su and enter the system administrator password.

Then move the JMF to its new location (don't forget to replace 'user' with your user directory name):

[root@localhost ~]$ mv  /home/user/JMF-2.1.1e /opt/

Create a symbolic link to reference in the environment variables (this way it's easier to update):

[root@localhost ~]$ ln -s /opt/JMF-2.1.1e /opt/JMF

Next we have to set global environment variables. We do so by editing (or creating, in case it doesn't exist) a file named java.sh in /etc/profile.d/java.sh, with the following content:

export JAVA_HOME=/opt/jdk
export JMFHOME=/opt/JMF
export CLASSPATH=$JMFHOME/lib/jmf.jar:$JMFHOME/lib/mp3plugin.jar:$JMFHOME/lib/fobs4jmf.jar:$CLASSPATH
export LD_LIBRARY_PATH=$JMFHOME/lib:$LD_LIBRARY_PATH
export PATH=$JAVA_HOME/bin:$JMFHOME/bin:$PATH

Change JAVA_HOME to the location of the JRE (or JDK). Later we will talk about fobs4jmf.jar. Note that every export command must be in only one line; if the Wiki engine changes that when laying out this page, please write your /etc/profile.d/java.sh removing the extra line breaks if you copy and paste from here.

After rebooting your system, every user could type jmstudio from the command line to launch the JMStudio, with no need to this from the installation directory (/opt/JMF-2.1.1e/bin/).


OpenOffice.org Configuration

Before being able to use the Java Media Framework to reproduce audio and video in OpenOffice.org, you must add the JMF library folder to the class path of the Java Virtual Machine launched by OpenOffice.org. You do so with the dialog under Tools > Options:

Tools > Options dialog, Java settings.


Press the "Class Path" button, and add the JMF library folder (if you have choosen the system-wide installation, it is /opt/JMF/lib; if you have installed the JMF just in your home directory, it is /home/user/JMF-2.1.1e/lib).

Java class path settings.


You will need to restart OpenOffice.org for this changes to take effect.

OOo JavaMediaFramework Tools Options Java Restart.png


After restart, you should be able to play audio and sound supported by JMF. You can try playing one of the sounds from the gallery:


Media Player

Troubleshooting

If you get an error similar to the following:

Unpacking...
tail: cannot open `+309' for reading: No such file or directory
Extracting...
./install.sfx.25050: line 1: ==: No such file or directory
./install.sfx.25050: line 3: syntax error near unexpected token `)'

you will have to edit the installer and correct a line.

There are different ways of doing this, we will use the vim editor.

First we have to clear things up, because this error corrupts the installer file. You can test this by checking its size:

[user@localhost ~]$ cd Download/JMF/
[user@localhost JMF]$ ls -l .
total 8
-rwxrw-r-- 1 user user 4022 ene 21 09:44 install.sfx.25050
-rwxr-xr-x 1 user user    0 ene 21 09:44 jmf-2_1_1e-linux-i586.bin

So remove everything and copy back the file downloaded:

[user@localhost JMF]$ rm -f *
[user@localhost JMF]$ cp ../jmf-2_1_1e-linux-i586.bin .
[user@localhost JMF]$ chmod +x jmf-2_1_1e-linux-i586.bin

Open the file with vim in binary mode:

[user@localhost JMF]$ vim -b jmf-2_1_1e-linux-i586.bin


OOo JavaMediaFramework issue vim 1.png


In the vim editor, type /tail and press ENTER to look for the line to be fixed:


OOo JavaMediaFramework issue vim 2.png


This will find the problematic line.


OOo JavaMediaFramework issue vim 3.png


Then press the key l to move to the left on that line, until the sign +.

Press i to insert text, and insert -n , with a space


OOo JavaMediaFramework issue vim 4.png


Press ESC to stop inserting, and type :wq to write the changes and quit.

Extending JMF

Sun's Java Media Framework comes with support for few formats. You can extend it by installing Fobs4JMF, which is a JMF wrapper for the popular ffmpeg, it can play the most common formats and codecs (ogg, mp3, m4a, divx, xvid, h264, mov, avi, etc):

JMF playing xvid

Please refer to http://fobs.sourceforge.net for more details.

Unfortunately there are no recent binaries for Linux (see http://sourceforge.net/project/showfiles.php?group_id=105646&package_id=117443), so you will have to compile it from the sources.

Once compiled, you don't need to install anything, you just have to copy fobs4jmf.jar and libfobs4jmf.so in /opt/JMF/lib/.

TODO: not very complicated explanation of how to compile it (at least in Ubuntu) on people's demand... See Discussion tab, where this request has been requested, of those able to do, and thanks!

Personal tools