bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.41k stars 1.57k forks source link

Audio Recording JavaCV #1888

Open muguryildirim opened 1 year ago

muguryildirim commented 1 year ago

Hi everyone, I'm trying to record&play only audio but i keep getting the same error. org.bytedeco.javacv.FFmpegFrameRecorder$Exception: No audio output stream (Is audioChannels > 0 and has start() been called?) (For more details, make sure FFmpegLogCallback.set() has been called.)

recorder.recordSamples(sampleRate, numChannels, sBuff); //Error Line


saudet commented 1 year ago

Please use record(Frame) instead of recordSamples().

Nycrera commented 1 year ago

Well, the exception message may be on point.

Two things I would check: Has the recorder been started with start()? and When constructing the recorder have you set the audioChannel count?

Simply try setting the audiochannels with: recorder.setAudioChannels(2); Before starting the recorder.

muguryildirim commented 1 year ago

Hey @saudet , what you said yesterday, did not work. I ran a different code with using 'Mixer' and this is the result I got ( I'm currently working with Ubuntu OS )

"Line unsupported: interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame. little-endian.
TargetDataLine line = (TargetDataLine) mixer.getLine(dataLineinfo); // Cause of error.
muguryildirim commented 1 year ago

I've got it, thank you both.

saudet commented 1 year ago

If you're trying to record audio from the microphone, there's a working example here: https://github.com/bytedeco/javacv/blob/master/samples/WebcamAndMicrophoneCapture.java