Adding Audio To Video

Hi, I realise that this is a relatively common problem and dutifully have read the relevant threads on the forum.

Quite simply, I wish to add audio (wav file) to a video (MPEG format). My original plan had been just to have two players and add one as a Controller of the other and play them that way. Unfortunately due to the diffferences in duration (actual) what's happened is that one file was 'stretched' to be the same length as the other. As the video/audio is for lip-reading type research you can understand why this is unacceptable.

My next option, upon further reading of the docs, was to try using the CreateMergingDataSource() method. I created two DataSources and loaded my files into them. Unfortunately when trying to merge them I get an exception telling me that the sources aren't compatible.

What other options do I have? The compatibility referred to in the docs talks about Push and Pull sources which I'm sure they both are the same.

Thanks for your time. I can provide source if necessary.

[1047 byte] By [DerekHartleya] at [2007-11-26 20:55:24]
# 1
Well i can think of only the data source type problem causing a IncompatibleSourceException.Anyways post your code here.
qUesT_foR_knOwLeDgea at 2007-7-10 2:22:57 > top of Java-index,Security,Cryptography...
# 2
I think you are receiving a NoPlayerException!
qUesT_foR_knOwLeDgea at 2007-7-10 2:22:57 > top of Java-index,Security,Cryptography...
# 3

Yes, you were right. The Exception IS a NoPlayerException. Basically I end up with a DataSource with a content descriptor of application.mixed which it can't find a player for. Which I guess is understandable. I'm not sure it's necessary, but my code is below

import javax.swing.*;

import java.net.*;

import javax.media.*;

import java.awt.Component;

import java.beans.Beans;

import javax.media.bean.playerbean.MediaPlayer;

import javax.media.protocol.DataSource;

public class MediaPanel extends JPanel{

DataSource m_dataSourceVideo;

DataSource m_dataSourceWav;

DataSource m_dataSourceFinal;

DataSource[] m_adataSourceArray;

MediaPlayer m_playerMaster;

Player m_playerMedia;

Component m_componentVideo;

boolean m_bIsVideo;

boolean m_bIsWav;

MediaPanel() {

try {

ClassLoader cl = this.getClass().getClassLoader();

m_playerMaster = (MediaPlayer)Beans.instantiate(cl,"javax.media.bean.playerbean.MediaPlayer");

}

catch(Exception e) {

System.out.println("Can't create MediaPlayer");

System.exit(0);

}

}

public void LoadWav(URL urlWav) {

m_bIsWav = false;

try {

m_dataSourceWav = Manager.createDataSource(urlWav);

}

catch(Exception e) {

m_bIsWav = false;

System.out.println("Can't load Wav");

}

m_bIsWav = true;

}

public void LoadVideo(URL urlVideo) {

m_bIsVideo = false;

try {

m_dataSourceVideo = Manager.createDataSource(urlVideo);

}

catch(Exception e) {

m_bIsVideo = false;

System.out.println("Can't create Video");

}

m_bIsVideo = true;

}

public void PlayMedia() {

m_playerMaster.setPlayer(m_playerMedia);

if(m_bIsVideo) {

if((m_componentVideo = m_playerMedia.getVisualComponent()) != null) {

add(m_componentVideo);

}

repaint();

m_playerMedia.start();

}

}

public void SetMedia() {

if(m_bIsWav && m_bIsVideo) {

// We have both, need to merge them

System.out.println("Calling Merge");

MergeMedia();

try {

m_playerMedia = Manager.createPlayer(m_dataSourceFinal);

return;

}

catch(Exception e) {

System.out.println(e.getMessage());

System.out.println("Can't create player from DataSource");

}

}

else {

if(m_bIsWav) {

m_dataSourceFinal = m_dataSourceWav;

return;

}

if(m_bIsVideo) {

m_dataSourceFinal = m_dataSourceVideo;

return;

}

}

}

public void MergeMedia() {

DataSource[] m_adataSourceArray = {m_dataSourceWav, m_dataSourceVideo};

try {

m_dataSourceFinal = Manager.createMergingDataSource(m_adataSourceArray);

}

catch(Exception e) {

System.out.println(e.getMessage());

System.out.println("Merging failed");

}

}

}

DerekHartleya at 2007-7-10 2:22:57 > top of Java-index,Security,Cryptography...
# 4

> Yes, you were right. The Exception IS a

> NoPlayerException. Basically I end up with a

> DataSource with a content descriptor of

> application.mixed which it can't find a player for.

> Which I guess is understandable. I'm not sure it's

> necessary, but my code is below

Yes it won't be necessary. If there is no plugin which can handle streams which represent two different formats then there is no point as there won't be a player that can satisfy this need. Rather you can try obtaining individual track from one data sources say the track that represents audio and add it as a track to the video datasourcea after disabling the video streams audio track. I haven't tried anything of that sort. Anyways you can give it a thought.

qUesT_foR_knOwLeDgea at 2007-7-10 2:22:57 > top of Java-index,Security,Cryptography...