@Override public AudioBuffer decodeFrame(ByteBuffer frame, ByteBuffer dst) throws IOException { return new AudioBuffer(frame, format, frame.remaining() / format.getFrameSize()); }
protected ByteBuffer decodeAudio(ByteBuffer audioPkt) throws IOException { if (inputAudioCodec.v2 == Codec.PCM) { return audioPkt; } else { AudioBuffer decodeFrame = audioDecoder.decodeFrame(audioPkt, null); return decodeFrame.getData(); } }
@Override public void outputAudioFrame(AudioFrameWithPacket audioFrame) throws IOException { if (!outputFormat.isAudio() || outputAudioCodec == null) return; outputAudioPacket(Packet.createPacketWithData(audioFrame.getPacket(), encodeAudio(audioFrame.getAudio())), org.jcodec.common.AudioCodecMeta.fromAudioFormat(audioFrame.getAudio().getFormat())); }
return new AudioBuffer(dst, new AudioFormat(sampleRate, sampleSizeInBits, channelCount, true, false), nFrames);
return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 24, channels, true, true), nSamples / channels); } else if (sampleSizeInBits == 20) { int nSamples = (frame.remaining() / 6) * 2; return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 24, channels, true, true), nSamples / channels); } else { int nSamples = (frame.remaining() / 5) * 2; return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 16, channels, true, true), nSamples / channels);
@Override public AudioBuffer decodeFrame(ByteBuffer frame, ByteBuffer dst) throws IOException { MpaHeader header = MpaHeader.read_header(frame); if (!initialized) { init(header); } boolean intensityStereo = ((header.mode == JOINT_STEREO) && ((header.modeExtension & 0x1) != 0)); if (intensityStereo) throw new RuntimeException("Intensity stereo is not supported."); dst.order(ByteOrder.LITTLE_ENDIAN); MP3SideInfo si = Mp3Bitstream.readSideInfo(header, frame, channels); int reserve = frameData.position(); frameData.put(NIOUtils.read(frame, header.frameBytes)); frameData.flip(); if (header.protectionBit == 0) { frame.getShort(); } NIOUtils.skip(frameData, reserve - si.mainDataBegin); BitReader br = BitReader.createBitReader(frameData); ScaleFactors[] scalefac = new ScaleFactors[2]; decodeGranule(header, dst, si, br, scalefac, 0); if (header.version == MPEG1) decodeGranule(header, dst, si, br, scalefac, 1); br.terminate(); NIOUtils.relocateLeftover(frameData); dst.flip(); return new AudioBuffer(dst, null, 1); }
@Override public AudioBuffer decodeFrame(ByteBuffer frame, ByteBuffer dst) throws IOException { // Internally all AAC streams are ADTS wrapped ADTSParser.read(frame); SampleBuffer sampleBuffer = new SampleBuffer(); decoder.decodeFrame(NIOUtils.toArray(frame), sampleBuffer); if (sampleBuffer.isBigEndian()) { // Not a simple setter! This will also swap the order of bytes inside the buffer. sampleBuffer.setBigEndian(false); } return new AudioBuffer(ByteBuffer.wrap(sampleBuffer.getData()), toAudioFormat(sampleBuffer), 0); }
@Override public AudioFrameWithPacket getNextAudioFrame() throws IOException { Packet audioPkt = inputAudioPacket(); if (audioPkt == null) return null; AudioBuffer audioBuffer; if (inputAudioCodec.v2 == Codec.PCM) { DemuxerTrackMeta audioMeta = getAudioMeta(); audioBuffer = new AudioBuffer(audioPkt.getData(), audioMeta.getAudioCodecMeta().getFormat(), audioMeta.getTotalFrames()); } else { audioBuffer = audioDecoder.decodeFrame(audioPkt.getData(), null); } return new AudioFrameWithPacket(audioBuffer, audioPkt); }