MediaMuxer HEVC“没有编解码器配置”

时间:2016-03-31 19:58:00

标签: android mediacodec hevc

尝试将HEVC编码的视频复用到Samsung Galaxy S6上的MediaMuxer MPEG-4容器中。

MediaFormat(从MediaCodec获得):

{height=1080, width=1920, max_capacity=8847360, what=1869968451, mime=video/hevc, csd-0=java.nio.ByteArrayBuffer[position=0,limit=76,capacity=76], remained_resource=6773760}

csd-0 出现在那里,根据表格in the docs

,这对于H265 / hevc来说已经足够了

MediaMuxer根据此格式创建索引为0的视频轨道。在编写了一些示例然后调用mediaMuxer.stop()之后,抛出IllegalStateException并在logcat中显示以下内容:

E/MPEG4Writer: Missing codec specific data
D/MPEG4Writer: Video track stopping
D/MPEG4Writer: Video track source stopping
D/MPEG4Writer: Video track source stopped
I/MPEG4Writer: Received total/0-length (247/0) buffers and encoded 247 frames. - Audio
I/MPEG4Writer: Audio track drift time: 0 us
I/MPEG4Writer: Received total/0-length (173/0) buffers and encoded 173 frames. - Video
D/MPEG4Writer: Video track stopped
D/MPEG4Writer: Audio track stopping
D/MPEG4Writer: Audio track source stopping
D/MPEG4Writer: Audio track source stopped
D/MPEG4Writer: Audio track stopped
D/MPEG4Writer: Duration from tracks range is [5744606, 5764430] us
D/MPEG4Writer: Stopping writer thread
D/MPEG4Writer: 0 chunks are written in the last batch
D/MPEG4Writer: Writer thread stopped
E/MP4FileMuxer: finish: stop or release failed
java.lang.IllegalStateException: Failed to stop the muxer

生成的MP4文件无法播放。可能是什么问题?

1 个答案:

答案 0 :(得分:2)

所以,回答我自己的问题:似乎"视频/ hevc" MediaMuxer仅支持从Android 7.0 r1开始支持(即使使用N-preview-5也无法使用)。看起来MediaMuxer.addTrack()的文档已经更新以反映这一点。

相关的AOSP代码:

MPEG4Writer.cpp on N preview 5 - no HEVC support

MPEG4Writer.cpp on N r1 - HEVC bits and pieces everywhere

不幸的是,有些Marshmallow设备支持HEVC视频编码(例如Samsung Exynos),但是使用MediaMuxer将其转储到MP4文件中将无效,因此需要自定义解决方案。