merge some ogg audio files using java programming language - java

I have some .ogg sound files that must be merged together.But the problem is in that the java only support .wav extension (as I used AudioSystem and AudioInputStream).
I've searched among different pages for converting and I've not found a better way than.
Do you know a better way other than using Command line tool?

I think you may have to inspect and tinker with the source code. This can be obtained from various libraries that have JOrbis and other files needed for ogg playback and encoding (there are several on github).
For a project where I needed to load decompressed ogg files (that were originally wav) into memory, I used source code from the example OggPlayer (usually included in the package) and intercepted the bytes before they were written to a SourceDataLine. You can maybe also find a hook in example code that compresses wav to ogg and then link the two parts.

Related

PDF Compression - HTML to PDF (wkhtmltopdf)

Background
I'm working on a Scala/Java project where we convert individual HTML files to PDF files. We then merge the individual files into one larger complete PDF file.
For the converting we are using sPDF which is built on top of wkhtmltopdf. For the merging we use PDFMergerUtility.
The reasons for making individual files is a bit complicated - but it should be noted we can't make one big PDF off the bat and have to make the individual files first.
The issue
Initially we had no problems with this approach - however as the system has grown - so have the final PDF files. We went from files that were 2MB-3MB to files that are 20MB. I would like to know if there is any obvious compression methods or techniques we could use?
There is a lot of shared content across the individual files but since we're just merging them as isolated/independent files (as in, none of the content that is the same across the individual files is being reused to save space) it doesn't make a difference in bringing down the file size.
If I manually ZIP the final PDF file it greatly reduces the file size -as obviously there is a lot of repeated content.
So one option might just be to zip the PDF after I've finished the merging, but I would prefer to compress it during the merger process or conversion process.
Any ideas?
You could try Sejda to merge, it's Java, open source and based on a fork of PDFBox. It can generate PDF files using object streams (PDFBox currently doesn't support that) and, in case it doesn't reduce the size that much, you can try to pipe its 'compress' task which goes through the document removing unused resources and compressing images.
It's battle tested as engine behind PDFsam so, if you want to give it a quick test and see what's the outcome, just download PDFsam, use the merge module with your files (and compression flag on) and the result is what Sejda will generate.

Is it possible (and how) to determine the endianness of an AIFF audio file?

I work on an audio Importer in JAVA (used in a drum sequencer) and I have the following problem with importing AIFF files:
I have 2 AIFF files of the same type (24bit, 44100kHz, mono), one is created on a Mac, the other is created with wavelab on a windows computer. Both files are uncompressed PCM, both are FORM == AIFF.
The AIFF from the Mac is BigEndian (as it should be),
the AIFF from Wavelab (windows) is LittleEndian.
Both files can be played back properly in Wavelab (Windows) as well as in Quicktime (Windows).
How can these tools detect the endianness of these files? In any way it must be possible, otherwise at least one of the files would sound just like noise (that's what happen in my application).
Is there some hidden information within the file header or any other way to determine the endianness of the AIFF file?
Any suggestions?
Thanks a lot
A quick googling says, AIFF files are big endian.
However according to Wikipedia there is another format called AIFF-C that compresses data. Apple uses little endian these days and created a fake compression method named sowt that essentially means "no compression but little endian". You might have to check for that.
Apart from that, plain AIFF provides no way to check for endianness. A standard AIFF that is encoded in little endian seems to violate the specification.

parse ogg file in java without decoding

I have a .spx file (an Ogg file with Speex-encoded audio). I would like to use Java to pull the Speex-encoded bytes out of the Ogg container.
The problem is, it seems all of the Java libraries I can find (JSpeex, JOrbis) are written with the assumption that I would also like to decode the audio into raw pcm, which I do not.
Is there a generic Ogg format reader library out there for Java? On the other hand, is it possible to use parts of JSpeex or JOrbis to do what I want?
I could not find an Ogg library in Java after some shallow searching.
But if you are willing to implement Ogg parsing from scratch, the words straight from the horse's mouth are readily available:
Ogg bitstream overview
Ogg logical bitstream and framing spec
(Top page: https://www.xiph.org/vorbis/doc/)
I have not worked with Ogg file with Speex-encoded audio but once I have worked on a use case where I wanted to extract opus packets from ogg opus file, without being decoded to pcm audio. You can find that solution in this answer
https://stackoverflow.com/a/65320789/10110652
This piece of code also works for ogg file with vorbis encoding, so may be this might help with speex encoding as well. Do let me know if this works for you.
Happy Coding!!!❤

Java: How to read available audio tracks in a video file?

Some video files contain multiple audio tracks. Multiple languages for example. Is there a library which gets information about these audio tracks? Names of the audio tracks would be sufficient.
It should support common formats (mkv, avi,...)
I believe the best monolithic media file library available is that for VLC player. I seem to remember there was a Java wrapper, but it's probably not maintained (like all Java wrappers more than a few weeks old heheh).
I have found a solution to my problem. From Java I call the following command:
ffmpeg -i myvideo.mkv
Then I read the commands output and filter the lines which start with Stream #.
This works on all my files with multiple audio tracks.

Java library for extracting audio information from MP3 files

Is there any freely available library (other than java media framework) that I can use to extract the bit rate (eg. 128 kbps, VBR) and the audio quality (eg 44.1KHz, Stereo) from a MP3 file?
I would like a standalone library that I can incorporate into my application jar, to be deployed on older Macs too that have only Java 1.5 available and I can't get them upgraded or add any big Java library to.
Just to clarify: I will not play, transcode or do anything of the sort with the audio stream itself, I am interested in the metadata only.
I confess I do not know much about MP3 files, but you can see from the format specification that all the informations needed are in the 32 bits long header of the file.
You could open the MP3 with a FileInputStream, read the first 4 bytes of the file and, using some simple binary masks, retrieve the informations you need. IMHO using a specialized library for that is a bit of an overkill.
Take a look at JAudioTagger, plain simple and easy to use, the data you are looking for is into MP3AudioHeader class, with methods like getBitRate()
You can use the LAMEOnJ library:
http://openinnowhere.sourceforge.net/lameonj/
This java library is light but you must have the LAMELib installed on target computer.
I'm not a java programmer, but i'm pretty sure you could read the mp3 file into a byte array then see http://www.mp3-tech.org/programmer/frame_header.html for frame info.
This format specification shows you what's contained the MPEG (mp3) header. You can write code to retrieve this header.

Categories