mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Derive Format.frameRate for MP4 videos
Issue: #5598 PiperOrigin-RevId: 237067179
This commit is contained in:
parent
f35dbeb567
commit
851134ec16
5 changed files with 14 additions and 8 deletions
|
|
@ -401,21 +401,27 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
||||||
for (int i = 0; i < trackCount; i++) {
|
for (int i = 0; i < trackCount; i++) {
|
||||||
TrackSampleTable trackSampleTable = trackSampleTables.get(i);
|
TrackSampleTable trackSampleTable = trackSampleTables.get(i);
|
||||||
Track track = trackSampleTable.track;
|
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,
|
Mp4Track mp4Track = new Mp4Track(track, trackSampleTable,
|
||||||
extractorOutput.track(i, track.type));
|
extractorOutput.track(i, track.type));
|
||||||
|
|
||||||
// Each sample has up to three bytes of overhead for the start code that replaces its length.
|
// 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.
|
// Allow ten source samples per output sample, like the platform extractor.
|
||||||
int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
|
int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
|
||||||
Format format = track.format.copyWithMaxInputSize(maxInputSize);
|
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 =
|
format =
|
||||||
MetadataUtil.getFormatWithMetadata(
|
MetadataUtil.getFormatWithMetadata(
|
||||||
track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder);
|
track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder);
|
||||||
mp4Track.trackOutput.format(format);
|
mp4Track.trackOutput.format(format);
|
||||||
|
|
||||||
durationUs =
|
|
||||||
Math.max(
|
|
||||||
durationUs,
|
|
||||||
track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs);
|
|
||||||
if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
|
if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
|
||||||
firstVideoTrackIndex = tracks.size();
|
firstVideoTrackIndex = tracks.size();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ track 0:
|
||||||
maxInputSize = 36722
|
maxInputSize = 36722
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
frameRate = -1.0
|
frameRate = 29.970028
|
||||||
rotationDegrees = 0
|
rotationDegrees = 0
|
||||||
pixelWidthHeightRatio = 1.0
|
pixelWidthHeightRatio = 1.0
|
||||||
channelCount = -1
|
channelCount = -1
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ track 0:
|
||||||
maxInputSize = 36722
|
maxInputSize = 36722
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
frameRate = -1.0
|
frameRate = 29.970028
|
||||||
rotationDegrees = 0
|
rotationDegrees = 0
|
||||||
pixelWidthHeightRatio = 1.0
|
pixelWidthHeightRatio = 1.0
|
||||||
channelCount = -1
|
channelCount = -1
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ track 0:
|
||||||
maxInputSize = 36722
|
maxInputSize = 36722
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
frameRate = -1.0
|
frameRate = 29.970028
|
||||||
rotationDegrees = 0
|
rotationDegrees = 0
|
||||||
pixelWidthHeightRatio = 1.0
|
pixelWidthHeightRatio = 1.0
|
||||||
channelCount = -1
|
channelCount = -1
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ track 0:
|
||||||
maxInputSize = 36722
|
maxInputSize = 36722
|
||||||
width = 1080
|
width = 1080
|
||||||
height = 720
|
height = 720
|
||||||
frameRate = -1.0
|
frameRate = 29.970028
|
||||||
rotationDegrees = 0
|
rotationDegrees = 0
|
||||||
pixelWidthHeightRatio = 1.0
|
pixelWidthHeightRatio = 1.0
|
||||||
channelCount = -1
|
channelCount = -1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue