Commit 497c51b9 by sheenachhabra Committed by Marc Baechinger

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
parent adb99da8
......@@ -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,8 +376,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
return;
}
pendingSamples.addLast(Pair.create(bufferInfo, byteBuf));
doInterleave();
// 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment