为什么MediaCodec的影片为三星Galaxy S7乱码? [英] Why is video made with MediaCodec garbled for Samsung Galaxy S7?

查看:1965
本文介绍了为什么MediaCodec的影片为三星Galaxy S7乱码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过Surface - > MediaCodec - > MediaMuxer编码视频时,在三星Galaxy S7上进行测试时,我会得到一个非常奇怪的结果。对于其他测试的设备(具有棉花糖和HTC Desire的模拟器),视频正确出现,但在该设备上,视频是乱码。





使用MediaCodec将一系列图像保存为视频具有类似的视频输出,但是我看不到解决方案可以在这里应用,因为我使用Surface作为输入,并将颜色格式设置为COLOR_FormatSurface。



我也尝试解决每个 MediaCodec编码的视频在底部有绿色条纹和色度旋转的视频分辨率(已定在1280 x 720) up,但这并没有解决问题。 (参见 Nexus 7 2013 mediacodec视频编码器乱码输出



有人有什么建议,我可能会尝试使视频格式正确?



这是编码的日志的一部分:

  D / ViewRootImpl:#1 mView = android.widget.LinearLayout {1dc79f2 VE ..... ...... I。 0,0-0,0#102039c android:id / toast_layout_root} 
I / ACodec:[]现在未初始化
I / OMXClient:使用客户端OMX多路复用器。
我/ ACodec:[OMX.qcom.video.encoder.avc]现在加载
W / ACodec:[OMX.qcom.video.encoder.avc] storeMetaDataInBuffers(输出)失败w / err -1010
W / ACodec:不知道颜色格式0x7fa30c06 = 2141391878
W / ACodec:不知道颜色格式0x7fa30c04 = 2141391876
W / ACodec:不知道颜色格式0x7fa30c08 = 2141391880
W / ACodec:不知道颜色格式0x7fa30c07 = 2141391879
W / ACodec:不知道颜色格式0x7f000789 = 2130708361
D / ViewRootImpl:MSG_RESIZED_REPORT:ci = Rect(0,0 - 0, 0)vi = Rect(0,0 - 0,0)或= 1
I / ACodec:setupVideoEncoder成功
W / ACodec:不知道颜色格式0x7f000789 = 2130708361
I / ACodec :[OMX.qcom.video.encoder.avc] Now Loaded-> Idle
I / ACodec:[OMX.qcom.video.encoder.avc] Now Idle->执行
I / ACodec :[OMX.qcom.video.encoder.avc]现在执行
I / MPEG4Writer:setStartTimestampUs:0
I / MPEG4Writer:最早的轨道开始时间:0

第五个无法识别颜色似乎是COLOR_FormatSurface ...这是一个问题吗?



其他详细信息:




  • MIME:video / avc

  • 分辨率:1280 x 720

  • 帧速率:30

  • IFrame间隔:2

  • Bitrate:8847360


解决方案

p>每个Android文档 MediaCodec.createInputSurface()


Surface必须使用硬件加速的API渲染,例如
OpenGL ES。 lockCanvas(android.graphics.Rect)可能会失败或产生
意外结果


I必须错过(或忽略)在写代码。由于我正在使用lockCanvas()获取画布来绘制我的视频帧,所以代码破裂。我已经通过使用lockHardwareCanvas()如果API级别> = 23(因为它之前不可用,并且因为代码在API级别19上正常运行)快速解决了这个问题。长期以来(对于我和其他任何可能绊倒的人),我可能需要更多的OpenGL内容才能获得更为永久和稳定的解决方案。这是不值得去的路线,除非我找到一个设备的例子,这将不能用我的快速修复。


When I encode a video via Surface -> MediaCodec -> MediaMuxer, I get a very strange result when testing on the Samsung Galaxy S7. For other devices tested (emulator with Marshmallow and HTC Desire), the video comes out correctly, but on this device the video is garbled.

Using MediaCodec to save series of images as Video had a similar output of video, but I don't see how the solution could apply here because I am using a Surface as input and set the color format to COLOR_FormatSurface.

I also tried messing with the video resolution (settled on 1280 x 720) per MediaCodec Encoded video has green bar at bottom and chrominance screwed up, but that didn't solve the problem either. (c.f. Nexus 7 2013 mediacodec video encoder garbled output)

Does anyone have suggestions for what I might try to get the video formatted correctly?

Here is part of the log from the encoding:

D/ViewRootImpl: #1 mView = android.widget.LinearLayout{1dc79f2 V.E...... ......I. 0,0-0,0 #102039c android:id/toast_layout_root}
I/ACodec:  [] Now uninitialized
I/OMXClient: Using client-side OMX mux.
I/ACodec: [OMX.qcom.video.encoder.avc] Now Loaded
W/ACodec: [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -1010
W/ACodec: do not know color format 0x7fa30c06 = 2141391878
W/ACodec: do not know color format 0x7fa30c04 = 2141391876
W/ACodec: do not know color format 0x7fa30c08 = 2141391880
W/ACodec: do not know color format 0x7fa30c07 = 2141391879
W/ACodec: do not know color format 0x7f000789 = 2130708361
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
I/ACodec: setupVideoEncoder succeeded
W/ACodec: do not know color format 0x7f000789 = 2130708361
I/ACodec: [OMX.qcom.video.encoder.avc] Now Loaded->Idle
I/ACodec: [OMX.qcom.video.encoder.avc] Now Idle->Executing
I/ACodec: [OMX.qcom.video.encoder.avc] Now Executing
I/MPEG4Writer: setStartTimestampUs: 0
I/MPEG4Writer: Earliest track starting time: 0

The 5th unrecognized color seems to be COLOR_FormatSurface... Is that a problem?

Other details:

  • MIME: video/avc
  • Resolution: 1280 x 720
  • Frame rate: 30
  • IFrame interval: 2
  • Bitrate: 8847360

解决方案

Per Android Docs for MediaCodec.createInputSurface():

The Surface must be rendered with a hardware-accelerated API, such as OpenGL ES. lockCanvas(android.graphics.Rect) may fail or produce unexpected results.

I must have missed (or ignored) that in writing the code. Since I was using lockCanvas() to get a canvas upon which to draw my video frames, the code broke. I have put a quick fix on the problem by using lockHardwareCanvas() if API level >= 23 (since it is unavailable prior to that and since the code ran fine on API level 19).

Long term however (for me and anyone else who might stumble across this), I may have to get into more OpenGL stuff for a more permanent and stable solution. It's not worth going that route though unless I find an example of a device which will not work with my quick fix.

这篇关于为什么MediaCodec的影片为三星Galaxy S7乱码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