public static TapeTimecode tapeTimecode(long frame, boolean dropFrame, int tapeFps) { if (dropFrame) { long D = frame / 17982; long M = frame % 17982; frame += 18 * D + 2 * ((M - 2) / 1798); } long sec = frame / tapeFps; return new TapeTimecode((short) (sec / 3600), (byte) ((sec / 60) % 60), (byte) (sec % 60), (byte) (frame % tapeFps), dropFrame, tapeFps); } }
private int toCounter(TapeTimecode tc, int fps) { int frames = toSec(tc) * fps + tc.getFrame(); if (tc.isDropFrame()) { long D = frames / 18000; long M = frames % 18000; frames -= 18 * D + 2 * ((M - 2) / 1800); } return frames; }
@Override public void write(ByteBuffer bb) { BitWriter bw = new BitWriter(bb); if (timeCode == null) bw.writeNBit(0, 25); else { bw.write1Bit(timeCode.isDropFrame() ? 1 : 0); bw.writeNBit(timeCode.getHour(), 5); bw.writeNBit(timeCode.getMinute(), 6); bw.write1Bit(1); bw.writeNBit(timeCode.getSecond(), 6); bw.writeNBit(timeCode.getFrame(), 6); } bw.write1Bit(closedGop ? 1 : 0); bw.write1Bit(brokenLink ? 1 : 0); bw.flush(); }
private boolean isGap(TapeTimecode prevTimecode, TapeTimecode tapeTimecode) { boolean gap = false; if (prevTimecode == null && tapeTimecode != null) { gap = true; } else if (prevTimecode != null) { if (tapeTimecode == null) gap = true; else { if (prevTimecode.isDropFrame() != tapeTimecode.isDropFrame()) { gap = true; } else { gap = isTimeGap(prevTimecode, tapeTimecode); } } } return gap; }
private static TapeTimecode _getTimecode(int startCounter, int frameNo, TimecodeSampleEntry entry) { return TapeTimecode.tapeTimecode(frameNo + startCounter, entry.isDropFrame(), entry.getNumFrames() & 0xff); }
private void dumpGroupHeader(ByteBuffer b) { GOPHeader gopHeader = GOPHeader.read(b); System.out.print(MainUtils.colorBright("group header" + " <closed:" + gopHeader.isClosedGop() + ",broken link:" + gopHeader.isBrokenLink() + (gopHeader.getTimeCode() != null ? (",timecode:" + gopHeader.getTimeCode().toString()) : "") + ">", MainUtils.ANSIColor.MAGENTA, true)); }
private boolean isGap(TapeTimecode prevTimecode, TapeTimecode tapeTimecode) { boolean gap = false; if (prevTimecode == null && tapeTimecode != null) { gap = true; } else if (prevTimecode != null) { if (tapeTimecode == null) gap = true; else { if (prevTimecode.isDropFrame() != tapeTimecode.isDropFrame()) { gap = true; } else { gap = isTimeGap(prevTimecode, tapeTimecode); } } } return gap; }
public static TapeTimecode readTapeTimecode(File mxf) throws IOException { FileChannelWrapper read = NIOUtils.readableChannel(mxf); try { Fast fast = new Fast(read); MXFDemuxerTrack track = fast.getVideoTrack(); TimecodeComponent timecode = fast.getTimecode(); List<SourceClip> sourceClips = fast.getSourceClips(track.getTrackId()); long tc = 0; boolean dropFrame = false; Rational editRate = null; if (timecode != null) { editRate = track.getEditRate(); dropFrame = timecode.getDropFrame() != 0; tc = timecode.getStart(); } for (SourceClip sourceClip : sourceClips) { tc += sourceClip.getStartPosition(); } if (editRate != null) { return TapeTimecode.tapeTimecode(tc, dropFrame, (int) Math.ceil(editRate.toDouble())); } return null; } finally { read.close(); } }
private int toCounter(TapeTimecode tc, int fps) { int frames = toSec(tc) * fps + tc.getFrame(); if (tc.isDropFrame()) { long D = frames / 18000; long M = frames % 18000; frames -= 18 * D + 2 * ((M - 2) / 1800); } return frames; }
private boolean isGap(TapeTimecode prevTimecode, TapeTimecode tapeTimecode) { boolean gap = false; if (prevTimecode == null && tapeTimecode != null) { gap = true; } else if (prevTimecode != null) { if (tapeTimecode == null) gap = true; else { if (prevTimecode.isDropFrame() != tapeTimecode.isDropFrame()) { gap = true; } else { gap = isTimeGap(prevTimecode, tapeTimecode); } } } return gap; }
private TapeTimecode getTimecode(int startCounter, int frameNo, TimecodeSampleEntry entry) { int frame = dropFrameAdjust(frameNo + startCounter, entry); int sec = frame / entry.getNumFrames(); return new TapeTimecode((short) (sec / 3600), (byte) ((sec / 60) % 60), (byte) (sec % 60), (byte) (frame % entry.getNumFrames()), entry.isDropFrame()); }
private int toCounter(TapeTimecode tc, int fps) { int frames = toSec(tc) * fps + tc.getFrame(); if (tc.isDropFrame()) { long D = frames / 18000; long M = frames % 18000; frames -= 18 * D + 2 * ((M - 2) / 1800); } return frames; }
private void addTimecodeInt(Packet packet) throws IOException { TapeTimecode tapeTimecode = packet.getTapeTimecode(); boolean gap = isGap(prevTimecode, tapeTimecode); prevTimecode = tapeTimecode; if (gap) { outTimecodeSample(); firstTimecode = tapeTimecode; fpsEstimate = tapeTimecode.isDropFrame() ? 30 : -1; samplePts += sampleDuration; sampleDuration = 0; tcFrames = 0; } sampleDuration += packet.getDuration(); tcFrames++; }
private TapeTimecode getTimecode(int startCounter, int frameNo, TimecodeSampleEntry entry) { int frame = dropFrameAdjust(frameNo + startCounter, entry); int sec = frame / entry.getNumFrames(); return new TapeTimecode((short) (sec / 3600), (byte) ((sec / 60) % 60), (byte) (sec % 60), (byte) (frame % entry.getNumFrames()), entry.isDropFrame()); }
private boolean isTimeGap(TapeTimecode prevTimecode, TapeTimecode tapeTimecode) { boolean gap = false; int sec = toSec(tapeTimecode); int secDiff = sec - toSec(prevTimecode); if (secDiff == 0) { int frameDiff = tapeTimecode.getFrame() - prevTimecode.getFrame(); if (fpsEstimate != -1) frameDiff = (frameDiff + fpsEstimate) % fpsEstimate; gap = frameDiff != 1; } else if (secDiff == 1) { if (fpsEstimate == -1) { if (tapeTimecode.getFrame() == 0) fpsEstimate = prevTimecode.getFrame() + 1; else gap = true; } else { int firstFrame = tapeTimecode.isDropFrame() && (sec % 60) == 0 && (sec % 600) != 0 ? 2 : 0; if (tapeTimecode.getFrame() != firstFrame || prevTimecode.getFrame() != fpsEstimate - 1) gap = true; } } else { gap = true; } return gap; }
private void addTimecodeInt(Packet packet) throws IOException { TapeTimecode tapeTimecode = packet.getTapeTimecode(); boolean gap = isGap(prevTimecode, tapeTimecode); prevTimecode = tapeTimecode; if (gap) { outTimecodeSample(); firstTimecode = tapeTimecode; fpsEstimate = tapeTimecode.isDropFrame() ? 30 : -1; samplePts += sampleDuration; sampleDuration = 0; tcFrames = 0; } sampleDuration += packet.getDuration(); tcFrames++; }
public static GOPHeader read(ByteBuffer bb) { BitReader _in = BitReader.createBitReader(bb); boolean dropFrame = _in.read1Bit() == 1; short hours = (short) _in.readNBit(5); byte minutes = (byte) _in.readNBit(6); _in.skip(1); byte seconds = (byte) _in.readNBit(6); byte frames = (byte) _in.readNBit(6); boolean closedGop = _in.read1Bit() == 1; boolean brokenLink = _in.read1Bit() == 1; return new GOPHeader(new TapeTimecode(hours, minutes, seconds, frames, dropFrame, 0), closedGop, brokenLink); }