Android record in FLAC file - java

How can I make a record with a microphone in FLAC file?
I have tried this:
import javaFlacEncoder.FLAC_FileEncoder;
FLAC_FileEncoder flacEncoder = new FLAC_FileEncoder();
File outputFile = new File(dir + "/flac1.flac");
flacEncoder.encode(file, outputFile);
Error:
E/AndroidRuntime(5891): java.lang.VerifyError: javaFlacEncoder/FLAC_FileEncoder
Whether it is possible to record sound in format Wav using Java 1.6 and android 4.0.3?

From what earlier comments here were alluding to:
From this link Android appears only support AMR, PCM and GSM codecs. If you need .flac (often google's services favorite) I suggest using the lossless PCM (supports .wav) formats and using FFMPEG, SOX or some other audio converter service to then make them .flac.
(all codecs implemented in Android 3.1x (level 12) so this should apply to your version)

Related

Java: playing audio from a youtube video

I'm thinking about coding a Java applet that would take in the top 100 or so songs, find their samples (music that appears within the songs) off WhoSampled.com and then playing those samples off of YouTube.
My problem is the playing part, let's say I have the URL. What's the best way to deal with that in Java, do you think ripping the audio off and playing the audio from there would be best, or should I try to control a sentient YouTube player.
I'm leaning towards extracting the audio, and this: thread mentions a way to extract that audio, however the code:
wget http://www.youtube.com/get_video.php?video_id=...
ffmpeg -i - audio.mp3
Is not written in Java. How do I, if possible convert this to run in a Java program? Or does anyone know a good way in Java
Thank you for your suggestions.
You can use an FFMPEG Java wrapper like this one https://github.com/bramp/ffmpeg-cli-wrapper/
An example can be found in Readme. Converting MP4 to mp3 should be like this:
FFmpeg ffmpeg = new FFmpeg("/path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput("input.mp4") // Filename, or a FFmpegProbeResult
.overrideOutputFiles(true) // Override the output if it exists
.addOutput("output.mp3") // Filename for the destination
.setFormat("mp3") // Format is inferred from filename, or can be set
.setAudioCodec("aac") // using the aac codec
.setAudioSampleRate(48_000) // at 48KHz
.setAudioBitRate(32768) // at 32 kbit/s
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
// Run a one-pass encode
executor.createJob(builder).run();

RTSP stream with OpenCV [duplicate]

I'm trying to access a RTSP video stream from an IP camera using OpenCV and Java. I can access the stream using VLC player with the following format: rtsp://192.168.1.10:554/rtsp_live0 but when I try to use OpenCV the video stream seems to always be closed.
The code I'm using... (simplified)
VideoCapture capture = new VideoCapture();
capture.open("rtsp://192.168.1.10:554/rtsp_live0");
while(!capture.isOpened())
System.out.print("Not opened :( \r");
I have a Mustcam H806P and found the stream URI from this website: http://www.ispyconnect.com/man.aspx?n=ipcamera
What am I doing wrong?
I'm reporting Alexander Smorkalov answer on answers.opencv.org
OpenCV uses ffmpeg library for video I/O. Try to get video stream with console ffmpeg tool. The address must be the same.
See also here OpenCV - how to capture rtsp video stream

Can't play .m4a or .3gpp audio files in my website

Basically, I built an app in android that records my message and saves it as .m4a or .3gpp format.
When I plays the records in my app it works fine, but when I'm trying to play it on my website it doesnt work...
Android(Java)
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(OUTPUT_FILE);
recorder.prepare();
recorder.start();
Website(HTML)
<audio controls="controls" preload="none">
<source src="my_record.m4a" type="audio/mp4"/>
</audio>
P.S: When I tried to open some other m4a audio files(files that i found online), I succeded.
The audio tag is quite sensitive about this. Anything above 128mbps it will not play. A lot of encoders automatically choose the highest quality bit rate (usually around 320mbps) and the audio tag won't play them. Sample rate should be 44100hz.
the sampling rate supported by AAC audio coding standard ranges from 8 to 96 kHz, the sampling rate supported by AMRNB is 8kHz, and the sampling rate supported by AMRWB is 16kHz.
Hence change Audioencoder to AAC in your code
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
to
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
and then set filename extension to .mp3
Hope this works for you.:)

Java, recording audio - line not supported

My goal
I want to do the following in Java: record some sound made by Java itself, and then save it as a wav file.
I've searched for a lot of these kind of programs online, and I've found some good ones, but I get the same problem again and again (the current version can be found here). The problem is always something like this:
In the public class, the function start begins with
AudioFormat format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
, where getAudioFormat() returns AudioFormat(16000,8,2,true,true). If I run the file, it prints Line not supported, but why?
What I've tried:
I've searched for loads of different formats online, and tried each of them.
I've taken an existing wav file which Java can play, taken the format of that one, and used it as the format for the file I try to create.
Some more information:
System.out.println(AudioSystem.getTargetLineInfo(info));
System.out.println(AudioSystem.getAudioFileTypes());
System.out.println(AudioSystem.getMixerInfo());
System.out.println(AudioSystem.getSourceDataLine(format));
where format is the format of the existing wav file, and info is defined as in the first code snippet, prints:
[Ljavax.sound.sampled.Line$Info;#4eec7777
[Ljavax.sound.sampled.AudioFileFormat$Type;#41629346
[Ljavax.sound.sampled.Mixer$Info;#6d311334
com.sun.media.sound.DirectAudioDevice$DirectSDL#448139f0
I use Windows 7, 64 bits.
I'd like to add that if there's a better, entirely different way to achieve my goal, that's fine too.

DICOM JPEG compression not yet supported in Android

DicomDroid.jar used to open a .dcm formated image in my Android application. I got the follwing exception when try to open it.
java.io.IOException: DICOM JPEG compression not yet supported
Adding my code below
try {
// Read the imagefile into a byte array (data[])
File imagefile = new File(path);
byte[] data = new byte[(int) imagefile.length()];
FileInputStream fis = new FileInputStream(imagefile);
fis.read(data);
fis.close();
// Create a DicomReader with the given data array (data[])
DicomReader DR = new DicomReader(data);
} catch (Exception ex) {
Log.e("ERROR", ex.toString());
}
What can be done to avoid this error?
Thanks in advance.
The cause is pretty obvious. That DICOM library doesn't support that particular kind of DICOM file.
There's not much you can do about it ... unless you are prepared to enhance the library yourself.
But I think you have probably made a mistake in setting up your instrument to generate DICOM files with JPEG compression. JPEG is lossy, and best practice is to capture and store images with the best resolution feasible. If you need to downgrade resolution to reduce bandwidth, it would be better to
save a high resolution DICOM,
convert the DICOM to a low resolution JPG, and
send the JPEG.
Another option is to get the Dicom file in an uncompressed format (ej: Explicit VR Little Endian). This is the simplest dicom file format and every dicom library has support for such format.
So, when you get your Dicom file from your PACS, force this transfer syntax. This way, your dicom library will be able to deal with the image file.

Categories