MediaMuxer HEVC "no codec config"

MediaMuxer HEVC "no codec config"

正在尝试将 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出现在那里,根据tablein the docs[=,H265/hevc就够了16=]

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 文件无法播放。可能是什么问题?

因此,回答我自己的问题:似乎 "video/hevc" 仅受从 Android 7.0 r1 开始的 MediaMuxer 支持(即使使用 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

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