MediaRecord录制的视频比预期偏小
问题描述:
在使用MediaRecorder进行录制视频,设置录制大小后,自动结束录制后,查看保存的视频发现大小比设置的要小:mMediaRecorder.setMaxFileSize(30*1024*1024L);//30M
原因分析:
这个问题应该说是设计如此,在frameworks/av/media/libstagefright/MPEG4Writer.cpp:bool MPEG4Writer::exceedsFileSizeLimit() {
// No limit
if (mMaxFileSizeLimitBytes == 0) {
return false;
}
int64_t nTotalBytesEstimate = static_cast<int64_t>(mInMemoryCacheSize);
for (List<Track *>::iterator it = mTracks.begin();
it != mTracks.end(); ++it) {
nTotalBytesEstimate += (*it)->getEstimatedTrackSizeBytes();
}
notifyEstimateSize(nTotalBytesEstimate); // add for mtk
if (!mStreamableFile) {
// Add 1024 bytes as error tolerance
return nTotalBytesEstimate + 1024 >= mMaxFileSizeLimitBytes;
}
// Be conservative in the estimate: do not exceed 95% of
// the target file limit. For small target file size limit, though,
// this will not help.
return (nTotalBytesEstimate >= (95 * mMaxFileSizeLimitBytes) / 100);
}
在录制视频的大小达到了设置大小的95%后就会触发停止录制