In MPEG4Writer.cpp:
// The default MIN_MOOV_BOX_SIZE is set to 0.6% x 1MB / 2, // where 1MB is the common file size limit for MMS application. // The default MAX _MOOV_BOX_SIZE value is based on about 3 // minute video recording with a bit rate about 3 Mbps, because // statistics also show that most of the video captured are going // to be less than 3 minutes.
This is a bad guess about how MediaMuxer can be used. We record a maximum of 15 seconds of high definition video, and MIN_MOOV_BOX_SIZE is too small. Therefore, to make the file available, I have to rewrite the file to move the moov header before mdat and fix some offsets. Here is my code. This is not great. Error paths are not handled correctly, and they make assumptions about the order of the boxes.
public void fastPlay(String srcFile, String dstFile) { RandomAccessFile inFile = null; FileOutputStream outFile = null; try { inFile = new RandomAccessFile(new File(srcFile), "r"); outFile = new FileOutputStream(new File(dstFile)); int moovPos = 0; int mdatPos = 0; int moovSize = 0; int mdatSize = 0; byte[] boxSizeBuf = new byte[4]; byte[] pathBuf = new byte[4]; int boxSize; int dataSize; int bytesRead; int totalBytesRead = 0; int bytesWritten = 0;
mbert65
source share