Java Code Examples for com.google.android.exoplayer2.extractor.TrackOutput#format()

The following examples show how to use com.google.android.exoplayer2.extractor.TrackOutput#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeiReader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
        || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    String formatId = channelFormat.id != null ? channelFormat.id : idGenerator.getFormatId();
    output.format(
        Format.createTextSampleFormat(
            formatId,
            channelMimeType,
            /* codecs= */ null,
            /* bitrate= */ Format.NO_VALUE,
            channelFormat.selectionFlags,
            channelFormat.language,
            channelFormat.accessibilityChannel,
            /* drmInitData= */ null,
            Format.OFFSET_SAMPLE_RELATIVE,
            channelFormat.initializationData));
    outputs[i] = output;
  }
}
 
Example 2
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void maybeInitExtraTracks() {
  if (emsgTrackOutputs == null) {
    emsgTrackOutputs = new TrackOutput[2];
    int emsgTrackOutputCount = 0;
    if (additionalEmsgTrackOutput != null) {
      emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
    }
    if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
      emsgTrackOutputs[emsgTrackOutputCount++] =
          extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
    }
    emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);

    for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
      eventMessageTrackOutput.format(EMSG_FORMAT);
    }
  }
  if (cea608TrackOutputs == null) {
    cea608TrackOutputs = new TrackOutput[closedCaptionFormats.size()];
    for (int i = 0; i < cea608TrackOutputs.length; i++) {
      TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT);
      output.format(closedCaptionFormats.get(i));
      cea608TrackOutputs[i] = output;
    }
  }
}
 
Example 3
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void maybeInitExtraTracks() {
  if (emsgTrackOutputs == null) {
    emsgTrackOutputs = new TrackOutput[2];
    int emsgTrackOutputCount = 0;
    if (additionalEmsgTrackOutput != null) {
      emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
    }
    if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
      emsgTrackOutputs[emsgTrackOutputCount++] =
          extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
    }
    emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);

    for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
      eventMessageTrackOutput.format(EMSG_FORMAT);
    }
  }
  if (cea608TrackOutputs == null) {
    cea608TrackOutputs = new TrackOutput[closedCaptionFormats.size()];
    for (int i = 0; i < cea608TrackOutputs.length; i++) {
      TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT);
      output.format(closedCaptionFormats.get(i));
      cea608TrackOutputs[i] = output;
    }
  }
}
 
Example 4
Source File: UserDataReader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public void createTracks(
    ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(
        MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
            || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    output.format(
        Format.createTextSampleFormat(
            idGenerator.getFormatId(),
            channelMimeType,
            /* codecs= */ null,
            /* bitrate= */ Format.NO_VALUE,
            channelFormat.selectionFlags,
            channelFormat.language,
            channelFormat.accessibilityChannel,
            /* drmInitData= */ null,
            Format.OFFSET_SAMPLE_RELATIVE,
            channelFormat.initializationData));
    outputs[i] = output;
  }
}
 
Example 5
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void maybeInitExtraTracks() {
  if (emsgTrackOutputs == null) {
    emsgTrackOutputs = new TrackOutput[2];
    int emsgTrackOutputCount = 0;
    if (additionalEmsgTrackOutput != null) {
      emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
    }
    if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
      emsgTrackOutputs[emsgTrackOutputCount++] =
          extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
    }
    emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);

    for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
      eventMessageTrackOutput.format(EMSG_FORMAT);
    }
  }
  if (cea608TrackOutputs == null) {
    cea608TrackOutputs = new TrackOutput[closedCaptionFormats.size()];
    for (int i = 0; i < cea608TrackOutputs.length; i++) {
      TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT);
      output.format(closedCaptionFormats.get(i));
      cea608TrackOutputs[i] = output;
    }
  }
}
 
Example 6
Source File: UserDataReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void createTracks(
    ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(
        MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
            || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    output.format(
        Format.createTextSampleFormat(
            idGenerator.getFormatId(),
            channelMimeType,
            /* codecs= */ null,
            /* bitrate= */ Format.NO_VALUE,
            channelFormat.selectionFlags,
            channelFormat.language,
            channelFormat.accessibilityChannel,
            /* drmInitData= */ null,
            Format.OFFSET_SAMPLE_RELATIVE,
            channelFormat.initializationData));
    outputs[i] = output;
  }
}
 
Example 7
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static void outputFormat(
    FlacStreamMetadata streamMetadata, @Nullable Metadata metadata, TrackOutput output) {
  Format mediaFormat =
      Format.createAudioSampleFormat(
          /* id= */ null,
          MimeTypes.AUDIO_RAW,
          /* codecs= */ null,
          streamMetadata.bitRate(),
          streamMetadata.maxDecodedFrameSize(),
          streamMetadata.channels,
          streamMetadata.sampleRate,
          getPcmEncoding(streamMetadata.bitsPerSample),
          /* encoderDelay= */ 0,
          /* encoderPadding= */ 0,
          /* initializationData= */ null,
          /* drmInitData= */ null,
          /* selectionFlags= */ 0,
          /* language= */ null,
          metadata);
  output.format(mediaFormat);
}
 
