简体   繁体   English

如何在Android上将WebRTC本地视频流录制到文件?

[英]How to record WebRTC local video stream to file on Android?

I have using WebRTC. 我使用过WebRTC。 I want to local video stream to file. 我想将本地视频流发送到文件。 I'd appreciate it if you gave me a hint to approach this. 如果你给我一个提示来解决这个问题我会很感激的。

Thank you for reading it. 谢谢你的阅读。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //sigConnect("http://10.54.36.19:8000/");
    sigConnect("http://unwebrtc.herokuapp.com/");
    initWebRTC();

    Log.i(TAG, "VideoCapturerAndroid.getDeviceCount() = " + VideoCapturerAndroid.getDeviceCount());
    String nameOfFrontFacingDevice = VideoCapturerAndroid.getNameOfFrontFacingDevice();
    String nameOfBackFacingDevice = VideoCapturerAndroid.getNameOfBackFacingDevice();
    Log.i(TAG, "VideoCapturerAndroid.getNameOfFrontFacingDevice() = " + nameOfFrontFacingDevice);
    Log.i(TAG, "VideoCapturerAndroid.getNameOfBackFacingDevice() = " + nameOfBackFacingDevice);
    VideoCapturerAndroid capturer = VideoCapturerAndroid.create(nameOfFrontFacingDevice);

    MediaConstraints videoConstraints = new MediaConstraints();

    VideoSource videoSource = peerConnectionFactory.createVideoSource(capturer, videoConstraints);
    localVideoTrack = peerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, videoSource);

    glview = (GLSurfaceView) findViewById(R.id.glview);
    VideoRendererGui.setView(glview, null);
    try {
        rendereRemote = VideoRendererGui.createGui(0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);
        rendereLocal = VideoRendererGui.createGui(72, 72, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);
        localVideoTrack.addRenderer(rendereLocal);
    } catch (Exception e) {
        e.printStackTrace();
    }

    mediaStream = peerConnectionFactory.createLocalMediaStream(LOCAL_MEDIA_STREAM_ID);
    mediaStream.addTrack(localVideoTrack);

}

Libjingle library use GlSurfaceView for rendering video. Libjingle库使用GlSurfaceView渲染视频。 You may try using FFMPEG library for saving video frames from that view. 您可以尝试使用FFMPEG库来保存该视图中的视频帧。 Not sure about audio though 虽然不确定音频

You have to create video container, like mp4, and manually encode and write every raw frame. 您必须创建视频容器,如mp4,并手动编码和写入每个原始帧。 Also the latest webrtc version, provides an access to recording audio from microphone. 最新的webrtc版本还提供了从麦克风录制音频的访问权限。 You should encode and mux audio samples as well. 您还应编码和复用音频样本。

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

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