Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem while merging two audio files

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/how-to/java/OtherOpenSourceProjectsFaq page can do that.
 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic