Bookmark Topic Watch Topic
  • New Topic

Problem while merging two audio files  RSS feed

 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,

I have a requirement like merging two audio files of type m4a formats.For this I have followed the below code.

FileInputStream fistream1 = new FileInputStream("C:\\Temp\\2.m4a"); // first source file
FileInputStream fistream2 = new FileInputStream("C:\\Temp\\1.m4a");//second source file
SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
FileOutputStream fostream = new FileOutputStream("C:\\Temp\\final.m4a");//destination file

int temp;

while( ( temp = sistream.read() ) != -1)
{
// System.out.print( (char) temp ); // to print at DOS prompt
fostream.write(temp); // to write to file
}
fostream.close();
sistream.close();
fistream1.close();
fistream2.close();

When I execute this one only the content of first file is getting as final.m4a. In case of mp3 format which is working good.But I need m4a files merging.

Can anyone please help me on this.

Thanks in Advance,
SNEHITHAPRASAD.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
It's not generally possible to append the contents of two files of the same structured file formats by merely appending their bytes. I'm surprised that it even works for MP3. Most likely you will have to find a dedicated library for MPEG-4 to make this work. Maybe one of the libraries listed in the http://www.coderanch.com/how-to/java/OtherOpenSourceProjectsFaq page can do that.
 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi ,

No No. It's working fine for merging two audio files which are in mp3 format.But I need for this m4a format.

Thanks,
SNEHITHAPRASAD.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
What do you mean by "No No"? Just because it's working for one file format doesn't mean it's going to work for some other file format.
 
Nam Ha Minh
Ranch Hand
Posts: 515
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
I agree with Ulf Dittmer that it's weird to merge two audio files using the OP's technique.
I suggest the OP to take a look at FFMPEG library to do this object in a correct way.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Snehitha Prasad wrote:Hi ,

No No. It's working fine for merging two audio files which are in mp3 format.But I need for this m4a format.

Thanks,
SNEHITHAPRASAD.


Ulf Dittmer wrote:What do you mean by "No No"? Just because it's working for one file format doesn't mean it's going to work for some other file format.



I am not convinced that it worked for MP3 (or at least for all cases) either. There are details like sampling rates and such in the header, and if the two files have different header details, you can't just bolt the sampling data of one file to another (without any conversion). Also, the header of the second file is not sampling data.

And ... I thought that there are checksums with MP3. You may have also got lucky that the player didn't complain.

Henry

 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!