title: Why is video made with MediaCodec garbled for Samsung Galaxy S7?
body: <p>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.</p>
  
  <p><a href="https://i.stack.imgur.com/9rEER.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9rEER.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://stackoverflow.com/q/18795353/4639640">Using MediaCodec to save series of images as Video</a> 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.</p>
  
  <p>I also tried messing with the video resolution (settled on 1280 x 720) per <a href="https://stackoverflow.com/a/34945633/4639640">MediaCodec Encoded video has green bar at bottom and chrominance screwed up</a>, but that didn't solve the problem either. (c.f. <a href="https://stackoverflow.com/q/22579865/4639640">Nexus 7 2013 mediacodec video encoder garbled output</a>)</p>
  
  <p>Does anyone have suggestions for what I might try to get the video formatted correctly?</p>
  
  <p>Here is part of the log from the encoding:</p>
  
  <pre><code>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-&gt;Idle
  I/ACodec: [OMX.qcom.video.encoder.avc] Now Idle-&gt;Executing
  I/ACodec: [OMX.qcom.video.encoder.avc] Now Executing
  I/MPEG4Writer: setStartTimestampUs: 0
  I/MPEG4Writer: Earliest track starting time: 0
  </code></pre>
  
  <p>The 5th unrecognized color seems to be COLOR_FormatSurface... Is that a problem?</p>
  
  <p>Other details:</p>
  
  <ul>
  <li>MIME: video/avc </li>
  <li>Resolution: 1280 x 720 </li>
  <li>Frame rate: 30 </li>
  <li>IFrame interval: 2 </li>
  <li>Bitrate: 8847360</li>
  </ul>