mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Timestamp HEVC samples based on the first NALU's timestamp.
Issue: #893
This commit is contained in:
parent
c0a81e1138
commit
daa5835915
1 changed files with 9 additions and 7 deletions
|
|
@ -120,7 +120,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
// Indicate the start of the next NAL unit.
|
// Indicate the start of the next NAL unit.
|
||||||
int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset);
|
int nalUnitType = NalUnitUtil.getH265NalUnitType(dataArray, nalUnitOffset);
|
||||||
startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType);
|
startNalUnit(absolutePosition, bytesWrittenPastPosition, nalUnitType, pesTimeUs);
|
||||||
// Continue scanning the data.
|
// Continue scanning the data.
|
||||||
offset = nalUnitOffset + 3;
|
offset = nalUnitOffset + 3;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -136,7 +136,7 @@ import java.util.Collections;
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNalUnit(long position, int offset, int nalUnitType) {
|
private void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
||||||
if (!hasOutputFormat) {
|
if (!hasOutputFormat) {
|
||||||
vps.startNalUnit(nalUnitType);
|
vps.startNalUnit(nalUnitType);
|
||||||
sps.startNalUnit(nalUnitType);
|
sps.startNalUnit(nalUnitType);
|
||||||
|
|
@ -144,7 +144,7 @@ import java.util.Collections;
|
||||||
}
|
}
|
||||||
prefixSei.startNalUnit(nalUnitType);
|
prefixSei.startNalUnit(nalUnitType);
|
||||||
suffixSei.startNalUnit(nalUnitType);
|
suffixSei.startNalUnit(nalUnitType);
|
||||||
sampleReader.startNalUnit(position, offset, nalUnitType);
|
sampleReader.startNalUnit(position, offset, nalUnitType, pesTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
private void nalUnitData(byte[] dataArray, int offset, int limit) {
|
||||||
|
|
@ -161,7 +161,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
private void nalUnitEnd(long position, int offset, int discardPadding, long pesTimeUs) {
|
private void nalUnitEnd(long position, int offset, int discardPadding, long pesTimeUs) {
|
||||||
if (hasOutputFormat) {
|
if (hasOutputFormat) {
|
||||||
sampleReader.endNalUnit(position, offset, pesTimeUs);
|
sampleReader.endNalUnit(position, offset);
|
||||||
} else {
|
} else {
|
||||||
vps.endNalUnit(discardPadding);
|
vps.endNalUnit(discardPadding);
|
||||||
sps.endNalUnit(discardPadding);
|
sps.endNalUnit(discardPadding);
|
||||||
|
|
@ -377,6 +377,7 @@ import java.util.Collections;
|
||||||
private long nalUnitStartPosition;
|
private long nalUnitStartPosition;
|
||||||
private boolean nalUnitHasKeyframeData;
|
private boolean nalUnitHasKeyframeData;
|
||||||
private int nalUnitBytesRead;
|
private int nalUnitBytesRead;
|
||||||
|
private long nalUnitTimeUs;
|
||||||
private boolean lookingForFirstSliceFlag;
|
private boolean lookingForFirstSliceFlag;
|
||||||
private boolean firstSliceFlag;
|
private boolean firstSliceFlag;
|
||||||
|
|
||||||
|
|
@ -396,8 +397,9 @@ import java.util.Collections;
|
||||||
readingSample = false;
|
readingSample = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startNalUnit(long position, int offset, int nalUnitType) {
|
public void startNalUnit(long position, int offset, int nalUnitType, long pesTimeUs) {
|
||||||
firstSliceFlag = false;
|
firstSliceFlag = false;
|
||||||
|
nalUnitTimeUs = pesTimeUs;
|
||||||
nalUnitBytesRead = 0;
|
nalUnitBytesRead = 0;
|
||||||
nalUnitStartPosition = position;
|
nalUnitStartPosition = position;
|
||||||
// Flush the previous sample when reading a non-VCL NAL unit.
|
// Flush the previous sample when reading a non-VCL NAL unit.
|
||||||
|
|
@ -422,7 +424,7 @@ import java.util.Collections;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endNalUnit(long position, int offset, long timeUs) {
|
public void endNalUnit(long position, int offset) {
|
||||||
if (firstSliceFlag) {
|
if (firstSliceFlag) {
|
||||||
// If the NAL unit ending is the start of a new sample, output the previous one.
|
// If the NAL unit ending is the start of a new sample, output the previous one.
|
||||||
if (readingSample) {
|
if (readingSample) {
|
||||||
|
|
@ -430,7 +432,7 @@ import java.util.Collections;
|
||||||
outputSample(offset + nalUnitLength);
|
outputSample(offset + nalUnitLength);
|
||||||
}
|
}
|
||||||
samplePosition = nalUnitStartPosition;
|
samplePosition = nalUnitStartPosition;
|
||||||
sampleTimeUs = timeUs;
|
sampleTimeUs = nalUnitTimeUs;
|
||||||
readingSample = true;
|
readingSample = true;
|
||||||
sampleIsKeyframe = nalUnitHasKeyframeData;
|
sampleIsKeyframe = nalUnitHasKeyframeData;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue