创建一个从屏幕上争夺的Andr​​oid视频 [英] Create video from screen grabs in android

查看:204
本文介绍了创建一个从屏幕上争夺的Andr​​oid视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在录制视频的用户交互,人们可以然后上传到自己的社交媒体网站。

I would like to record user interaction in a video that people can then upload to their social media sites.

例如,会说话的汤姆猫的Andr​​oid应用程序有一个小摄像机图标。用户可以preSS摄像机图标,然后与应用程序,preSS图标停止录制,然后将视频处理/转换准备上传的交互。

For example, the Talking Tom Cat android app has a little camcorder icon. The user can press the camcorder icon, then interact with the app, press the icon to stop the recording and then the video is processed/converted ready for upload.

我想我可以用setDrawingCacheEnabled(真),保存图像,但不知道如何添加音频或进行视频。

I think I can use setDrawingCacheEnabled(true) to save images but don't know how to add audio or make a video.

更新:经过进一步的阅读我想我会需要使用NDK和ffmpeg的。我preFER不这样做,但是,如果没有其他的选择,没有人知道如何做到这一点?

Update: After further reading I think I will need to use the NDK and ffmpeg. I prefer not to do this, but, if there are no other options, does anyone know how to do this?

有谁知道如何做到这一点在Android的?

Does anyone know how to do this in Android?

<一个href="http://stackoverflow.com/questions/9091794/android-screen-capturing-or-make-video-from-images">Android屏幕捕捉,或使从图像视频

<一个href="http://stackoverflow.com/questions/6980370/how-to-record-screen-video-as-like-talking-tomcat-application-does-in-iphone">how以创纪录的屏幕录像为喜欢说话Tomcat应用确实在iPhone?

推荐答案

使用媒体与 CONFIGURE_FLAG_EN code codeC API将其设置为一间codeR。无需ffmpeg的:)

Use the MediaCodec API with CONFIGURE_FLAG_ENCODE to set it up as an encoder. No ffmpeg required :)

您已经找到了如何抓取屏幕在您链接到的其他问题,现在你只需要在每个捕获的帧喂媒体codeC ,设置适当的格式标志,时间戳等。

You've already found how to grab the screen in the other question you linked to, now you just need to feed each captured frame to MediaCodec, setting the appropriate format flags, timestamp, etc.

编辑:样品$ C $下,这是很难找到,但<一个href="https://android.googlesource.com/platform/cts/+/6289d680cb75fa5a985464b9f362d4a2a007a7bf%5E!/#F0">here它是的,帽尖马丁Storsjö。快速API演练:

Sample code for this was hard to find, but here it is, hat tip to Martin Storsjö. Quick API walkthrough:

MediaFormat inputFormat = MediaFormat.createVideoFormat("video/avc", width, height);
inputFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
inputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
inputFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
inputFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 75);
inputFormat.setInteger("stride", stride);
inputFormat.setInteger("slice-height", sliceHeight);

encoder = MediaCodec.createByCodecName("OMX.TI.DUCATI1.VIDEO.H264E"); // need to find name in media codec list, it is chipset-specific

encoder.configure(inputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
encoder.start();
encoderInputBuffers = encoder.getInputBuffers();
encoderOutputBuffers = encoder.getOutputBuffers();

byte[] inputFrame = new byte[frameSize];

while ( ... have data ... ) {
    int inputBufIndex = encoder.dequeueInputBuffer(timeout);

    if (inputBufIndex >= 0) {
        ByteBuffer inputBuf = encoderInputBuffers[inputBufIndex];
        inputBuf.clear();

        // HERE: fill in input frame in correct color format, taking strides into account
        // This is an example for I420
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                inputFrame[ i * stride + j ] = ...; // Y[i][j]
                inputFrame[ i * stride/2 + j/2 + stride * sliceHeight ] = ...; // U[i][j]
                inputFrame[ i * stride/2 + j/2 + stride * sliceHeight * 5/4 ] = ...; // V[i][j]
            }
        }

        inputBuf.put(inputFrame);

        encoder.queueInputBuffer(
            inputBufIndex,
            0 /* offset */,
            sampleSize,
            presentationTimeUs,
            0);
    }

    int outputBufIndex = encoder.dequeueOutputBuffer(info, timeout);

    if (outputBufIndex >= 0) {
        ByteBuffer outputBuf = encoderOutputBuffers[outputBufIndex];

        // HERE: read get the encoded data

        encoder.releaseOutputBuffer(
            outputBufIndex, 
            false);
    }
    else {
        // Handle change of buffers, format, etc
    }
}

也有一些开放问题

编辑:你会喂数据作为支持的像素格式之一字节的缓冲区,例如I420或NV12。有不幸的是确定哪些格式将工作在特定设备上没有完美的方式;然而,这是典型的为同一格式,可以从相机获得与EN codeR工作。

You'd feed the data in as a byte buffer in one of the supported pixel formats, for example I420 or NV12. There is unfortunately no perfect way of determining which formats would work on a particular device; however it is typical for the same formats you can get from the camera to work with the encoder.

这篇关于创建一个从屏幕上争夺的Andr​​oid视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