示例#1
0
    public ByteBuffer transcodeFrame(ByteBuffer src, ByteBuffer dst) throws IOException {
      if (src == null) return null;
      Picture8Bit decoded = decoder.decodeFrame8Bit(src, pic0.getData());
      if (pic1 == null) {
        pic1 =
            Picture8Bit.create(
                decoded.getWidth(), decoded.getHeight(), encoder.getSupportedColorSpaces()[0]);
        transform =
            ColorUtil.getTransform8Bit(decoded.getColor(), encoder.getSupportedColorSpaces()[0]);
      }
      transform.transform(decoded, pic1);
      pic1.setCrop(new Rect(0, 0, track.thumbWidth, track.thumbHeight));
      int rate = TARGET_RATE;
      do {
        try {
          encoder.encodeFrame8Bit(pic1, dst);
          break;
        } catch (BufferOverflowException ex) {
          Logger.warn("Abandon frame, buffer too small: " + dst.capacity());
          rate -= 10;
          rc.setRate(rate);
        }
      } while (rate > 10);
      rc.setRate(TARGET_RATE);

      H264Utils.encodeMOVPacket(dst);

      return dst;
    }
示例#2
0
    public Frame decodeFrame(List<ByteBuffer> nalUnits, byte[][] buffer) {
      Frame result = null;

      for (ByteBuffer nalUnit : nalUnits) {
        NALUnit marker = NALUnit.read(nalUnit);

        unescapeNAL(nalUnit);

        switch (marker.type) {
          case NON_IDR_SLICE:
          case IDR_SLICE:
            if (result == null) {
              if (sps.size() == 0 || pps.size() == 0) {
                Logger.warn("Skipping frame as no SPS/PPS have been seen so far...");
                return null;
              }
              result = init(buffer, nalUnit, marker);
            }
            decoder.decode(nalUnit, marker);
            break;
          case SPS:
            SeqParameterSet _sps = SeqParameterSet.read(nalUnit);
            sps.put(_sps.seq_parameter_set_id, _sps);
            break;
          case PPS:
            PictureParameterSet _pps = PictureParameterSet.read(nalUnit);
            pps.put(_pps.pic_parameter_set_id, _pps);
            break;
          default:
        }
      }

      filter.deblockFrame(result);

      updateReferences(result);

      return result;
    }
  protected void read(Map<Integer, ByteBuffer> tags) {
    super.read(tags);

    for (Iterator<Entry<Integer, ByteBuffer>> it = tags.entrySet().iterator(); it.hasNext(); ) {
      Entry<Integer, ByteBuffer> entry = it.next();

      ByteBuffer _bb = entry.getValue();

      switch (entry.getKey()) {
        case 0x3215:
          signalStandard = _bb.get();
          break;
        case 0x320c:
          frameLayout = LayoutType.values()[_bb.get()];
          break;
        case 0x3203:
          storedWidth = _bb.getInt();
          break;
        case 0x3202:
          storedHeight = _bb.getInt();
          break;
        case 0x3216:
          storedF2Offset = _bb.getInt();
          break;
        case 0x3205:
          sampledWidth = _bb.getInt();
          break;
        case 0x3204:
          sampledHeight = _bb.getInt();
          break;
        case 0x3206:
          sampledXOffset = _bb.getInt();
          break;
        case 0x3207:
          sampledYOffset = _bb.getInt();
          break;
        case 0x3208:
          displayHeight = _bb.getInt();
          break;
        case 0x3209:
          displayWidth = _bb.getInt();
          break;
        case 0x320a:
          displayXOffset = _bb.getInt();
          break;
        case 0x320b:
          displayYOffset = _bb.getInt();
          break;
        case 0x3217:
          displayF2Offset = _bb.getInt();
          break;
        case 0x320e:
          aspectRatio = new Rational(_bb.getInt(), _bb.getInt());
          break;
        case 0x3218:
          activeFormatDescriptor = _bb.get();
          break;
        case 0x320d:
          videoLineMap = readInt32Batch(_bb);
          break;
        case 0x320f:
          alphaTransparency = _bb.get();
          break;
        case 0x3210:
          transferCharacteristic = UL.read(_bb);
          break;
        case 0x3211:
          imageAlignmentOffset = _bb.getInt();
          break;
        case 0x3213:
          imageStartOffset = _bb.getInt();
          break;
        case 0x3214:
          imageEndOffset = _bb.getInt();
          break;
        case 0x3212:
          fieldDominance = _bb.get();
          break;
        case 0x3201:
          pictureEssenceCoding = UL.read(_bb);
          break;
        case 0x321a:
          codingEquations = UL.read(_bb);
          break;
        case 0x3219:
          colorPrimaries = UL.read(_bb);
          break;
        default:
          Logger.warn(String.format("Unknown tag [ " + ul + "]: %04x", entry.getKey()));
          continue;
      }
      it.remove();
    }
  }