简体   繁体   English

Mediacodec在线编码视频

[英]Mediacodec to encode video online

I was able to implement a code which records video bases on CameraCaptureActivity from grafika. 我能够实现一个代码,该代码在grafika的CameraCaptureActivity上记录了视频基础。 Now I can record myself counting from 1 to 10, but when I go to see the recorded video I am saying 1,3,8,9, that is I missed some frames to be recorded. 现在,我可以记录自己从1到10的计数,但是当我去看记录的视频时,我说的是1,3,8,9,那是我错过了一些要记录的帧。 The surface was configured: 该表面已配置:

private static int VIDEO_WIDTH = 720;  // dimensions for 720p video
private static int VIDEO_HEIGHT = 1280;
private static int DESIRED_PREVIEW_FPS = 30; 

and the encoder 和编码器

format.SetInteger(MediaFormat.KeyColorFormat, (int)MediaCodecCapabilities.Formatsurface);
format.SetInteger(MediaFormat.KeyBitRate, 100000);
format.SetInteger(MediaFormat.KeyFrameRate, 30);
format.SetInteger(MediaFormat.KeyIFrameInterval, 5);

width: 310 and height: 310. 宽度:310和高度:310。

is my problem the BitRate? 我的问题是BitRate吗? Which values should I set in order to receive every frame which I display to be recorded by the encoder? 为了接收编码器记录的每帧图像,我应该设置哪些值? thanks. 谢谢。

I've seen MediaMuxer pause for 1+ seconds when writing data to disk, but generally not at lower bit rates -- the 1Mbps bit rate used by Grafika should be fine -- and they're usually several seconds apart. 我已经看到MediaMuxer在将数据写入磁盘时会暂停1+秒,但通常不会以较低的比特率-Grafika使用的1Mbps比特率应该没问题-而且它们通常相隔数秒。 So I'm not sure if that's the problem you're facing. 因此,我不确定这是否是您面临的问题。

There's a nice blog post about the MediaMuxer problem here: http://blog.horizon.camera/post/134263616000/optimizing-mediamuxers-writing-speed . 这里有一篇有关MediaMuxer问题的不错的博客文章: http ://blog.horizo​​n.camera/post/134263616000/optimizing-mediamuxers-writing-speed。 In short, the MediaMuxer write stalls, so no frames are being pulled out of the MediaCodec encoder. 简而言之,MediaMuxer写入停顿,因此没有帧被拉出MediaCodec编码器。 Eventually MediaCodec runs out of buffers and can't take any more input, so the Camera starts discarding frames. 最终,MediaCodec的缓冲区用完了,无法再接受任何输入,因此摄像机开始丢弃帧。

Wrapping the MediaMuxer calls with systrace tags will help narrow things down. systrace标签包装MediaMuxer调用将有助于缩小范围。 The idea is to bracket all the "interesting" calls in your encoding setup with android.os.Trace beginSection() / endSection() calls, and collect systrace output with the --app tag ( example here ). 这个想法是用android.os.Trace beginSection() / endSection()调用将编码设置中的所有“有趣”调用beginSection() endSection() ,并使用--app标记收集systrace输出( 此处为示例 )。 Looking at the systrace output will show you how long each function takes, show you which threads each runs on, and help you identify areas where a call has blocked and is starving other threads. 查看systrace输出将显示每个函数需要花费多长时间,显示每个函数运行在哪个线程上,并帮助您确定调用已阻塞并且正在使其他线程处于饥饿状态的区域。

It's entirely possible there's something else going on, but this is a good place to start. 完全有可能发生其他事情,但这是一个不错的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM