imalimin / HardwareVideoCodec

HardwareVideoCodec is an efficient video recording library for Android. Supports software and hardware encode. With it, you can record a video at any resolution, no need to care about camera resolution. Everything is so easy.
GNU General Public License v2.0
452 stars 122 forks source link

部分机型写入muxer 写入video 的时候,presentationTimeUs混乱 #20

Open chezi008 opened 4 years ago

chezi008 commented 4 years ago
2019-11-29 15:48:43.747 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(13, 521541): 259
2019-11-29 15:48:43.768 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(13, 544217): 255
2019-11-29 15:48:43.786 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(14, 566893): 263
2019-11-29 15:48:43.811 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(14, 589569): 270
2019-11-29 15:48:43.828 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(15, 612244): 263
2019-11-29 15:48:43.852 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(16, 634920): 290
2019-11-29 15:48:43.886 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(17, 657596): 247
2019-11-29 15:48:43.907 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(17, 680272): 260
2019-11-29 15:48:43.940 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(18, 702947): 264
2019-11-29 15:48:43.958 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(19, 725623): 249
2019-11-29 15:48:43.979 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(19, 748299): 252
2019-11-29 15:48:43.982 9147-9356/com.lmy.sample E/MuxerImpl: writeVideoSample(20, 598474): 8944
2019-11-29 15:48:43.982 9147-9356/com.lmy.sample E/MediaAdapter: pushBuffer called before start
2019-11-29 15:48:43.997 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(20, 770975): 250
2019-11-29 15:48:43.998 9147-9356/com.lmy.sample V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@148ed9a
2019-11-29 15:48:43.998 9147-9356/com.lmy.sample V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@38e46cb
2019-11-29 15:48:44.003 9147-9356/com.lmy.sample V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@2433dc1
2019-11-29 15:48:44.003 9147-9356/com.lmy.sample V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@7b84966
2019-11-29 15:48:44.018 9147-9355/com.lmy.sample E/MuxerImpl: writeAudioSample(21, 793650): 248
2019-11-29 15:48:44.019 9147-9356/com.lmy.sample W/System.err: java.lang.IllegalStateException: writeSampleData returned an error
2019-11-29 15:48:44.019 9147-9356/com.lmy.sample W/System.err:     at android.media.MediaMuxer.nativeWriteSampleData(Native Method)
2019-11-29 15:48:44.019 9147-9356/com.lmy.sample W/System.err:     at android.media.MediaMuxer.writeSampleData(MediaMuxer.java:473)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at com.lmy.codec.muxer.impl.MuxerImpl.writeSample(MuxerImpl.kt:150)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at com.lmy.codec.muxer.impl.MuxerImpl.access$writeSample(MuxerImpl.kt:27)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at com.lmy.codec.muxer.impl.MuxerImpl$writeVideoSample$2.run(MuxerImpl.kt:132)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at com.lmy.codec.pipeline.impl.EventPipeline$1.handleMessage(EventPipeline.kt:36)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at android.os.Looper.loop(Looper.java:165)
2019-11-29 15:48:44.020 9147-9356/com.lmy.sample W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)

解决方案:使用自己统计的presentationTimeUs

mBufferInfo.presentationTimeUs = pTimer.presentationTimeUs/1000
chezi008 commented 4 years ago

VideoEncoderImpl 类中