Skip writing 0 sized samples in Mp4Muxer
The existing logic to drop (actually fail on) 0 sized samples seems no op if if 2 out of 10 samples are of size 0. Checked same scenario with MediaMuxer where 1. If input file has 300 samples. 2. Make every 5th sample as an empty byte buffer. 3. Output file is generated without error. 4. Output file has 240 samples. 5. Exoplayer is able to play output file (blurry). The new change is in line with MediaMuxer behaviour. PiperOrigin-RevId: 528798046
This commit is contained in:
parent
b4b7e0e7c0
commit
d5fc9e9627
@ -270,12 +270,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
// Calculate the additional space required.
|
||||
long bytesNeededInMdat = 0L;
|
||||
for (Pair<BufferInfo, ByteBuffer> sample : track.pendingSamples) {
|
||||
bytesNeededInMdat += sample.second.limit();
|
||||
bytesNeededInMdat += sample.second.remaining();
|
||||
}
|
||||
|
||||
// Drop all zero-length samples.
|
||||
checkState(bytesNeededInMdat > 0);
|
||||
|
||||
// If the required number of bytes doesn't fit in the gap between the actual data and the moov
|
||||
// box, extend the file and write out the moov box to the end again.
|
||||
if (mdatDataEnd + bytesNeededInMdat >= mdatEnd) {
|
||||
@ -366,7 +363,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
pendingSamples = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void writeSampleData(ByteBuffer byteBuf, BufferInfo bufferInfo) throws IOException {
|
||||
public void writeSampleData(ByteBuffer byteBuffer, BufferInfo bufferInfo) throws IOException {
|
||||
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) > 0) {
|
||||
hadKeyframe = true;
|
||||
}
|
||||
@ -379,9 +376,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
return;
|
||||
}
|
||||
|
||||
pendingSamples.addLast(Pair.create(bufferInfo, byteBuf));
|
||||
// Skip empty samples.
|
||||
// TODO(b/279931840): Confirm whether muxer should throw when writing empty samples.
|
||||
if (byteBuffer.remaining() > 0) {
|
||||
pendingSamples.addLast(Pair.create(bufferInfo, byteBuffer));
|
||||
doInterleave();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int videoUnitTimebase() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user