Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize DefaultExtractorsFactory sniffing order #6410

Closed
lsgfly opened this issue Sep 9, 2019 · 2 comments
Closed

Optimize DefaultExtractorsFactory sniffing order #6410

lsgfly opened this issue Sep 9, 2019 · 2 comments
Assignees

Comments

@lsgfly
Copy link

lsgfly commented Sep 9, 2019

when we select extractor, we makes a pass through all of the available extractor util we find the
correct extractor. I find the sniff of MatroskaExtractor will cost 25ms.
80% of our videos are in MP4 format.
Can I put the Mp4Extractor as the first place.

public Extractor selectExtractor(ExtractorInput input, Uri uri)
        throws IOException, InterruptedException {
      for (Extractor extractor : extractors) {
        try {
          if (extractor.sniff(input)) {
            this.extractor = extractor;
            break;
          }
        } catch (EOFException e) {
          // Do nothing.
        } finally {
          input.resetPeekPosition();
        }
      }
}
  public synchronized Extractor[] createExtractors() {
    Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 12 : 13];
    extractors[0] = new MatroskaExtractor(matroskaFlags);
    extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
    extractors[2] = new  Mp4Extractor(mp4Flags);
    extractors[3] = new Mp3Extractor(mp3Flags);
    extractors[4] = new AdtsExtractor();
    extractors[5] = new Ac3Extractor();
    extractors[6] = new TsExtractor(tsMode, tsFlags);
    extractors[7] = new FlvExtractor();
    extractors[8] = new OggExtractor();
    extractors[9] = new PsExtractor();
    extractors[10] = new WavExtractor();
    extractors[11] = new AmrExtractor();
    if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
      try {
        extractors[12] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
      } catch (Exception e) {
        // Should never happen.
        throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
      }
    }
    return extractors;
  }
@ojw28
Copy link
Contributor

ojw28 commented Sep 9, 2019

There is nothing stopping you from doing this yourself by injecting your own ExtractorsFactory when building a ProgressiveMediaSource (using this API).

As mentioned on #6325 (comment), we should also revisit the sniffing order:

At some point we should also revisit the sniffing order. In particular, I don't think we've ever looked at how much data each extractor sniffs, on average, before establishing the media is not in its own format. If there are extractors that have to sniff a lot of data to do this, we should consider whether it's possible to push them down in the order without increasing the chances of false positives.

Let's use this issue to track doing that. @andrewlewis - Please reassign within your team as appropriate.

@ojw28 ojw28 changed the title Can I put the Mp4Extractor as the first place. Optimize DefaultExtractorsFactory sniffing order Sep 9, 2019
@andrewlewis andrewlewis assigned kim-vde and unassigned andrewlewis Sep 22, 2019
ojw28 pushed a commit that referenced this issue Apr 8, 2020
Issue: #6410
PiperOrigin-RevId: 305436352
@ojw28 ojw28 closed this as completed Jun 12, 2020
@ojw28
Copy link
Contributor

ojw28 commented Jun 12, 2020

In addition to the commit referenced above, further improvements were made in 7df9938 and 1f17756.

@google google locked and limited conversation to collaborators Aug 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants