Android 7.0 MediaCodec编码错误的颜色格式

时间:2016-09-01 09:49:07

标签: video encoding mediacodec android-7.0-nougat

我使用下面的代码来编码来自video/avc

Surface格式
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);
// ...
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
        MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
// ...

并使用MediaMuxer写入mp4文件。

但输出无法与MediaPlayer一起播放,经过一番分析后,我发现像素格式(颜色格式)非常奇怪,请参阅ffmpeg下面的输出。

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffeba000000] decoding for stream 0 failed
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'VID20160901_112308_1180449004.mp4':
Metadata:
  major_brand     : mp42
  minor_version   : 0
  compatible_brands: isommp42
  creation_time   : 2016-09-01 03:23:15
  com.android.version: 7.0
Duration: 00:00:06.74, start: 0.000000, bitrate: 1449 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 640x1136, 0 kb/s, SAR 1:1 DAR 40:71, 0.01 fps, 90k tbr, 90k tbn, 180k tbc (default)
Metadata:
  creation_time   : 2016-09-01 03:23:15
  handler_name    : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
Metadata:
  creation_time   : 2016-09-01 03:23:15
  handler_name    : SoundHandle

视频流没有bit rateframe rate非常低,pix格式为yuv420p(tv, bt470bg/bt470bg/smpte170m),谁可以解释这种颜色格式?

相同的编码代码在Android 7.0之前工作,以下是Android 6.0的可行输出。

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'files/video/VID20160901_171106_156925259.mp4':
Metadata:
  major_brand     : mp42
  minor_version   : 0
  compatible_brands: isommp42
  creation_time   : 2016-09-01 09:11:11
  com.android.version: 6.0.1
Duration: 00:00:04.16, start: 0.000000, bitrate: 1498 kb/s
  Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 640x1136, 1439 kb/s, SAR 1:1 DAR 40:71, 28.87 fps, 29.83 tbr, 90k tbn, 180k tbc (default)
  Metadata:
    creation_time   : 2016-09-01 09:11:11
    handler_name    : VideoHandle
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 44 kb/s (default)
Metadata:
  creation_time   : 2016-09-01 09:11:11
  handler_name    : SoundHandle

唯一明显的区别是像素格式,我在Android 7.0中获得了yuv420p(tv, bt470bg/bt470bg/smpte170m),但它应该是yuv420p

如何解决此问题?

0 个答案:

没有答案