Audio Files accurate seek to - java

Which Audio format should I use to get the best accurate seek to? (play the song from an offset)
I whant this to be accurate on the millisecond.
is that Possible?

I can say that the format of the audio file matters. I had this problem with long mp3 file. As the mp3 files aren't designed for such accurate seeking you can check this answer for more details
In my case the bitrate of the mp3 file was low, It was 96Kps. and the VBR data wasn't correct which caused the mp3 file to seek wrongly on android.
My intent was to make android and IOS app that seeks accurately through this file but I failed to find the correct format that is suitable for both.
For the IOS, I used MP3 Diags and applied custom transformations to remove and rebuild the VBR
For Android, I converted the file to m4a format and it worked perfectly. I used Audacity and installed the FFmpeg package to be able to export to m4a format.
This is the file sample that contains the problem I mentioned

The format doesn't matter, as long as it's compatible with Android's MediaPlayer class. It has a seekTo() method that is accrate to the millisecond.

Related

Android: How to trim WAV audio programmatically in API 30?

I need to be able trim wav audio files for an application I'm building.. but I have several problems.
I tried using FFmpeg-android, but if you target the latest SDK, and in the future, android no longer allows using "FFmpeg.execute". I also tried with the newer mobile-FFmpeg, but the developer stopped maintaining it a few months ago... I also would like to avoid heavy frameworks to also work with video, since I only need to work with audio. I can't find answers anywhere, what am I supposed to do?
You can use AudioTrack to write PCM.
I don't know how one translates input files into PCM data. But once it is in that form, you can edit it to suit your needs and then use AudioTrack to play back the result.
Maybe the MediaExtractor.readSampleData method can be used to read the audio data into an array where you can get to it and do your trimming. I've not done enough with Android to know if this is a viable plan or not.

Writing Wav Files of Unknown Length (Java)

I am trying to add a feature to some audio processing software I have written.
My software already captures sound from a microphone input, processes it in real time, and sends the result to a speaker output. (This is already a threaded application.) I've been using javax.sound.sampled.* and working with wav data (transforming it to and from numerical samples to do the processing.
I would like to add a feature to save both the raw input and the transformed output of a session with this software to wav files. But the signature for creating a new wav file (e.g., WavFile.newWavFile(...) seems to want to know in advance how many frames of data it is going to receive. Since these are live sessions of indeterminate time, I have no way of knowing this information before hand.
Am I missing something? Is there some way around this, other than a hack like saving files of data or samples, and then post-processing it?
Most audio file writers need to know the full file size before writing to an output stream. There's an open source project called Tritonus which is an implementation of the Java sound API that has an AudioOutputStream plugin you could try.

How to output elementary streams with android media recorder?

I want to output elementary video streams with media recorder in android for the purpose of streaming with live555. In essence, I want to get media recorder to output an MPEG-4 Video Elementary Stream file (an .m4e file) or an H.264 Video Elementary Stream file (an .264 file). Is it possible to do that with media recorder on android? Or is there any other way to get it work?
From the MediaRecorder APIs I see that you have to call the setOutputFormat() before calling prepare(), this limits you to select one of the available options - 3GP/MP4. Hence you can use your own parser to operate on the dump from the mediarecorder, which can give you elementary streams.
The answer is, as I understand, that it is not easy to do that with MediaRecorder while recording. You may do that without much difficulty, using ffmpeg once the video is recorded. The reason is that, MediaPlayer cannot record as elementary streams. Even if we record video only, it will be put in a container format such as 3GPP or MP4. Now, for tools like ffmpeg to work on these files, they need the 3GPP or MP4 header information must be present on the recorded file. But, MediaPlayer will write those headers to the file only after it finished recording.

Java file conversion

I have a video recording in Android and the file generated is 3gp. I want to send mp4 file to server, how can I convert 3gp file to mp4, is there any jar for this purpose?
These kind of conversions are usually CPU intensive, therefore the battery can be consumed pretty fast. Leave the conversion to the server. You may use Youtube for this

100% Java encoder for AVI animation

I am looking for a 100% Java solution for encoding software generated images into an AVI stream together with an uncompressed audio track.
At the moment I am using JMF, but its size and installation problems make it a bad solution for my purpose.
While it does not support audio, I created an MJPEG AVI Java class some years ago. You basically just tell it the resolution of your output video, along with the frame rate, then you just keep adding images to it. When you are done, you tell it to finish and it'll close out the AVI. It is based off of the Microsoft documentation on AVI, RIFF, and BITMAP file formats.
Other than not supporting audio, the only real problem is it implements the version of the AVI format limited to 2GB per file. While the class will write out a much larger file, I am uncertain that any players or video editors would be able to read it.
The way I've used this code in the past, is to generate an MJPEG AVI for processing in a video editor (adding audio, etc. in the editor). It helped me with automating some tedious slide show generation. Not sure if this code will help you, as is, but it might help if you are trying to roll your own solution. MJPEGGenerator.java is available if you are interested!
You can use JMF, see this nice example.
There is a nice blog entry here:
http://www.randelshofer.ch/blog/2008/08/writing-avi-videos-in-pure-java/
By Werner Randelshofer

Categories