dcsimg
how do i add image and audio files in my program, and then save it as a movie file?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Meryl_Louise
Posted On:   Sunday, March 28, 2004 01:06 AM

Hello there! I'm having a problem regarding the program im working on. I'm using j2sdk1.4.0 and jmf2.1.1e. My program imports jpeg files and audio files and converts it to a .mov format. A text is also set as a title. It should be doing somewhat like what a MovieMaker of XP does, but only a lot simpler (functionality/interface-wise). I was able to convert the jpeg files to a .mov format but im having a problem when i play the file. I'm using quicktime 5 player. An error saying "You may experience problems playing a video track because the compressor found that the image data may be corrupted." always shows up. But when i continue, the player plays the file but sometimes it doesnt show all the images. What could be wrong? Here's the code im working on --    More>>

Hello there! I'm having a problem regarding the program im working on. I'm using j2sdk1.4.0 and jmf2.1.1e. My program imports jpeg files and audio files and converts it to a .mov format. A text is also set as a title. It should be doing somewhat like what a MovieMaker of XP does, but only a lot simpler (functionality/interface-wise). I was able to convert the jpeg files to a .mov format but im having a problem when i play the file. I'm using quicktime 5 player. An error saying "You may experience problems playing a video track because the compressor found that the image data may be corrupted." always shows up. But when i continue, the player plays the file but sometimes it doesnt show all the images. What could be wrong? Here's the code im working on --




			
public boolean doIt(int width, int height, int frameRate, Vector imgFiles, MediaLocator outML) {
ImageDataSource ids = new ImageDataSource(width, height, frameRate, imgFiles);
Processor p;
try{
p = Manager.createProcessor(ids);
}catch (Exception e){
return false;
}
p.addControllerListener(this);
p.configure();
if (!waitForState(p, p.Configured)){
return false;
}
p.setContentDescriptor(new ContentDescriptor(FileTypeDescriptor.QUICKTIME));
TrackControl tcs[] = p.getTrackControls();
Format f[] = tcs[0].getSupportedFormats();
if (f == null || f.length <= 0){
return false;
}
tcs[0].setFormat(f[0]);
p.realize();
DataSink dsink;
if ((dsink = createDataSink(p, outML)) == null){
System.err.println("Failed to create a DataSink for: " + outML);
return false;
}
dsink.addDataSinkListener(this);
fileDone = false;
try{
p.start();
dsink.start();
}catch (IOException e){
System.err.println("IO error during processing");
return false;
}
waitForFileDone();
try{
dsink.close();
}catch(Exception e){}
p.removeControllerListener(this);
return true;
}
}




Iv used a media locator to get the jpeg files. And iv also used data sink for the processor and the medialocator. The imagedatasource should read the jpeg files and turn it into a stream fo jmf buffers. Here's the code--



			
class ImageDataSource extends PullBufferDataSource {
ImageSourceStream streams[];
ImageDataSource(int width, int height, int frameRate, Vector imageFilenames){
streams = new ImageSourceStream[1];
streams[0] = new ImageSourceStream(width, height, frameRate, imageFilenames);
}
public void setLocator(MediaLocator source){
}
public MediaLocator getLocator(){
return null;
}
public String getContentType(){
return ContentDescriptor.RAW;
}
public void connect(){
}
public void disconnect(){
}
public void start(){
}
public void stop(){
}
public PullBufferStream[] getStreams() {
return streams;
}
public Time getDuration(){
return DURATION_UNKNOWN;
}
public Object[] getControls(){
return new Object[0];
}
public Object getControl(String type){
return null;
}
}//end of ImageDataSource class

class ImageSourceStream implements PullBufferStream{
Vector imageFilenames;
int width, height;
VideoFormat format;
int nextImage = 0;
boolean ended = false;

public ImageSourceStream(int width, int height, int frameRate, Vector imageFilenames){
this.width = width;
this.height = height;
this.imageFilenames = imageFilenames;

format = new VideoFormat(VideoFormat.JPEG, new Dimension(width, height), Format.NOT_SPECIFIED, Format.byteArray, (float)frameRate);
}

public boolean willReadBlock() {
return false;
}
public void read(Buffer buf) throws IOException{
try{
if (nextImage >= imageFilenames.size()) {
int m;
System.err.println("Done reading all images.");
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
ended = true;
return;
}
else{
String imageFile = (String)imageFilenames.elementAt(nextImage);
nextImage++;
System.err.println(" - reading image file: " + imageFile);

RandomAccessFile randomFile = new RandomAccessFile(imageFile, "r");
byte data[] = null;
if (buf.getData() instanceof byte[])
data = (byte[])buf.getData();
if (data == null || data.length < randomFile.length()){
data = new byte[(int)randomFile.length()];
buf.setData(data);
}
System.err.println(" read " + randomFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int)randomFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
randomFile.close();

}//end of else condition
}//end of try
catch(IOException ioe){
System.err.println("ERROR IN READING BUFFER");
}
}//end of read

public Format getFormat(){
return format;
}
public ContentDescriptor getContentDescriptor(){
return new ContentDescriptor(ContentDescriptor.RAW);
}
public long getContentLength(){
return 0;
}
public boolean endOfStream(){
return ended;
}
public Object[] getControls(){
return new Object[0];
}
public Object getControl(String type){
return null;
}
}//end of ImageSourceStream class




Plus, the text that should be included in the movie will be entered by the user through a textfield. How can I incorporate the text in the .mov format? Should i set the text as a jpeg format before i can include it in the vector of jpeg files im using to get the images? Another thing is that i'm also having a problem on how i will be able to incorporate the audio files in the movie. Does java has a package for adding or setting or whatever u may call it, audiofiles in the movie?




As u can see, i really, really need help. So please, please, please, please help me by posting ur ideas/opinions regarding my program. I'll need all the help i can get. Thank you soooo much.



-Meryl

   <<Less
About | Sitemap | Contact