webrtc 代码学习(二十七)video capture 设置

video capture 设置作者:LanPZzzz文章目录1. video capture 创建,在Add Video Track 时需要创建video source,里面就是video capture,这里就不再重复创建的过程了2. video capture 在选择format 的时候是查看最理想的一个,查看代码1. video capture 创建,在Add Video Track...
摘要由CSDN通过智能技术生成

video capture 设置
作者:LanPZzzz

1. video capture 创建,在Add Video Track 时需要创建video source,里面就是video capture,这里就不再重复创建的过程了
2. video capture 在选择format 的时候是查看最理想的一个,查看代码
\pc\videocapturertracksource.cc 354
  format_ = GetBestCaptureFormat(formats);
// Find the format that best matches the default video size.
// Constraints are optional and since the performance of a video call
// might be bad due to bitrate limitations, CPU, and camera performance,
// it is better to select a resolution that is as close as possible to our
// default and still meets the contraints.
const cricket::VideoFormat& GetBestCaptureFormat(
    const std::vector<cricket::VideoFormat>& formats) {
  RTC_DCHECK(formats.size() > 0);

  int 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Android 上打开 WebRTC 视频流,你需要使用 WebRTC 库和 Android 原生代码来实现。以下是一个示例代码,可以帮助你开始: 1. 导入 WebRTC 库: 在你的 Android 项目中,在 app/build.gradle 文件中添加以下依赖项: ``` implementation 'org.webrtc:google-webrtc:1.0.+' ``` 2. 创建 PeerConnectionFactory: ``` PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions()); PeerConnectionFactory peerConnectionFactory = PeerConnectionFactory.builder().createPeerConnectionFactory(); ``` 3. 创建 VideoCapturer: ``` VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(false)); ``` 4. 创建 VideoSource: ``` SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", null); VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast()); videoCapturer.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver()); videoCapturer.startCapture(1280, 720, 30); ``` 5. 创建 VideoTrack: ``` VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("video", videoSource); ``` 6. 创建 PeerConnection: ``` PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(Arrays.asList(new PeerConnection.IceServer("stun:stun.l.google.com:19302"))); PeerConnection peerConnection = peerConnectionFactory.createPeerConnection(configuration, new CustomPeerConnectionObserver()); ``` 7. 将 VideoTrack 添加到 PeerConnection 中: ``` peerConnection.addTrack(videoTrack); ``` 8. 创建 VideoRenderer: ``` SurfaceViewRenderer localView = findViewById(R.id.local_view); localView.init(surfaceTextureHelper.getSurfaceTexture(), context); localView.setMirror(true); VideoRenderer localRenderer = new VideoRenderer(localView); videoTrack.addRenderer(localRenderer); ``` 9. 创建 Offer: ``` peerConnection.createOffer(new CustomSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { peerConnection.setLocalDescription(new CustomSdpObserver(), sessionDescription); // 发送 Offer 到远端 } }, new MediaConstraints()); ``` 这就是一个简单的 WebRTC 视频流应用的示例代码。你需要根据你的具体需求来进行相应的修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值