使用FFmpeg的Andr​​oid摄像头捕获 [英] Android Camera Capture using FFmpeg

查看:214
本文介绍了使用FFmpeg的Andr​​oid摄像头捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上午试着走了Android摄像头所产生的preVIEW框架,并通过数据[] 来FFmpeg的输入管道来生成FLV视频。 我使用的命令是:

Am tryin' to take the preview frame generated by the android camera and pass the data[] to ffmpeg input pipe to generate a flv video. The command that I used was :

ffmpeg -f image2pipe -i pipe: -f flv -vcodec libx264 out.flv

我还试图迫使输入格式为 yuv4mpegpipe rawvideo 但没有成功... 通过Android的摄像头所产生的preVIEW框的默认格式为 NV21 。 该办法时invokin的ffmpeg是通过进程API 和写入preVIEW帧数据[] 的过程'标准输入 ... 该在previewFrame()定义如下:

I've also tried to force the input format to yuv4mpegpipe and rawvideo but with no success... The default format of the preview frame generated by android-camera is NV21. The way am invokin' ffmpeg is through the Process API and writing the preview frames data[] to the process' stdin... The onPreviewFrame() definition is as follows :

public void onPreviewFrame(byte[] data, Camera camera)
{   
    try
    {
        processIn.write(data);
    }
    catch(Exception e)
    {
        Log.e(TAG, FUNCTION + " : " + e.getMessage());
    }               
    camera.addCallbackBuffer(new byte[bufferSize]);
}

生产工程过程连接到的ffmpeg 进程标准输入 BUFFERSIZE 是以提供 addCallbackBuffer()的说明文件来计算。 有什么是我干什么错了...?

processIn is connected to the ffmpeg process stdin and buffersize is computed based on the documentation provided for addCallbackBuffer(). Is there something that am doin' wrong...?

谢谢...

推荐答案

还挺得到它的工作完美... 这似乎是happenin'的错误是关系到图像流的 V codeC 。 看来,FFmpeg的有没有规定要取消code NV21 格式图像或图像流。 对于那些不得不在 NV21 格式preVIEW帧转​​换为 JPEG 并作为图像曾在实到流时间到的ffmpeg 的过程中,转换必须是。最近的可靠的解决方案,转化为 JPEG 如下:

Kinda got it working perfectly... The mistake that seemed to be happenin' was related to the vcodec of the image stream. Seems that ffmpeg has no provision to decode NV21 format images or image stream. For that had to convert the NV21 format preview frame to JPEG and as the images had to streamed in real time to the ffmpeg process ,the conversion had to be On the Fly. The closest reliable solution for On the Fly conversion to JPEG was as follows :

public void onPreviewFrame(byte[] data, Camera camera)
{
        if(isFirstFrame)
    {
        Camera.Parameters cameraParam = camera.getParameters();
        Camera.Size previewSize = cameraParam.getPreviewSize();
        previewFormat = cameraParam.getPreviewFormat();
        frameWidth = previewSize.width;
        frameHeight = previewSize.height;
        frameRect = new Rect(0, 0, frameWidth, frameHeight);
        isFirstFrame = false;
    }

    previewImage = new YuvImage(data, previewFormat, frameWidth, frameHeight, null);

    if(previewImage.compressToJpeg(frameRect, 50, processIn))
        Log.d(TAG, "Data : " + data.length);

    previewImage = null;

    camera.addCallbackBuffer(new byte[bufferSize]);
}

的ffmpeg 命令用的是:

ffmpeg -f image2pipe -vcodec mjpeg -i - -f flv -vcodec libx264 out.flv

这篇关于使用FFmpeg的Andr​​oid摄像头捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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