bytedeco/javacv

AAC streamed byte packets and recordSamples

Aperta

#1933 aperta il 10 nov 2022

 (12 commenti) (0 reazioni) (0 assegnatari)Java (1583 fork)batch import
enhancementhelp wantedquestion

Metriche repository

Star
 (6985 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

I have a use case to get packets from a streaming server, from an RTMP encoder. And transcode to Ogg/Opus using recordSamples. It's similar to the microphone examples but different. Giving the recorder the raw AAC bytes produces a noisy output. Using the frame grabber to be the rtmp client works.

Does the AAC packets need to be decoded to PCM first to be usable ? Is there a way to do this without passing them to the framegrabber or can they be sent to a frame grabber using PipedInputStream ?

It's not a common use case it seems I only see microphone inputs that is PCM already. The server might have a utility already to decode the AAC packets to PCM to be consumable by the recorder.

Example of what I am trying to do right now but the output has to go to an outputstream for sending bytes to a websocket service.

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("D:\\test.ogg", 1);
	    	recorder.setFormat("ogg");
	    	recorder.setAudioCodec(AV_CODEC_ID_OPUS);
	    	recorder.setSampleFormat(AV_SAMPLE_FMT_FLT);
	    	recorder.setAudioOption("vbr", "constrained");
	        recorder.setAudioBitrate(24000);
	        recorder.setSampleRate(16000);
	        recorder.setAudioChannels(1);	
 recorder.start();

Then in the packet capture method. I dont know the method yet to get the samplerate from the input packets. packet.getData is an AAC packet.

byte[] data = packet.getData();
ByteBuffer buffer = ByteBuffer.wrap(data);
recorder.recordSamples(48000, 2, buffer);

Guida contributor