1. 程式人生 > >Using Android MediaCodec H264 and Display

Using Android MediaCodec H264 and Display

Android MediaCode request API level 16

public class MyTextureView extends TextureView implements  TextureView.SurfaceTextureListener{

    private static  final String MIME_TYPE = "video/avc";
    private static final String TAG = "MyTextureView" ;
    private MediaCodec decode;

    public MyTextureView
(Context context, AttributeSet attrs) { super(context, attrs); setSurfaceTextureListener(this); } private void init(Surface surface, int width , int height) { Log.e(TAG, "PreviewThread: gou zhao"); try { decode = MediaCodec.createDecoderByType(MIME_TYPE); } catch
(IOException e) { e.printStackTrace(); } if (decode==null) { Log.e(TAG, "decode is null "); } int frameRate = MainApplication.getApplication().getDeviceSettingInfo().getFrontRate(); final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height); format.setInteger(MediaFormat.KEY_BIT_RATE, 6000
); format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate>0?frameRate:30); format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 32); format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0); byte[] header_sps = {0, 0, 0, 1, 103, 66, 0 , 41, -115, -115, 64, 80 , 30 , -48 , 15 ,8,-124, 83, -128}; byte[] header_pps = {0,0 ,0, 1, 104, -54, 67, -56}; format.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps)); format.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps)); decode.configure(format, surface,null,0); decode.start(); } @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { init(new Surface(surface), width, height); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { if (decode != null) { decode.release(); } return false; } @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { } //解碼h264資料 public void decoderH264(byte[] input, long timestamp) { try { int length = input.length; ByteBuffer[] inputBuffers = decode.getInputBuffers(); int inputBufferIndex = decode.dequeueInputBuffer(0); Log.i(TAG, "inputBufferIndex: " +inputBufferIndex + ", in buf len=" +inputBuffers.length); if (inputBufferIndex >= 0) { ByteBuffer inputBuffer = inputBuffers[inputBufferIndex]; inputBuffer.clear(); try{ inputBuffer.put(input, 0, length); }catch (Exception e){ e.printStackTrace(); } decode.queueInputBuffer(inputBufferIndex, 0, length, 0, 0); } MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo(); int outputBufferIndex = decode.dequeueOutputBuffer(bufferInfo, 0); Log.w(TAG, "outputBufferIndex=" +outputBufferIndex + ", out buf len=" + decode.getOutputBuffers().length); while (outputBufferIndex >= 0) { //decode.releaseOutputBuffer(outputBufferIndex, true); decode.releaseOutputBuffer(outputBufferIndex, timestamp); outputBufferIndex = decode.dequeueOutputBuffer(bufferInfo, 0); } } catch (Throwable t) { t.printStackTrace(); } } }

相關推薦

Using Android MediaCodec H264 and Display

Android MediaCode request API level 16 public class MyTextureView extends TextureView implements TextureView.SurfaceTextureListe

Using Swift with Cocoa and Objective-C下載

target cocoa 下載地址 obj swift nbsp 地址 bject uil 《Using Swift with Cocoa and Objective-C Building App 》 下載地址 http://download.csdn.net/

android adb shell and monkey 學習記錄

型號 orm -a reboot 觸摸事件 serial roc ear cpu Monkey環境: android SDK and JDK SDK目錄下的platform-tools和tools目錄要配置環境變量 查看版本: ADB 的安裝這裏就

Android MediaCodec 狀態(States)轉換分析

configure 三種 com android m spl 詳細 blog pla sta *由於工作需要,需要利用MediaCodec實現Playback及Transcode等功能,故在學習過程中翻譯了Google官方的MediaCodec API文檔,由於作者水平限制

[React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime

lar javascrip reac lan com value pla edt int Using the react-intl FormattedDate and FormattedTime components, we’ll render a JavaSc

mysql更新字段值提示You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode

error without 使用 using ble mod code span set 1 引言 當更新字段缺少where語句時,mysql會提示一下錯誤代碼: Error Code: 1175. You are using safe update mode and yo

Cordova Upload Images using File Transfer Plugin and .Net core WebAPI

ini blank see art back sele pad indexof apps In this article, I am going to explain ,"How to Upload Images to the server using Cordova Fi

Structure Inference Network:Object Detection Using Scene-Level Context and Instance-Level Relationships筆記小結

sigmoid alt 識別 fas lin sca 回歸 全連接 大量 結構推理網絡:基於場景級與實例級目標檢測 原文鏈接:https://arxiv.org/abs/1807.00119 Yong Liu, Ruiping Wang, Shiguang Shan,

android UVC h264 ffmpeg軟解碼

需求:由於android連線UVC 264攝像頭需要解碼資料,於是用ffmpeg進行解碼   參考:https://blog.csdn.net/gobitan/article/details/22750719   以下內容為轉載和部分修改:  

android UVC h264 ffmpeg硬解碼(RK3288 android5.1)

username需求:由於軟解碼速度跟不上導致解碼花屏嚴重,轉用ffmpeg交叉編譯android 5.1原始碼硬解碼。   假設已經編譯好RK3288 android5.1系統(主要是硬編碼用到的libstagefright庫) 系統編譯參考:https://blog.csd

Android studio The versions of the Android Gradle plugin and Gradle are not compatible.

錯誤: The versions of the Android Gradle plugin and Gradle are not compatible. 原因是:Android的Gealle外掛和Gradle的版本是不相容的。 需要修改工程裡的bulid.grade的 cla

更新資料庫中資料時出現: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe m

在資料庫中更新資料時報錯: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column  To disable safe mode, toggle

讀《Tooth-Marked Tongue Recgnition Using Multiple Instance Learning and CNN Features》

本人 組會彙報的一篇關於齒痕舌判定的文章,貼上PPT 涉及多示例學習和神經網路方面知識。                    

論文筆記12:Building Adaptive Tutoring Model using Artificial Neural Networks and Reinforcement Learning

論文筆記12:《Building Adaptive Tutoring Model using Artificial Neural Networks and Reinforcement Learning》 參考文獻:Building Adaptive Tutoring Model Using Ar

Centos/RHEL :How to add,delete and display LVM tags

1. 什麼是LVM標籤?   在你想開機啟動時讓邏輯卷被啟用可用時,新增lvm標籤是一個不錯的選擇。lvm標籤允許那些被預先標記的實現這樣的效果。 2. 配置檔案   配置檔案/etc/lvm/lvm.conf中有這樣一段話: # vim /etc/lvm/lvm.conf # If v

Android 5.0 and later only support position-independent executables

在參考Android利用tcpdump和wireshark抓取網路資料包使用tcpdump的時候,會提示如下資訊: λ adb shell /data/local/tcpdump "/data/local/tcpdump": error: Android 5.0 and later

android-mediacodec-google官方demo

官方地址 https://github.com/PhilLab/Android-MediaCodec-Examples/blob/master/ExtractMpegFramesTest.java   掘金概述文章 https://juejin.im/entry/58628

MySQL Workbench批量修改資料報錯:Error Code: 1175. You are using safe update mode and you tried to update a t

批量修改資料SQL:update sys_menu set menu_extralink = true     錯誤資訊: Error Code: 1175. You are using safe update mode and you tried to upd

Reading Level Assessment Using Support Vector Machines and Statistical Language Models-paper

Authors: Sarah E. Schwarm University of Washington, Seattle, WAMari Ostendorf University of Washington, Seattle, WAPublished in: ACLtime:June 25 - 30, 2005

building a blog using google app engine and python

Today, I created two videos as a continuation of my YouTube series (). This post will be short because you might need just a little over 5 minutes a pie