You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android设备用flutter_webrtc播放Google NestCam视频帧率骤降求助

问题:Google NestCam在Android Flutter WebRTC播放帧率骤降(30fps→0.5fps)

Google NestCam本身帧率为30fps,但在Android设备上通过flutter_webrtc组件播放其视频时,画面帧率降至0.5fps,已排查确认网络与设备性能均无异常。

Flutter端视频展示代码

RTCVideoView(
 _remoteRenderer,
 mirror: false,
 objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover,
),

flutter_webrtc性能日志片段

I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: initPlayout(sampleRate=48000, channels=1, bufferSizeFactor=1.0)
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: byteBuffer.capacity: 960
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: minBufferSizeInBytes: 7688
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: createAudioTrackBeforeOreo
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: nativeOutputSampleRate: 48000
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: AudioTrack: session ID: 553, channels: 1, sample rate: 48000, max gain: 1.0
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: AudioTrack: buffer size in frames: 3844
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: AudioTrack: buffer capacity in frames: 3844
I/org.webrtc.Logging( 1726): VolumeLogger: start@[name=worker_thread - 1913, id=49]
I/org.webrtc.Logging( 1726): VolumeLogger: audio mode is: MODE_NORMAL
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: startPlayout
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: AudioTrackThread@[name=AudioTrackJavaThread, id=84]
I/org.webrtc.Logging( 1726): WebRtcAudioTrackExternal: doAudioTrackStateCallback: 0
I/org.webrtc.Logging( 1726): VolumeLogger: VOICE_CALL stream volume: 8 (max=8)
D/FlutterWebRTCPlugin( 1726): onAddTrack
D/FlutterWebRTCPlugin( 1726): onAddTrack
D/FlutterWebRTCPlugin( 1726): onConnectionChangeCONNECTING
W/FlutterWebRTCPlugin( 1726): FlutterRTCVideoRenderer.setVideoTrack, set video track to 9308e6dc-fc46-4916-beb1-e913ae3d61c1
I/org.webrtc.Logging( 1726): EglRenderer: Releasing.
I/org.webrtc.Logging( 1726): EglRenderer: eglBase detach and release.
I/org.webrtc.Logging( 1726): EglRenderer: Releasing done.
I/org.webrtc.Logging( 1726): EglRenderer: Quitting render thread.
I/org.webrtc.Logging( 1726): EglRenderer: Initializing EglRenderer
I/org.webrtc.Logging( 1726): EglRenderer: EglBase.create shared context
I/org.webrtc.Logging( 1726): EglBase14Impl: Using OpenGL ES version 2
[log] received stream: Instance of 'MediaStreamNative'
[log] received stream: Instance of 'MediaStreamNative'
D/FlutterWebRTCPlugin( 1726): onSelectedCandidatePairChanged
D/FlutterWebRTCPlugin( 1726): onIceGatheringChangeCOMPLETE
D/FlutterWebRTCPlugin( 1726): onConnectionChangeCONNECTED
I/org.webrtc.Logging( 1726): EglRenderer: Duration: 4003 ms. Frames received: 0. Dropped: 0. Rendered: 0. Render fps: .0. Average render time: NA. Average swapBuffer time: NA.
I/org.webrtc.Logging( 1726): CameraStatistics: Camera fps: 30.
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: ctor name: OMX.qcom.video.decoder.avc type: H264 color format: 19 context: org.webrtc.EglBase14Impl$Context@99e8b53
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: ctor name: c2.android.avc.decoder type: H264 color format: 19 context: org.webrtc.EglBase14Impl$Context@99e8b53
I/org.webrtc.Logging( 1726): EglBase14Impl: Using OpenGL ES version 2
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: initDecodeInternal name: OMX.qcom.video.decoder.avc type: H264 width: 1920 height: 1080
I/org.webrtc.Logging( 1726): SurfaceTextureHelper: Setting listener to org.webrtc.AndroidVideoDecoder@b267fd
I/OMXClient( 1726): IOmx service obtained
D/MediaCodec( 1726): flushMediametrics
D/SurfaceUtils( 1726): connecting to surface 0x7d3c746d70, reason connectToSurface
I/MediaCodec( 1726): [OMX.qcom.video.decoder.avc] setting surface generation to 1767426
D/SurfaceUtils( 1726): disconnecting from surface 0x7d3c746d70, reason connectToSurface(reconnect)
D/SurfaceUtils( 1726): connecting to surface 0x7d3c746d70, reason connectToSurface(reconnect)
W/ExtendedACodec( 1726): failed to reallocate omx vpp component: -2
I/ExtendedACodec( 1726): setupVideoDecoder()
I/ExtendedACodec( 1726): Decoder will be in frame by frame mode
W/ExtendedACodec( 1726): Failed to set frame packing format on component
D/SurfaceUtils( 1726): set up nativeWindow 0x7d3c746d70 for 1920x1080, color 0x7fa30c06, rotation 0, usage 0x20402900
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: initDecodeInternal done
D/SurfaceUtils( 1726): set up nativeWindow 0x7d3c746d70 for 1920x1088, color 0x7fa30c06, rotation 0, usage 0x20402900
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: Decoder format changed: {crop-right=1919, color-format=2141391878, slice-height=1088, mime=video/raw, hdr-static-info=java.nio.HeapByteBuffer[pos=0 lim=25 cap=25], stride=1920, color-standard=1, color-transfer=3, crop-bottom=1079, crop-left=0, width=1920, color-range=2, crop-top=0, height=1088}
I/org.webrtc.Logging( 1726): AndroidVideoDecoder: Frame stride and slice height: 1920 x 1088
I/org.webrtc.Logging( 1726): CameraStatistics: Camera fps: 30.
I/org.webrtc.Logging( 1726): EglRenderer: Duration: 4003 ms. Frames received: 2. Dropped: 0. Rendered: 2. Render fps: .5. Average render time: 3931 us. Average swapBuffer time: 878 us.

