@Override public DemuxerTrackMeta getMeta() { return new DemuxerTrackMeta(DemuxerTrackMeta.Type.AUDIO, null, totalFrames, (double) duration / timescale, null); } }
private int detectKeyFrame(int start) throws IOException { int[] seekFrames = videoTrack.getMeta().getSeekFrames(); if (seekFrames == null) return start; int prev = seekFrames[0]; for (int i = 1; i < seekFrames.length; i++) { if (seekFrames[i] > start) break; prev = seekFrames[i]; } return prev; }
@Override public AudioCodecMeta getAudioCodecMeta() { if (audioInputTrack != null && audioInputTrack.getMeta() != null && audioInputTrack.getMeta().getAudioCodecMeta() != null) { return audioInputTrack.getMeta().getAudioCodecMeta(); } return audioCodecMeta; }
double sec = (double) duration.getNum() / duration.getDen(); int frameCount = Ints.checkedCast(track.getFrameCount()); DemuxerTrackMeta meta = new DemuxerTrackMeta(t, Codec.codecByFourcc(track.getFourcc()), sec, seekFrames, frameCount, getCodecPrivate(track), videoCodecMeta, audioCodecMeta); orientation = DemuxerTrackMeta.Orientation.D_0; meta.setOrientation(orientation);
ByteBuffer codecPrivate = inTrack.getMeta().getCodecPrivate(); H264Decoder decoder = H264Decoder.createH264DecoderFromCodecPrivate(codecPrivate); int totalFrames = (int) inTrack.getMeta().getTotalFrames(), seqNo = 0; for (int i = sf; (inFrame = inTrack.nextFrame()) != null; i++) { ByteBuffer data = inFrame.getData(); Size size = inTrack.getMeta().getVideoCodecMeta().getSize();
@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); }
@Override public VideoCodecMeta getVideoCodecMeta() { if (videoCodecMeta != null) return videoCodecMeta; DemuxerTrackMeta meta = getTrackVideoMeta(); if (meta != null && meta.getVideoCodecMeta() != null) { videoCodecMeta = meta.getVideoCodecMeta(); } return videoCodecMeta; }
private static ContainerAdaptor detectDecoder(SeekableDemuxerTrack videoTrack) throws JCodecException { DemuxerTrackMeta meta = videoTrack.getMeta(); switch (meta.getCodec()) { case H264: return new AVCMP4Adaptor(meta); default: throw new UnsupportedFormatException("Codec is not supported"); } }
private void updateState(Packet packet) { int eNo = ((MP4Packet) packet).getEntryNo(); if (eNo != curENo) { curENo = eNo; // avcCBox = H264Utils.parseAVCC((VideoSampleEntry) ses[curENo]); // decoder = new H264Decoder(); // ((H264Decoder) decoder).addSps(avcCBox.getSpsList()); // ((H264Decoder) decoder).addPps(avcCBox.getPpsList()); } if(decoder == null) { decoder = H264Decoder.createH264DecoderFromCodecPrivate(meta.getCodecPrivate()); } }
/** * Get frame at current position in JCodec native image * * @return A decoded picture with metadata. * @throws IOException */ public PictureWithMetadata getNativeFrameWithMetadata() throws IOException { Packet frame = videoTrack.nextFrame(); if (frame == null) return null; Picture picture = decoder.decodeFrame(frame, getBuffer()); return new PictureWithMetadata(picture, frame.getPtsD(), frame.getDurationD(), videoTrack.getMeta().getOrientation()); }
@Override public Picture decodeFrame(Packet packet, byte[][] data) { updateState(packet); Picture pic = decoder.decodeFrame(packet.getData(), data); Rational pasp = meta.getVideoCodecMeta().getPixelAspectRatio(); if (pasp != null) { // TODO: transform } return pic; }
private static Codec detectVideoDecoder(DemuxerTrack track) throws IOException { DemuxerTrackMeta meta = track.getMeta(); if (meta != null) { Codec codec = meta.getCodec(); if (codec != null) return codec; } Packet packet = track.nextFrame(); if (packet == null) return null; return JCodecUtil.detectDecoder(packet.getData()); }
private void calcBufferSize() { int w = Integer.MIN_VALUE, h = Integer.MIN_VALUE; ByteBuffer bb = meta.getCodecPrivate().duplicate(); ByteBuffer b; while((b = H264Utils.nextNALUnit(bb)) != null) { NALUnit nu = NALUnit.read(b); if(nu.type != NALUnitType.SPS) continue; SeqParameterSet sps = H264Utils.readSPS(b); int ww = sps.picWidthInMbsMinus1 + 1; if (ww > w) w = ww; int hh = SeqParameterSet.getPicHeightInMbs(sps); if (hh > h) h = hh; } size = new Size(w << 4, h << 4); }
@Override public DemuxerTrackMeta getMeta() { return new DemuxerTrackMeta(DemuxerTrackMeta.Type.AUDIO, null, totalFrames, (double) duration / timescale, null); } }
private long getPreviousKeyFrame(long start) { DemuxerTrackMeta meta = videoTrack.getMeta(); if(meta == null) { // No information about keyframes available. Assume every frame is selfcontained. return start; } int[] seekFrames = meta.getSeekFrames(); if (seekFrames == null) { return start; } int prev = seekFrames[0]; for (int i = 1; i < seekFrames.length; i++) { if (seekFrames[i] > start) { break; } prev = seekFrames[i]; } return prev; }
private AudioDecoder createAudioDecoder(ByteBuffer codecPrivate) throws AACException { switch (inputAudioCodec.v2) { case AAC: return new AACDecoder(codecPrivate); case PCM: return new RawAudioDecoder(getAudioMeta().getAudioCodecMeta().getFormat()); } return null; }
@Override public DemuxerTrackMeta getMeta() { TrackType t = type == Type.VIDEO ? TrackType.VIDEO : TrackType.AUDIO; return new DemuxerTrackMeta(t, codec, 0, null, 0, ByteBuffer.wrap(codecPrivate), null, null); }
private long getPreviousKeyFrame(long start) { DemuxerTrackMeta meta = videoTrack.getMeta(); if(meta == null) { // No information about keyframes available. Assume every frame is selfcontained. return start; } int[] seekFrames = meta.getSeekFrames(); if (seekFrames == null) { return start; } int prev = seekFrames[0]; for (int i = 1; i < seekFrames.length; i++) { if (seekFrames[i] > start) { break; } prev = seekFrames[i]; } return prev; }
@Override public DemuxerTrackMeta getMeta() { int durationFrames = getMaxAvailableFrame(); return new DemuxerTrackMeta(TrackType.VIDEO, codec, (durationFrames + 1) * VIDEO_FPS, null, durationFrames + 1, null, null, null); } }
@Override public DemuxerTrackMeta getMeta() { if(syncSamples == null) { return null; } int[] copyOf = Arrays.copyOf(syncSamples, syncSamples.length); for (int i = 0; i < copyOf.length; i++) copyOf[i]--; TrackType type = getType(); return new DemuxerTrackMeta(type == TrackType.VIDEO ? VIDEO : (type == TrackType.SOUND ? AUDIO : OTHER), copyOf, sizes.length, (double) duration / timescale, box.getCodedSize()); } }