访问输出视频的同时录制 [英] Accessing the output video while recording

查看:131
本文介绍了访问输出视频的同时录制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总之,我正在寻找一种方式,从摄像头录制视频,以获得字节流。 这样做的目的是,同时节省了当前记录的特定部分,而不停止实际记录过程来访问输出文件,以连续记录。这甚至可能,或将我需要真正停止录音并保存它是可玩的?

In short, I'm looking for a way to get the byte stream from the camera while recording video. The aim is to continuously record while saving certain portions of the current recording without stopping the actual recording process to access the output file. Is this even possible, or will I need to actually stop the recording and save it for it be playable?

我见过的项目和开源库的,允许通过本地插座和ParcelFileDescriptor类流媒体直播从相机到服务器,所以我认为(也许不正确)的记录字节流必须能够访问以某种方式。

I've seen projects and open source library's that allow live streaming from the camera to a server via a local socket and the ParcelFileDescriptor class, so I assume (maybe incorrectly) that the recorder byte stream must be accessible somehow.

任何建议或帮助将是很大的AP preciated。

Any suggestions or help would be greatly appreciated.

推荐答案

设置输出文件的FileDescriptor:

Set output file to FileDescriptor:

mRecorder.setOutputFile(getStreamFd());

然后使用此功能:

Then use this function:

   private FileDescriptor getStreamFd() {
    ParcelFileDescriptor[] pipe = null;

    try {
        pipe = ParcelFileDescriptor.createPipe();

        new TransferThread(new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]),
                new FileOutputStream(getOutputFile())).start();
    } catch (IOException e) {
        Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
    }

    return (pipe[1].getFileDescriptor());
}

private File getOutputFile() {
    return (new File(Environment.getExternalStorageDirectory().getPath().toString() + "/YourDirectory/filename"));
}

新线程code:

New thread code:

    static class TransferThread extends Thread {
    InputStream in;
    FileOutputStream out;

    TransferThread(InputStream in, FileOutputStream out) {
        this.in = in;
        this.out = out;
    }

    @Override
    public void run() {
        byte[] buf = new byte[8192];
        int len;

        try {
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();

            out.flush();
            out.getFD().sync();
            out.close();

        } catch (IOException e) {
            Log.e(getClass().getSimpleName(),
                    "Exception transferring file", e);
        }
    }
}

不要忘了persmissions添加到您的清单文件:

Don't forget to add persmissions to your manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这篇关于访问输出视频的同时录制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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