Fix Avc Seek

This commit is contained in:
Dustin 2022-01-22 08:03:49 -07:00
parent 4c76bf1a9d
commit 5ebaafde6e
3 changed files with 17 additions and 6 deletions

View File

@ -21,7 +21,7 @@ public class AvcAviTrack extends AviTrack{
private NalUnitUtil.SpsData spsData;
//The frame as a calculated from the picCount
private int picFrame;
private int lastPicFrame;
private int lastPicCount;
//Largest picFrame, used when we hit an I frame
private int maxPicFrame =-1;
private int maxPicCount;
@ -56,7 +56,7 @@ public class AvcAviTrack extends AviTrack{
}
private void processIdr() {
lastPicFrame = 0;
lastPicCount = 0;
picFrame = maxPicFrame + 1;
}
@ -97,6 +97,13 @@ public class AvcAviTrack extends AviTrack{
return picFrame;
}
@Override
void seekFrame(int frame) {
super.seekFrame(frame);
this.picFrame = frame;
lastPicCount = 0;
}
int getPicOrderCountLsb(byte[] peek) {
if (peek[3] != 1) {
return 0;
@ -136,15 +143,15 @@ public class AvcAviTrack extends AviTrack{
case 2:
case 3:
case 4: {
final int myPicCount = getPicOrderCountLsb(peek);
int delta = myPicCount - lastPicFrame;
final int picCount = getPicOrderCountLsb(peek);
int delta = picCount - lastPicCount;
if (delta < negHalf) {
delta += maxPicCount;
} else if (delta > posHalf) {
delta -= maxPicCount;
}
picFrame += delta / 2;
lastPicFrame = myPicCount;
lastPicCount = picCount;
if (maxPicFrame < picFrame) {
maxPicFrame = picFrame;
}

View File

@ -63,7 +63,7 @@ public class AviSeekMap implements SeekMap {
public void setFrames(final long position, final long timeUs, final SparseArray<AviTrack> idTrackMap) {
final int seekFrameIndex = getSeekFrameIndex(timeUs);
videoTrack.frame = seekFrameIndex * seekIndexFactor;
videoTrack.seekFrame(seekFrameIndex * seekIndexFactor);
for (int i=0;i<audioIdMap.size();i++) {
final int audioId = audioIdMap.keyAt(i);
final int[] video2AudioFrameMap = audioIdMap.get(audioId);

View File

@ -95,6 +95,10 @@ public class AviTrack {
return frame;
}
void seekFrame(int frame) {
this.frame = frame;
}
public boolean newChunk(int tag, int size, ExtractorInput input) throws IOException {
final int remaining = size - trackOutput.sampleData(input, size, false);
if (remaining == 0) {