andeoid硬件解码
Finally, I must say, finally, we get low-level media APIs in Android, the Android hardware decoding and encoding APIs are finally available. It was a thing since Android 4.1 in Google IO 2012, but until now, when a new Android version 4.2 has been released, those low-level APIs are still too hard to use. There're so many Android vendors, we can't even get the same results from all Google's Nexus devices.
Despite the annoyings, I still tried these APIs and prayed them to get better in next Android release, and next Android release would swallow market quikly.
I just finished a simple video player with the combination of MediaExtractor and MediaCodec, you may find the full project from my Github.
private MediaExtractor extractor;
private MediaCodec decoder;
private Surface surface; public void run() {
extractor = new MediaExtractor();
extractor.setDataSource(SAMPLE); for (int i = 0; i < extractor.getTrackCount(); i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
extractor.selectTrack(i);
decoder = MediaCodec.createDecoderByType(mime);
decoder.configure(format, surface, null, 0);
break;
}
} if (decoder == null) {
Log.e("DecodeActivity", "Can't find video info!");
return;
} decoder.start(); ByteBuffer[] inputBuffers = decoder.getInputBuffers();
ByteBuffer[] outputBuffers = decoder.getOutputBuffers();
BufferInfo info = new BufferInfo();
boolean isEOS = false;
long startMs = System.currentTimeMillis(); while (!Thread.interrupted()) {
if (!isEOS) {
int inIndex = decoder.dequeueInputBuffer(10000);
if (inIndex >= 0) {
ByteBuffer buffer = inputBuffers[inIndex];
int sampleSize = extractor.readSampleData(buffer, 0);
if (sampleSize < 0) {
Log.d("DecodeActivity", "InputBuffer BUFFER_FLAG_END_OF_STREAM");
decoder.queueInputBuffer(inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
isEOS = true;
} else {
decoder.queueInputBuffer(inIndex, 0, sampleSize, extractor.getSampleTime(), 0);
extractor.advance();
}
}
} int outIndex = decoder.dequeueOutputBuffer(info, 10000);
switch (outIndex) {
case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
Log.d("DecodeActivity", "INFO_OUTPUT_BUFFERS_CHANGED");
outputBuffers = decoder.getOutputBuffers();
break;
case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
Log.d("DecodeActivity", "New format " + decoder.getOutputFormat());
break;
case MediaCodec.INFO_TRY_AGAIN_LATER:
Log.d("DecodeActivity", "dequeueOutputBuffer timed out!");
break;
default:
ByteBuffer buffer = outputBuffers[outIndex];
Log.v("DecodeActivity"
, "We can't use this buffer but render it due to the API limit, " + buffer); // We use a very simple clock to keep the video FPS, or the video
// playback will be too fast
while (info.presentationTimeUs / 1000 > System.currentTimeMillis() - startMs) {
try {
sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
decoder.releaseOutputBuffer(outIndex, true);
break;
} if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
Log.d("DecodeActivity", "OutputBuffer BUFFER_FLAG_END_OF_STREAM");
break;
}
} decoder.stop();
decoder.release();
extractor.release();
}
andeoid硬件解码的更多相关文章
- andeoid硬件解码学习 (二)
Finally, I must say, finally, we get low-level media APIs in Android, the Android hardware decoding ...
- android Mediaplayer硬件解码浅探
在讨论stagefright如何调用硬件解码之前,我们要先清楚几个问题. 我不展开这几个结论是如何得来的,因为这部分属于进程间通信binder的理解,和多媒体本身无关. 一.问题空间 这个有点像方法学 ...
- Android中使用MediaCodec硬件解码,高效率得到YUV格式帧,快速保存JPEG图片(不使用OpenGL)(附Demo)
MediaCodec的使用demo: https://github.com/vecio/MediaCodecDemo https://github.com/taehwandev/MediaCodecE ...
- Android的音频解码原来是直接调用的本地C方法直接通过硬件解码
Android就是披着JAVA外衣的C啊~音频解码原来是直接调用的本地C方法直接通过硬件解码的,JAVA和C的字节数组存放模式不同(java是大端,C根据不同平台不同),不同格式需要转化以后才能用. ...
- 使用C#+FFmpeg+DirectX+dxva2硬件解码播放h264流
本文门槛较高,因此行文看起来会乱一些,如果你看到某处能会心一笑请马上联系我开始摆龙门阵 如果你跟随这篇文章实现了播放器,那你会得到一个高效率,低cpu占用(单路720p视频解码播放占用1%左右cpu) ...
- 阿里云 RTC QoS 弱网对抗之 LTR 及其硬件解码支持
LTR 弱网对抗由于需要解码器的反馈,因此用硬件解码器实现时需要做一些特殊处理.另外,一些硬件解码器对 LTR 的实现不是特别完善,会导致出现解码错误.本文为 QoS 弱网优化系列的第三篇,将为您详解 ...
- 解密H264、AAC硬件解码的关键扩展数据处理
通过上一篇文章,我们用ffmpeg分离出一个多媒体容器中的音视频数据,但是很可能这些数据是不能被正确解码的.为什么呢?因为在解码这些数据之前,需要对解码器做一些配置,典型的就是目前流行的高清编码“黄金 ...
- (转) 解密H264、AAC硬件解码的关键扩展数据处理
出自:http://blog.itpub.net/30168498/viewspace-1576794/ 通过上一篇文章,我们用ffmpeg分离出一个多媒体容器中的音视频数据,但是很可能这 ...
- android 硬件解码学习
FileInputStream in = new FileInputStream("/sdcard/sample.ts"); String mimeType = "vid ...
随机推荐
- Codeforces Round #441 Div. 2 A B C D
题目链接 A. Trip for Meal 题意 三个点之间两两有路径,分别长为\(a,b,c\),现在从第一个点出发,走\(n-1\)条边,问总路径最小值. 思路 记起始点相邻的边为\(a,b\), ...
- 剖析CPU温度监控技术【转】
转自:http://blog.csdn.net/hunanchenxingyu/article/details/46476545 迄今为止还没有一种cpu散热系统能保证永不失效.失去了散热系统保护伞的 ...
- Linux firmware 加载【转】
转自:http://blog.chinaunix.net/uid-22028680-id-3157922.html 1.request_firmware在内核使用,需要文件系统支持,就是说,启动的时候 ...
- 聚类kmeans算法在yolov3中的应用
yolov3 kmeans yolov3在做boundingbox预测的时候,用到了anchor boxes.这个anchors的含义即最有可能的object的width,height.事先通过聚类得 ...
- iOS 动画笔记 (二)
有它们俩你就够了! 说明:下面有些概念我说的不怎么详细,网上实在是太多了,说了我觉得也意义不大了!但链接都给大家了,可以自己去看,重点梳理学习写动画的一个过程和一些好的博客! 一:说说这两个三方库,C ...
- luogu P2744 [USACO5.3]量取牛奶Milk Measuring
题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出.消费者要多少,他就给多少,从不有 ...
- 深入浅出 Cocoa 之 Core Data(4)- 使用绑定
深入浅出 Cocoa 之 Core Data(4)- 使用绑定 罗朝辉(http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 前面讲解了 Core Data 的框架, ...
- ZRender实现粒子网格动画实战
注:本博文代码基于ZRender 3.4.3版本号开发,相应版本号库地址:ZRender 库. 效果 实现分析 通过上面显示的效果图,能够看出,这样的效果就是在Canvas中生成多个可移动的点,然后依 ...
- 脚本命令加载外部配置文件夹conf
加载log4j配置文件 Log4iConfigurer类 public class Log4iConfigurer { private static boolean INITIALIZED = fal ...
- android listView 滑动载入数据 该数据是服务端获取的
package com.sunway.works.applycash; import java.util.ArrayList; import java.util.Calendar; import ja ...