当前位置: 首页>>代码示例>>Java>>正文


Java Format.createVideoSampleFormat方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.Format.createVideoSampleFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Format.createVideoSampleFormat方法的具体用法?Java Format.createVideoSampleFormat怎么用?Java Format.createVideoSampleFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.Format的用法示例。


在下文中一共展示了Format.createVideoSampleFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCsdBuffer

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
/**
 * Parses the {@link Format} and frame duration from a csd buffer.
 *
 * @param csdBuffer The csd buffer.
 * @param formatId The id for the generated format. May be null.
 * @return A pair consisting of the {@link Format} and the frame duration in microseconds, or
 *     0 if the duration could not be determined.
 */
private static Pair<Format, Long> parseCsdBuffer(CsdBuffer csdBuffer, String formatId) {
  byte[] csdData = Arrays.copyOf(csdBuffer.data, csdBuffer.length);

  int firstByte = csdData[4] & 0xFF;
  int secondByte = csdData[5] & 0xFF;
  int thirdByte = csdData[6] & 0xFF;
  int width = (firstByte << 4) | (secondByte >> 4);
  int height = (secondByte & 0x0F) << 8 | thirdByte;

  float pixelWidthHeightRatio = 1f;
  int aspectRatioCode = (csdData[7] & 0xF0) >> 4;
  switch(aspectRatioCode) {
    case 2:
      pixelWidthHeightRatio = (4 * height) / (float) (3 * width);
      break;
    case 3:
      pixelWidthHeightRatio = (16 * height) / (float) (9 * width);
      break;
    case 4:
      pixelWidthHeightRatio = (121 * height) / (float) (100 * width);
      break;
    default:
      // Do nothing.
      break;
  }

  Format format = Format.createVideoSampleFormat(formatId, MimeTypes.VIDEO_MPEG2, null,
      Format.NO_VALUE, Format.NO_VALUE, width, height, Format.NO_VALUE,
      Collections.singletonList(csdData), Format.NO_VALUE, pixelWidthHeightRatio, null);

  long frameDurationUs = 0;
  int frameRateCodeMinusOne = (csdData[7] & 0x0F) - 1;
  if (0 <= frameRateCodeMinusOne && frameRateCodeMinusOne < FRAME_RATE_VALUES.length) {
    double frameRate = FRAME_RATE_VALUES[frameRateCodeMinusOne];
    int sequenceExtensionPosition = csdBuffer.sequenceExtensionPosition;
    int frameRateExtensionN = (csdData[sequenceExtensionPosition + 9] & 0x60) >> 5;
    int frameRateExtensionD = (csdData[sequenceExtensionPosition + 9] & 0x1F);
    if (frameRateExtensionN != frameRateExtensionD) {
      frameRate *= (frameRateExtensionN + 1d) / (frameRateExtensionD + 1);
    }
    frameDurationUs = (long) (C.MICROS_PER_SECOND / frameRate);
  }

  return Pair.create(format, frameDurationUs);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:54,代码来源:H262Reader.java

示例2: parsePayload

import com.google.android.exoplayer2.Format; //导入方法依赖的package包/类
@Override
protected void parsePayload(ParsableByteArray data, long timeUs) throws ParserException {
  int packetType = data.readUnsignedByte();
  int compositionTimeMs = data.readUnsignedInt24();
  timeUs += compositionTimeMs * 1000L;
  // Parse avc sequence header in case this was not done before.
  if (packetType == AVC_PACKET_TYPE_SEQUENCE_HEADER && !hasOutputFormat) {
    ParsableByteArray videoSequence = new ParsableByteArray(new byte[data.bytesLeft()]);
    data.readBytes(videoSequence.data, 0, data.bytesLeft());
    AvcConfig avcConfig = AvcConfig.parse(videoSequence);
    nalUnitLengthFieldLength = avcConfig.nalUnitLengthFieldLength;
    // Construct and output the format.
    Format format = Format.createVideoSampleFormat(null, MimeTypes.VIDEO_H264, null,
        Format.NO_VALUE, Format.NO_VALUE, avcConfig.width, avcConfig.height, Format.NO_VALUE,
        avcConfig.initializationData, Format.NO_VALUE, avcConfig.pixelWidthAspectRatio, null);
    output.format(format);
    hasOutputFormat = true;
  } else if (packetType == AVC_PACKET_TYPE_AVC_NALU && hasOutputFormat) {
    // TODO: Deduplicate with Mp4Extractor.
    // Zero the top three bytes of the array that we'll use to decode nal unit lengths, in case
    // they're only 1 or 2 bytes long.
    byte[] nalLengthData = nalLength.data;
    nalLengthData[0] = 0;
    nalLengthData[1] = 0;
    nalLengthData[2] = 0;
    int nalUnitLengthFieldLengthDiff = 4 - nalUnitLengthFieldLength;
    // NAL units are length delimited, but the decoder requires start code delimited units.
    // Loop until we've written the sample to the track output, replacing length delimiters with
    // start codes as we encounter them.
    int bytesWritten = 0;
    int bytesToWrite;
    while (data.bytesLeft() > 0) {
      // Read the NAL length so that we know where we find the next one.
      data.readBytes(nalLength.data, nalUnitLengthFieldLengthDiff, nalUnitLengthFieldLength);
      nalLength.setPosition(0);
      bytesToWrite = nalLength.readUnsignedIntToInt();

      // Write a start code for the current NAL unit.
      nalStartCode.setPosition(0);
      output.sampleData(nalStartCode, 4);
      bytesWritten += 4;

      // Write the payload of the NAL unit.
      output.sampleData(data, bytesToWrite);
      bytesWritten += bytesToWrite;
    }
    output.sampleMetadata(timeUs, frameType == VIDEO_FRAME_KEYFRAME ? C.BUFFER_FLAG_KEY_FRAME : 0,
        bytesWritten, 0, null);
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:51,代码来源:VideoTagPayloadReader.java


注:本文中的com.google.android.exoplayer2.Format.createVideoSampleFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。