尝试将 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 文件无法播放。可能是什么问题?
最佳答案
因此,回答我自己的问题:似乎“video/hevc”仅受从 Android 7.0 r1 开始的 MediaMuxer 支持(即使使用 N-preview-5 也无法使用)。看起来像 MediaMuxer.addTrack() 的文档已更新以反射(reflect)这一点。
相关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 文件中将不起作用,因此需要自定义解决方案。
关于android - MediaMuxer HEVC "no codec config",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342589/