worried-alarm-18251
12/06/2025, 11:24 AMtall-airline-16756
12/06/2025, 11:25 AMtall-airline-16756
12/06/2025, 11:25 AMworried-alarm-18251
12/06/2025, 11:26 AMtall-airline-16756
12/06/2025, 11:26 AMnavigator.mediaDevices.getUserMedia or a native bridge that injects frames?
3. How do you render the feed for tracking/display — a <video> element, a <canvas> with drawn frames, or passing ImageBitmap/frames directly to the model?
4. Is the rotated video appearing only in the local preview, only on the tracked output (overlays/coordinates), or on remote/recorded streams as well?
5. Can you apply CSS transforms or modify the video/canvas dimensions in the WebView?
6. If possible, share the video track constraints you use (width/height/aspectRatio/facingMode) or a short snippet of how you start the camera.
Answering these will let me give concise steps (CSS/transform, canvas coordinate rotation, or preprocessing frames) tailored to your setup.
Sources: Codecs and more | LiveKit docsworried-alarm-18251
12/06/2025, 11:28 AMtall-airline-16756
12/06/2025, 11:28 AM<canvas> that sits over the video element, or does the tracker read frames directly from the video element?
If you want an immediate, common fix (rotate the preview and keep overlays consistent), try this approach:
1. Detect orientation and apply a CSS transform to the attached video element.
◦ After const videoEl = videoTrack.attach(); add:
videoEl.style.transformOrigin = 'center center';
// Example: rotate 90deg for landscape
videoEl.style.transform = 'rotate(90deg)';
// adjust size after rotation
videoEl.style.width = '240px';
videoEl.style.height = '135px'; // tweak to preserve aspect ratio
• For dynamic orientation changes, listen for orientationchange or window.resize and update videoEl.style.transform accordingly.
1. If you use a canvas overlay for hand tracking, rotate the canvas drawing context to match the video transform so coordinates align:
// assuming ctx is 2D canvas context
ctx.save();
// translate to center, rotate, then draw
ctx.translate(canvas.width/2, canvas.height/2);
ctx.rotate(Math.PI / 2); // 90deg
ctx.translate(-canvas.height/2, -canvas.width/2);
ctx.drawImage(videoEl, 0, 0, canvas.height, canvas.width);
ctx.restore();
• Swap width/height when rotating 90/270 degrees.
1. If the camera feed is physically rotated by the WebView/native layer (not just display), prefer rotating frames before sending/publishing:
◦ Capture into a canvas, rotate/draw the correct orientation, then create a new MediaStream from the canvas (canvas.captureStream()) and publish that track instead of the raw camera track.
1. Optional: constrain getUserMedia to a matching aspect ratio to reduce post-rotation resizing:
navigator.mediaDevices.getUserMedia({ video: { width: 1280, height: 720 } })
If you tell me whether you need local vs remote rotation and whether you use a canvas overlay or direct-frame input to the tracker, I’ll provide a tailored snippet you can drop into your code (including dynamic orientation handling inside your WebView).worried-alarm-18251
12/06/2025, 11:28 AMtall-airline-16756
12/06/2025, 11:28 AMconst videoEl = videoTrack.attach();
videoEl.autoplay = true;
videoEl.muted = true;
videoEl.playsInline = true;
videoEl.style.width = '240px';
videoEl.style.borderRadius = '12px';
videoEl.style.transformOrigin = 'center center';
// set initial rotation (0, 90, 180, or 270)
function applyRotation(deg) {
videoEl.style.transform = `rotate(${deg}deg)`;
// swap dimensions if rotated 90/270
if (deg % 180 !== 0) {
videoEl.style.width = '135px';
videoEl.style.height = '240px';
} else {
videoEl.style.width = '240px';
videoEl.style.height = '135px';
}
}
// example: landscape rotated 90°
applyRotation(90);
$("#vidOverlayAudio").append(videoEl);
2) Handle dynamic changes (orientationchange/resize)
function getDeviceRotation() {
// try Screen Orientation API, fallback to window.orientation if available
if (screen.orientation && screen.orientation.angle !== undefined) return screen.orientation.angle;
return (window.orientation !== undefined) ? window.orientation : 0;
}
function updateRotation() {
const angle = getDeviceRotation();
applyRotation(angle);
}
window.addEventListener('orientationchange', updateRotation);
window.addEventListener('resize', updateRotation);
updateRotation();
3) If you use a canvas overlay for hand-tracking (keeps coordinates aligned)
• Draw the rotated video into the canvas and run the tracker on that canvas/frame:
const canvas = document.getElementById('trackCanvas');
const ctx = canvas.getContext('2d');
function drawRotated() {
const angleRad = (getDeviceRotation() * Math.PI) / 180;
// set canvas size depending on rotation
if (Math.abs(angleRad - Math.PI/2) < 0.1 || Math.abs(angleRad - 3*Math.PI/2) < 0.1) {
canvas.width = videoEl.videoHeight;
canvas.height = videoEl.videoWidth;
} else {
canvas.width = videoEl.videoWidth;
canvas.height = videoEl.videoHeight;
}
ctx.save();
// move to center, rotate, draw, restore
ctx.translate(canvas.width/2, canvas.height/2);
ctx.rotate(angleRad);
ctx.drawImage(videoEl, -videoEl.videoWidth/2, -videoEl.videoHeight/2);
ctx.restore();
requestAnimationFrame(drawRotated);
}
videoEl.addEventListener('loadedmetadata', () => requestAnimationFrame(drawRotated));
• Run your hand-tracking on the canvas (or read ImageBitmap from canvas) so overlay coordinates match the rotated pixels.
4) If the WebView/native layer delivers frames already rotated
• Instead of publishing the raw camera track, capture the canvas stream after rotating and publish that:
const rotatedStream = canvas.captureStream(30);
const rotatedTrack = rotatedStream.getVideoTracks()[0];
// publish rotatedTrack instead of original track
await room.localParticipant.publishTrack(new LocalVideoTrack(rotatedTrack));
Which of these do you want as a final snippet to insert into your existing functions: (A) CSS-only preview rotation, (B) canvas + tracker alignment, or (C) capture-and-publish rotated stream? I’ll give the exact lines to merge into your CreateTracksOnSuccess/ConnectToLiveKit flow.worried-alarm-18251
12/06/2025, 1:23 PMtall-airline-16756
12/06/2025, 1:23 PMVideoPresets.h360 resolution is 640 (width) × 360 (height).
Sources: Codecs and more | LiveKit docsworried-alarm-18251
12/10/2025, 11:38 AMtall-airline-16756
12/10/2025, 11:38 AMconst videoEl = videoTrack.attach();
videoEl.autoplay = true;
videoEl.muted = true;
videoEl.playsInline = true;
videoEl.className = 'video-preview';
$("#vidOverlayAudio").append(videoEl);
CSS:
.video-preview {
width: 240px;
height: 135px;
object-fit: cover;
border-radius: 12px;
}
2) Reduce capture resolution (lowers bandwidth) — use preset Use LiveKit preset VideoPresets.h360 (640×360):
import { createLocalVideoTrack, VideoPresets } from 'livekit-client';
const track = await createLocalVideoTrack({
resolution: VideoPresets.h360.resolution, // 640x360
});
await room.localParticipant.publishTrack(track);
Or set defaults on Room:
const room = new Room({ videoCaptureDefaults: { resolution: VideoPresets.h360.resolution } });
3) Custom resolution + encoding (fine control)
const track = await createLocalVideoTrack({
resolution: { width: 480, height: 270, frameRate: 24 },
});
await room.localParticipant.publishTrack(track, {
videoEncoding: { maxBitrate: 400_000, maxFramerate: 24 },
});
4) AdaptiveStream (automatic optimization) Enable adaptive stream so LiveKit chooses suitable layer based on element size:
const room = new Room({ adaptiveStream: true });
Ensure you attach the track to an element (track.attach(element)) so adaptive sizing works.
Which do you want to apply: (A) CSS-only preview, (B) preset (VideoPresets.h360), (C) custom resolution/bitrate, or (D) adaptiveStream? I’ll give the exact lines to merge into your existing CreateTracksOnSuccess/ConnectToLiveKit flow.
Sources: Subscribing to tracks | LiveKit docs | Codecs and more | LiveKit docs | Configuring the Client SDK for Optimal Video Quality | Bringing Zoom's end-to-end optimizations to WebRTCworried-alarm-18251
12/10/2025, 11:40 AMtall-airline-16756
12/10/2025, 11:40 AMcreateLocalTracks and keep your roomOptions as-is. Example:
import { createLocalTracks, VideoPresets } from 'livekit-client';
// room options (keep as you have)
const roomOptions = {
adaptiveStream: true,
dynacast: true,
videoCaptureDefaults: {
resolution: VideoPresets.h360.resolution,
},
};
// create tracks with audio constraints
const localTracks = await LivekitClient.createLocalTracks({
audio: {
echoCancellation: true,
noiseSuppression: true,
// optional: automatic gain control
autoGainControl: true,
},
video: true,
});
Notes:
• These map to standard getUserMedia constraints and will be applied when capturing the microphone in the browser/WebView.
• If you need different audio constraints per-track, create the audio track separately using createLocalAudioTrack({ ... }) and publish it.