Closed tuananhdtu closed 3 years ago
this is video decode error. check input mediacodec h264 data .
Thank for reply But i think error in video encoder.
I debug in this function
fun drainEncoder(data: ByteArray): Int { var length = 0 val encoderOutputBuffers = mEncoder?.outputBuffers ?: return 0 val status = mEncoder?.dequeueOutputBuffer(mBufferInfo, 10000) ?: return 0 if (status >= 0) { val encodeData = encoderOutputBuffers[status] // config data sps/pps if ((mBufferInfo.flags and MediaCodec.BUFFER_FLAG_CODECCONFIG) != 0) { // The codec config data was pulled out when we got the // INFO_OUTPUT_FORMAT_CHANGED status. The MediaMuxer won't // accept // a single big blob -- it wants separate csd-0/csd-1 chunks -- // so simply saving this off won't work. if (mBufferInfo.size != 0) { encodeData.position(mBufferInfo.offset) encodeData.limit(mBufferInfo.offset + mBufferInfo.size) length = mBufferInfo.size encodeData.get(data, 0, length) mBufferInfo.size = 0 } } Log.e("mBufferInfo", "mBufferInfo.presentationTimeUs " + mBufferInfo.presentationTimeUs) Log.e("mBufferInfo", "mLastPresentationTimeUs " + mLastPresentationTimeUs) if (mBufferInfo.presentationTimeUs >= mLastPresentationTimeUs) { if (mBufferInfo.size != 0) { encodeData.position(mBufferInfo.offset) encodeData.limit(mBufferInfo.offset + mBufferInfo.size) mLastPresentationTimeUs = mBufferInfo.presentationTimeUs length = mBufferInfo.size encodeData.get(data, 0, mBufferInfo.size) val type = (data[4] and 0x1F).toInt() if (type == SPS) { // 某些手机I帧前面会附带上SPS和PPS,剥离掉SPS和PPS,仅使用I帧 val idrFrame = splitIDRFrame(data) System.arraycopy(idrFrame, 0, data, 0, idrFrame.size) length = idrFrame.size } } } mEncoder?.releaseOutputBuffer(status, false) if ((mBufferInfo.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { // end of stream, break encode data return -1 } } return length }
With samsung j410F: (device error) 2021-01-13 18:59:32.498 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 0 2021-01-13 18:59:32.499 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 0 2021-01-13 18:59:32.527 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 231965691750 2021-01-13 18:59:32.527 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 0 2021-01-13 18:59:35.601 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 0 2021-01-13 18:59:35.601 23335-23367/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 231965691750
With samsung j2 pro: (device not error) 2021-01-13 18:55:12.181 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 0 2021-01-13 18:55:12.181 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 0 2021-01-13 18:55:12.254 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 53000 2021-01-13 18:55:12.254 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 0 2021-01-13 18:55:12.371 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 119000 2021-01-13 18:55:12.371 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 53000 2021-01-13 18:55:12.492 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 176000 2021-01-13 18:55:12.492 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 119000 2021-01-13 18:55:12.609 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 251000 2021-01-13 18:55:12.609 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 176000 2021-01-13 18:55:12.752 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 300000 2021-01-13 18:55:12.753 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 251000 2021-01-13 18:55:12.856 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mBufferInfo.presentationTimeUs 321000 2021-01-13 18:55:12.857 8588-13073/com.trinity.sample E/mBufferInfo: [, , 0]:mLastPresentationTimeUs 300000
@wlanjie you can see log
samsung j410f have output mp4 only first frame
You can help me your solution
Your first timestamp 231965691750, when the following timestamp is less than the previous time, it will not be able to decode
why samsung j410f return first timestamp 231965691750? you can explain it?
in class MediaCodecSurfaceEncoder method onStart() you can set this line is bold, the error is fix
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE) mEncoder?.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) mInputSurface = mEncoder?.createInputSurface() if (SDK_INT >= 23 ) { mInputSurface?.let { mEncoder?.setOutputSurface(it) } } mEncoder?.start()
Help me