解决方案

  • 强制启用硬件加速解码
    从日志可见解码器进入了frame by frame mode,这通常是软件解码的特征,会大幅限制帧率。需在flutter_webrtc配置中强制启用硬件加速:可在Android原生层修改WebRTC解码参数,或者在RTCVideoRenderer初始化时添加硬件加速相关配置,确保使用OMX.qcom.video.decoder.avc这类硬件解码器而非软件解码器。

  • 明确指定视频流接收参数
    在WebRTC连接建立阶段,主动设置视频接收的帧率约束,明确要求30fps,避免协商阶段参数不匹配:

    final videoConstraints = RTCVideoConstraints(
      maxFps: 30,
      minFps: 30,
      maxWidth: 1920,
      maxHeight: 1080,
    );
    // 将约束应用到视频轨道或RTCPeerConnection配置中
    
  • 升级OpenGL ES版本
    日志显示当前使用OpenGL ES version 2,尝试强制使用OpenGL ES 3.0及以上版本,更高版本的GL能提升渲染效率。可在flutter_webrtc的Android原生配置中修改EglBase初始化参数,指定更高的OpenGL版本。

  • 减少资源占用:禁用不必要的音频轨道
    若无需播放NestCam的音频,可移除音频轨道,让更多系统资源分配给视频渲染:

    // 停止并移除所有音频轨道
    _remoteRenderer.srcObject?.getAudioTracks().forEach((track) {
      track.stop();
      _remoteRenderer.srcObject?.removeTrack(track);
    });
    
  • 升级flutter_webrtc到最新稳定版
    旧版本的flutter_webrtc可能存在Android端解码或渲染的已知bug,升级到最新稳定版可修复此类性能问题。

内容的提问来源于stack exchange,提问作者モコモコナオ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 15:32:35