Java Code Examples for com.google.android.exoplayer2.Format#copyWithFrameRate()
The following examples show how to use
com.google.android.exoplayer2.Format#copyWithFrameRate() .
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: MetadataUtil.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Returns a {@link Format} that is the same as the input format but includes information from the * specified sources of metadata. */ public static Format getFormatWithMetadata( int trackType, Format format, @Nullable Metadata udtaMetadata, @Nullable Metadata mdtaMetadata, GaplessInfoHolder gaplessInfoHolder) { if (trackType == C.TRACK_TYPE_AUDIO) { if (gaplessInfoHolder.hasGaplessInfo()) { format = format.copyWithGaplessInfo( gaplessInfoHolder.encoderDelay, gaplessInfoHolder.encoderPadding); } // We assume all udta metadata is associated with the audio track. if (udtaMetadata != null) { format = format.copyWithMetadata(udtaMetadata); } } else if (trackType == C.TRACK_TYPE_VIDEO && mdtaMetadata != null) { // Populate only metadata keys that are known to be specific to video. for (int i = 0; i < mdtaMetadata.length(); i++) { Metadata.Entry entry = mdtaMetadata.get(i); if (entry instanceof MdtaMetadataEntry) { MdtaMetadataEntry mdtaMetadataEntry = (MdtaMetadataEntry) entry; if (MDTA_KEY_ANDROID_CAPTURE_FPS.equals(mdtaMetadataEntry.key) && mdtaMetadataEntry.typeIndicator == MDTA_TYPE_INDICATOR_FLOAT) { try { float fps = ByteBuffer.wrap(mdtaMetadataEntry.value).asFloatBuffer().get(); format = format.copyWithFrameRate(fps); format = format.copyWithMetadata(new Metadata(mdtaMetadataEntry)); } catch (NumberFormatException e) { Log.w(TAG, "Ignoring invalid framerate"); } } } } } return format; }
Example 2
Source File: MetadataUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Returns a {@link Format} that is the same as the input format but includes information from the * specified sources of metadata. */ public static Format getFormatWithMetadata( int trackType, Format format, @Nullable Metadata udtaMetadata, @Nullable Metadata mdtaMetadata, GaplessInfoHolder gaplessInfoHolder) { if (trackType == C.TRACK_TYPE_AUDIO) { if (gaplessInfoHolder.hasGaplessInfo()) { format = format.copyWithGaplessInfo( gaplessInfoHolder.encoderDelay, gaplessInfoHolder.encoderPadding); } // We assume all udta metadata is associated with the audio track. if (udtaMetadata != null) { format = format.copyWithMetadata(udtaMetadata); } } else if (trackType == C.TRACK_TYPE_VIDEO && mdtaMetadata != null) { // Populate only metadata keys that are known to be specific to video. for (int i = 0; i < mdtaMetadata.length(); i++) { Metadata.Entry entry = mdtaMetadata.get(i); if (entry instanceof MdtaMetadataEntry) { MdtaMetadataEntry mdtaMetadataEntry = (MdtaMetadataEntry) entry; if (MDTA_KEY_ANDROID_CAPTURE_FPS.equals(mdtaMetadataEntry.key) && mdtaMetadataEntry.typeIndicator == MDTA_TYPE_INDICATOR_FLOAT) { try { float fps = ByteBuffer.wrap(mdtaMetadataEntry.value).asFloatBuffer().get(); format = format.copyWithFrameRate(fps); format = format.copyWithMetadata(new Metadata(mdtaMetadataEntry)); } catch (NumberFormatException e) { Log.w(TAG, "Ignoring invalid framerate"); } } } } } return format; }
Example 3
Source File: MetadataUtil.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Returns a {@link Format} that is the same as the input format but includes information from the * specified sources of metadata. */ public static Format getFormatWithMetadata( int trackType, Format format, @Nullable Metadata udtaMetadata, @Nullable Metadata mdtaMetadata, GaplessInfoHolder gaplessInfoHolder) { if (trackType == C.TRACK_TYPE_AUDIO) { if (gaplessInfoHolder.hasGaplessInfo()) { format = format.copyWithGaplessInfo( gaplessInfoHolder.encoderDelay, gaplessInfoHolder.encoderPadding); } // We assume all udta metadata is associated with the audio track. if (udtaMetadata != null) { format = format.copyWithMetadata(udtaMetadata); } } else if (trackType == C.TRACK_TYPE_VIDEO && mdtaMetadata != null) { // Populate only metadata keys that are known to be specific to video. for (int i = 0; i < mdtaMetadata.length(); i++) { Metadata.Entry entry = mdtaMetadata.get(i); if (entry instanceof MdtaMetadataEntry) { MdtaMetadataEntry mdtaMetadataEntry = (MdtaMetadataEntry) entry; if (MDTA_KEY_ANDROID_CAPTURE_FPS.equals(mdtaMetadataEntry.key) && mdtaMetadataEntry.typeIndicator == MDTA_TYPE_INDICATOR_FLOAT) { try { float fps = ByteBuffer.wrap(mdtaMetadataEntry.value).asFloatBuffer().get(); format = format.copyWithFrameRate(fps); format = format.copyWithMetadata(new Metadata(mdtaMetadataEntry)); } catch (NumberFormatException e) { Log.w(TAG, "Ignoring invalid framerate"); } } } } } return format; }
Example 4
Source File: Mp4Extractor.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Updates the stored track metadata to reflect the contents of the specified moov atom. */ private void processMoovAtom(ContainerAtom moov) throws ParserException { int firstVideoTrackIndex = C.INDEX_UNSET; long durationUs = C.TIME_UNSET; List<Mp4Track> tracks = new ArrayList<>(); // Process metadata. Metadata udtaMetadata = null; GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder(); Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta); if (udta != null) { udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime); if (udtaMetadata != null) { gaplessInfoHolder.setFromMetadata(udtaMetadata); } } Metadata mdtaMetadata = null; ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta); if (meta != null) { mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta); } boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0; ArrayList<TrackSampleTable> trackSampleTables = getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists); int trackCount = trackSampleTables.size(); for (int i = 0; i < trackCount; i++) { TrackSampleTable trackSampleTable = trackSampleTables.get(i); Track track = trackSampleTable.track; long trackDurationUs = track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs; durationUs = Math.max(durationUs, trackDurationUs); Mp4Track mp4Track = new Mp4Track(track, trackSampleTable, extractorOutput.track(i, track.type)); // Each sample has up to three bytes of overhead for the start code that replaces its length. // Allow ten source samples per output sample, like the platform extractor. int maxInputSize = trackSampleTable.maximumSize + 3 * 10; Format format = track.format.copyWithMaxInputSize(maxInputSize); if (track.type == C.TRACK_TYPE_VIDEO && trackDurationUs > 0 && trackSampleTable.sampleCount > 1) { float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f); format = format.copyWithFrameRate(frameRate); } format = MetadataUtil.getFormatWithMetadata( track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder); mp4Track.trackOutput.format(format); if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) { firstVideoTrackIndex = tracks.size(); } tracks.add(mp4Track); } this.firstVideoTrackIndex = firstVideoTrackIndex; this.durationUs = durationUs; this.tracks = tracks.toArray(new Mp4Track[0]); accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks); extractorOutput.endTracks(); extractorOutput.seekMap(this); }
Example 5
Source File: Mp4Extractor.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Updates the stored track metadata to reflect the contents of the specified moov atom. */ private void processMoovAtom(ContainerAtom moov) throws ParserException { int firstVideoTrackIndex = C.INDEX_UNSET; long durationUs = C.TIME_UNSET; List<Mp4Track> tracks = new ArrayList<>(); // Process metadata. Metadata udtaMetadata = null; GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder(); Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta); if (udta != null) { udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime); if (udtaMetadata != null) { gaplessInfoHolder.setFromMetadata(udtaMetadata); } } Metadata mdtaMetadata = null; Atom.ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta); if (meta != null) { mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta); } boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0; ArrayList<TrackSampleTable> trackSampleTables = getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists); int trackCount = trackSampleTables.size(); for (int i = 0; i < trackCount; i++) { TrackSampleTable trackSampleTable = trackSampleTables.get(i); Track track = trackSampleTable.track; long trackDurationUs = track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs; durationUs = Math.max(durationUs, trackDurationUs); Mp4Track mp4Track = new Mp4Track(track, trackSampleTable, extractorOutput.track(i, track.type)); // Each sample has up to three bytes of overhead for the start code that replaces its length. // Allow ten source samples per output sample, like the platform extractor. int maxInputSize = trackSampleTable.maximumSize + 3 * 10; Format format = track.format.copyWithMaxInputSize(maxInputSize); if (track.type == C.TRACK_TYPE_VIDEO && trackDurationUs > 0 && trackSampleTable.sampleCount > 1) { float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f); format = format.copyWithFrameRate(frameRate); } format = MetadataUtil.getFormatWithMetadata( track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder); mp4Track.trackOutput.format(format); if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) { firstVideoTrackIndex = tracks.size(); } tracks.add(mp4Track); } this.firstVideoTrackIndex = firstVideoTrackIndex; this.durationUs = durationUs; this.tracks = tracks.toArray(new Mp4Track[0]); accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks); extractorOutput.endTracks(); extractorOutput.seekMap(this); }
Example 6
Source File: Mp4Extractor.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Updates the stored track metadata to reflect the contents of the specified moov atom. */ private void processMoovAtom(ContainerAtom moov) throws ParserException { int firstVideoTrackIndex = C.INDEX_UNSET; long durationUs = C.TIME_UNSET; List<Mp4Track> tracks = new ArrayList<>(); // Process metadata. Metadata udtaMetadata = null; GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder(); Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta); if (udta != null) { udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime); if (udtaMetadata != null) { gaplessInfoHolder.setFromMetadata(udtaMetadata); } } Metadata mdtaMetadata = null; Atom.ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta); if (meta != null) { mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta); } boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0; ArrayList<TrackSampleTable> trackSampleTables = getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists); int trackCount = trackSampleTables.size(); for (int i = 0; i < trackCount; i++) { TrackSampleTable trackSampleTable = trackSampleTables.get(i); Track track = trackSampleTable.track; long trackDurationUs = track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs; durationUs = Math.max(durationUs, trackDurationUs); Mp4Track mp4Track = new Mp4Track(track, trackSampleTable, extractorOutput.track(i, track.type)); // Each sample has up to three bytes of overhead for the start code that replaces its length. // Allow ten source samples per output sample, like the platform extractor. int maxInputSize = trackSampleTable.maximumSize + 3 * 10; Format format = track.format.copyWithMaxInputSize(maxInputSize); if (track.type == C.TRACK_TYPE_VIDEO && trackDurationUs > 0 && trackSampleTable.sampleCount > 1) { float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f); format = format.copyWithFrameRate(frameRate); } format = MetadataUtil.getFormatWithMetadata( track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder); mp4Track.trackOutput.format(format); if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) { firstVideoTrackIndex = tracks.size(); } tracks.add(mp4Track); } this.firstVideoTrackIndex = firstVideoTrackIndex; this.durationUs = durationUs; this.tracks = tracks.toArray(new Mp4Track[0]); accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks); extractorOutput.endTracks(); extractorOutput.seekMap(this); }