i want best setting for live video for flutter (IO...
# ask-ai
f
i want best setting for live video for flutter (IOS and Android)
t
Thanks for reaching out, subhi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To get the best live video experience in your Flutter app for iOS and Android using LiveKit, here are some friendly tips you can follow: • General Video Configuration: Try using preset video parameters like
VideoParametersPresets.h720_169
(which is 1280x720 at 30fps with a 450 kbps bitrate) for a great balance of quality and performance. • Room Configuration: Make sure to enable adaptive streaming and dynacast in `RoomOptions`—this helps keep your video smooth even if the network gets a bit shaky:
Copy code
final roomOptions = RoomOptions(
  adaptiveStream: true,
  dynacast: true,
);
Video Track Publishing: When creating and publishing your video tracks, use
LocalVideoTrack
with these settings to get things just right:
Copy code
final videoTrack = await LocalVideoTrack.createCameraTrack(
  options: CameraCaptureOptions(
    cameraPosition: CameraPosition.front,
    params: VideoParameters(
      dimensions: VideoDimensions(1280, 720),
      encoding: VideoEncoding(
        maxBitrate: 450 * 1000,
        maxFramerate: 30,
      ),
    ),
  ),
);
await room.localParticipant.publishVideoTrack(videoTrack);
Platform-Specific Configurations: For iOS, don’t forget to update your
Info.plist
with camera and microphone usage descriptions. On Android, make sure your
AndroidManifest.xml
includes permissions for camera and audio. • Screen Sharing: If you’re adding screen sharing, use
ScreenShareCaptureOptions
with optimized settings like
VideoParametersPresets.screenShareH720FPS15
to keep things smooth. • Audio Configuration: Use the
communication
audio mode—it’s perfect for two-way voice chats. • Performance Considerations: To get the best encoding settings based on the device and network, try using
computeVideoEncodings
. These tweaks should help your app deliver awesome video quality and performance. If you have any questions or want to dive deeper, just let me know—I’m here to help! Sources: Swift & iOS SDK | livekit/livekit_composite | DeepWiki | lib/src/utils.dart
f
i want code for Flutter
t
Here’s a handy little code snippet to help you set up live video in your Flutter app using LiveKit:
Copy code
import 'package:livekit_client/livekit_client.dart';

void main() async {
  // Connect to the LiveKit server
  final room = await LiveKit.connect(
    'YOUR_SERVER_URL',
    'YOUR_ACCESS_TOKEN',
    roomOptions: RoomOptions(
      adaptiveStream: true,
      dynacast: true,
    ),
  );

  // Create and publish a video track
  final videoTrack = await LocalVideoTrack.createCameraTrack(
    options: CameraCaptureOptions(
      cameraPosition: CameraPosition.front, // Use front or back camera
      params: VideoParameters(
        dimensions: VideoDimensions(1280, 720), // 720p resolution
        encoding: VideoEncoding(
          maxBitrate: 450 * 1000, // 450 kbps
          maxFramerate: 30, // 30 fps
        ),
      ),
    ),
  );

  await room.localParticipant.publishVideoTrack(videoTrack);

  // Handle room events
  room.onParticipantConnected = (participant) {
    print('Participant connected: ${participant.identity}');
  };

  room.onParticipantDisconnected = (participant) {
    print('Participant disconnected: ${participant.identity}');
  };
}
Just swap out
YOUR_SERVER_URL
and
YOUR_ACCESS_TOKEN
with your actual LiveKit server URL and access token. This setup connects you to the server, turns on adaptive streaming, and publishes a crisp 720p video track using your front camera. If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
f
Give me full settings to work awesome for Android and IOS in flutter
t
Hey there! Here’s a friendly and thorough setup guide to help you get the best live video performance in Flutter for both Android and iOS using LiveKit: • General Video Configuration: You can start by using these handy predefined video parameters for common resolutions and bitrates:
Copy code
VideoParametersPresets.h720_169 // 1280x720 @ 30fps, 450 kbps bitrate
VideoParametersPresets.h1080_169 // 1920x1080 @ 30fps, 3 Mbps bitrate
Room Configuration: To boost performance, enable adaptive streaming and dynacast like this:
Copy code
final roomOptions = RoomOptions(
  adaptiveStream: true,
  dynacast: true,
);
Video Track Publishing: Here’s how to set up and publish a video track with optimal settings:
Copy code
final videoTrack = await LocalVideoTrack.createCameraTrack(
  options: CameraCaptureOptions(
    cameraPosition: CameraPosition.front, // or CameraPosition.back
    params: VideoParameters(
      dimensions: VideoDimensions(1280, 720),
      encoding: VideoEncoding(
        maxBitrate: 450 * 1000, // 450 kbps
        maxFramerate: 30, // 30 fps
      ),
    ),
  ),
);
await room.localParticipant.publishVideoTrack(videoTrack);
Platform-Specific Configurations:iOS: Don’t forget to add these keys to your
Info.plist
to keep things smooth:
Copy code
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses your camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses your microphone</string>
• Also, make sure to enable the "Audio, AirPlay, and Picture in Picture" background mode in Xcode. • Android: Add these permissions to your `AndroidManifest.xml`:
Copy code
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
• If you’re using Bluetooth audio devices, don’t forget to request Bluetooth permissions too. • Screen Sharing: For screen sharing, use these optimized settings:
Copy code
final screenShareTrack = await LocalVideoTrack.createScreenShareTrack(
  options: ScreenShareCaptureOptions(
    params: VideoParametersPresets.screenShareH720FPS15,
  ),
);
Audio Configuration: To get clear two-way voice communication, use the
communication
audio mode like this:
Copy code
await webrtc.WebRTC.initialize(options: {
  'androidAudioConfiguration': webrtc.AndroidAudioConfiguration.communication.toMap(),
});
Focus and Exposure: You can configure the camera focus and exposure modes for the best video quality:
Copy code
CameraCaptureOptions(
  focusMode: CameraFocusMode.auto,
  exposureMode: CameraExposureMode.auto,
);
Performance Considerations: It’s a great idea to automatically adjust encoding settings based on the device and network conditions, like this:
Copy code
var encodings = Utils.computeVideoEncodings(
  isScreenShare: track.source == TrackSource.screenShareVideo,
  dimensions: dimensions,
  options: publishOptions,
  codec: publishOptions.videoCodec,
);
Testing: Finally, try testing your app on different devices with varying hardware capabilities. For older devices, lowering the video resolution and framerate can really help keep things smooth. By following these tips, your app will deliver awesome video quality and smooth performance on both Android and iOS. If you run into any questions or need a hand, just let me know—I’m here to help!
f
Give me best settings for android too in flutter
t
Hey there! Here are some of the best settings to help you get the most out of live video in Flutter on Android using LiveKit: • General Video Configuration: Try using these predefined video parameters for Android to keep things smooth:
Copy code
VideoParametersPresets.h720_169 // 1280x720 @ 30fps, 450 kbps bitrate
VideoParametersPresets.h1080_169 // 1920x1080 @ 30fps, 3 Mbps bitrate
Room Configuration: For better performance, it’s great to enable adaptive streaming and dynacast:
Copy code
final roomOptions = RoomOptions(
  adaptiveStream: true,
  dynacast: true,
);
Video Track Publishing: Here’s how to set up and publish a video track with the best settings:
Copy code
final videoTrack = await LocalVideoTrack.createCameraTrack(
  options: CameraCaptureOptions(
    cameraPosition: CameraPosition.front, // or CameraPosition.back
    params: VideoParameters(
      dimensions: VideoDimensions(1280, 720),
      encoding: VideoEncoding(
        maxBitrate: 450 * 1000, // 450 kbps
        maxFramerate: 30, // 30 fps
      ),
    ),
  ),
);
await room.localParticipant.publishVideoTrack(videoTrack);
Android-Specific Configurations: • Don’t forget to add these permissions to your `AndroidManifest.xml`:
Copy code
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
• If you’re using Bluetooth audio devices, make sure to request those permissions too. • Audio Configuration: For clear two-way voice communication, use the
communication
audio mode like this:
Copy code
await webrtc.WebRTC.initialize(options: {
  'androidAudioConfiguration': webrtc.AndroidAudioConfiguration.communication.toMap(),
});
Screen Sharing: When sharing your screen, these optimized settings will help:
Copy code
final screenShareTrack = await LocalVideoTrack.createScreenShareTrack(
  options: ScreenShareCaptureOptions(
    params: VideoParametersPresets.screenShareH720FPS15,
  ),
);
Focus and Exposure: It’s a good idea to configure your camera’s focus and exposure modes like this:
Copy code
CameraCaptureOptions(
  focusMode: CameraFocusMode.auto,
  exposureMode: CameraExposureMode.auto,
);
Performance Considerations: To get the best encoding based on the device and network, you can automatically compute settings like this:
Copy code
var encodings = Utils.computeVideoEncodings(
  isScreenShare: track.source == TrackSource.screenShareVideo,
  dimensions: dimensions,
  options: publishOptions,
  codec: publishOptions.videoCodec,
);
These tips are tailored for Android to help you get the best video quality and performance. If you want to chat more or need a hand with anything else, just let me know!
f
Give me best VideoDimensions
t
Hey there! Here are some recommended video dimensions for live video in Flutter using LiveKit that should help you get the best quality: • 16:9 Aspect Ratio: • `h90_169`: 160x90 • `h180_169`: 320x180 • `h216_169`: 384x216 • `h360_169`: 640x360 • `h540_169`: 960x540 • `h720_169`: 1280x720 • `h1080_169`: 1920x1080 • `h1440_169`: 2560x1440 • `h2160_169`: 3840x2160 • 4:3 Aspect Ratio: • `h120_43`: 160x120 • `h180_43`: 240x180 • `h240_43`: 320x240 • `h360_43`: 480x360 • `h480_43`: 640x480 • `h540_43`: 720x540 • `h720_43`: 960x720 • `h1080_43`: 1440x1080 • `h1440_43`: 1920x1440 These dimensions come from the
VideoDimensionsPresets
class, and you can pair them with
VideoParametersPresets
to get the best results. For instance, using
h720_169
(1280x720) is a great choice for high-quality video streaming. If you want, I’m here to help with more details or examples—just let me know!
f
i mean for now i set
Copy code
dimensions: VideoDimensions(1280, 720),
encoding: VideoEncoding(
  maxBitrate: 450 * 1000, // 450 kbps
  maxFramerate: 60, // 30 fps
),
i want to be high resolution
t
If you want to get a sharper, clearer video, you can tweak the dimensions and encoding settings like this:
Copy code
dimensions: VideoDimensions(1920, 1080), // Full HD resolution
encoding: VideoEncoding(
  maxBitrate: 3000 * 1000, // 3 Mbps for higher quality
  maxFramerate: 60, // 60 fps for smoother video
),
This setup bumps your video to 1920x1080 (Full HD) with a nice 3 Mbps bitrate and a max framerate of 60 fps, which should give you smoother, better-looking video. Just double-check that your network and device can keep up with these settings so everything runs smoothly. If you have any questions or want me to walk you through it, just let me know—I’m here to help!