Example 8
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void maybeInitExtraTracks() {
  if (emsgTrackOutputs == null) {
    emsgTrackOutputs = new TrackOutput[2];
    int emsgTrackOutputCount = 0;
    if (additionalEmsgTrackOutput != null) {
      emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
    }
    if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
      emsgTrackOutputs[emsgTrackOutputCount++] =
          extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
    }
    emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);

    for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
      eventMessageTrackOutput.format(EMSG_FORMAT);
    }
  }
  if (cea608TrackOutputs == null) {
    cea608TrackOutputs = new TrackOutput[closedCaptionFormats.size()];
    for (int i = 0; i < cea608TrackOutputs.length; i++) {
      TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT);
      output.format(closedCaptionFormats.get(i));
      cea608TrackOutputs[i] = output;
    }
  }
}
 
Example 9
Source File: FlacExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static void outputFormat(
    FlacStreamMetadata streamMetadata, @Nullable Metadata metadata, TrackOutput output) {
  Format mediaFormat =
      Format.createAudioSampleFormat(
          /* id= */ null,
          MimeTypes.AUDIO_RAW,
          /* codecs= */ null,
          streamMetadata.bitRate(),
          streamMetadata.maxDecodedFrameSize(),
          streamMetadata.channels,
          streamMetadata.sampleRate,
          getPcmEncoding(streamMetadata.bitsPerSample),
          /* encoderDelay= */ 0,
          /* encoderPadding= */ 0,
          /* initializationData= */ null,
          /* drmInitData= */ null,
          /* selectionFlags= */ 0,
          /* language= */ null,
          metadata);
  output.format(mediaFormat);
}
 
Example 10
Source File: UserDataReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void createTracks(
    ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(
        MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
            || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    output.format(
        Format.createTextSampleFormat(
            idGenerator.getFormatId(),
            channelMimeType,
            /* codecs= */ null,
            /* bitrate= */ Format.NO_VALUE,
            channelFormat.selectionFlags,
            channelFormat.language,
            channelFormat.accessibilityChannel,
            /* drmInitData= */ null,
            Format.OFFSET_SAMPLE_RELATIVE,
            channelFormat.initializationData));
    outputs[i] = output;
  }
}
 
Example 11
Source File: DvbSubtitleReader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    DvbSubtitleInfo subtitleInfo = subtitleInfos.get(i);
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    output.format(
        Format.createImageSampleFormat(
            idGenerator.getFormatId(),
            MimeTypes.APPLICATION_DVBSUBS,
            null,
            Format.NO_VALUE,
            0,
            Collections.singletonList(subtitleInfo.initializationData),
            subtitleInfo.language,
            null));
    outputs[i] = output;
  }
}
 
Example 12
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void maybeInitExtraTracks() {
  if (emsgTrackOutputs == null) {
    emsgTrackOutputs = new TrackOutput[2];
    int emsgTrackOutputCount = 0;
    if (additionalEmsgTrackOutput != null) {
      emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
    }
    if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
      emsgTrackOutputs[emsgTrackOutputCount++] =
          extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
    }
    emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);

    for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
      eventMessageTrackOutput.format(EMSG_FORMAT);
    }
  }
  if (cea608TrackOutputs == null) {
    cea608TrackOutputs = new TrackOutput[closedCaptionFormats.size()];
    for (int i = 0; i < cea608TrackOutputs.length; i++) {
      TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT);
      output.format(closedCaptionFormats.get(i));
      cea608TrackOutputs[i] = output;
    }
  }
}
 
Example 13
Source File: SingleSampleMediaChunk.java    From K-Sonic with MIT License 5 votes vote down vote up
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
  DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
  try {
    // Create and open the input.
    long length = dataSource.open(loadDataSpec);
    if (length != C.LENGTH_UNSET) {
      length += bytesLoaded;
    }
    ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, bytesLoaded, length);
    BaseMediaChunkOutput output = getOutput();
    output.setSampleOffsetUs(0);
    TrackOutput trackOutput = output.track(0, trackType);
    trackOutput.format(sampleFormat);
    // Load the sample data.
    int result = 0;
    while (result != C.RESULT_END_OF_INPUT) {
      bytesLoaded += result;
      result = trackOutput.sampleData(extractorInput, Integer.MAX_VALUE, true);
    }
    int sampleSize = bytesLoaded;
    trackOutput.sampleMetadata(startTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
  } finally {
    Util.closeQuietly(dataSource);
  }
  loadCompleted = true;
}
 
Example 14
Source File: SeiReader.java    From K-Sonic with MIT License 5 votes vote down vote up
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
  for (int i = 0; i < outputs.length; i++) {
    idGenerator.generateNewId();
    TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
    Format channelFormat = closedCaptionFormats.get(i);
    String channelMimeType = channelFormat.sampleMimeType;
    Assertions.checkArgument(MimeTypes.APPLICATION_CEA608.equals(channelMimeType)
        || MimeTypes.APPLICATION_CEA708.equals(channelMimeType),
        "Invalid closed caption mime type provided: " + channelMimeType);
    output.format(Format.createTextSampleFormat(idGenerator.getFormatId(), channelMimeType, null,
        Format.NO_VALUE, channelFormat.selectionFlags, channelFormat.language,
        channelFormat.accessibilityChannel, null));
    outputs[i] = output;
  }
}
 
Example 15
Source File: WebvttExtractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}
 
Example 16
Source File: WebvttExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}
 
Example 17
Source File: WebvttExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}
 
Example 18
Source File: WebvttExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}
 
Example 19
Source File: WebvttExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}
 
Example 20
Source File: WebvttExtractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@RequiresNonNull("output")
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
  TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
  trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
      Format.NO_VALUE, 0, language, null, subsampleOffsetUs));
  output.endTracks();
  return trackOutput;
}