how hand track orientation, my device is in landsc...
# ask-ai
w
how hand track orientation, my device is in landscape mode, i m getting rotate video
t
Thanks for reaching out, Ajay. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're seeing rotated video when using hand tracking in landscape — I can help. A few quick clarifying questions so I can give the right steps: 1. Which platform/app are you using for hand tracking (iOS, Android, web, or a specific app like PitchVantage)? 2. Are you using a LiveKit SDK or a third‑party hand‑tracking library? If an SDK, which version? 3. How are you capturing/feeding the camera frames (native camera API, getUserMedia, or a processed video stream)? 4. Is the video physically rotated on the device camera output, or only rotated after you send/receive it (local preview vs remote)? 5. Do you want the tracking coordinates rotated to match landscape, or just the displayed video rotated? With those details I’ll provide concise steps (camera rotation transforms, canvas/image orientation fix, or SDK config) suited to your setup.
w
web, on device using webview
t
Thanks — got that you're on web inside a WebView. A few focused questions to pinpoint the fix: 1. Which hand-tracking library are you using (MediaPipe Hands, TensorFlow.js, or a custom solution)? 2. How is the camera feed acquired in the WebView —
navigator.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 docs
w
async function CreateTracksOnSuccess() { allTrack = await LivekitClient.createLocalTracks({ audio: true, video: true }); const videoTrack = allTrack.find(t => t.kind === 'video'); if (videoTrack) { const videoEl = videoTrack.attach(); videoEl.autoplay = true; videoEl.muted = true; videoEl.playsInline = true; videoEl.style.width = '240px'; videoEl.style.borderRadius = '12px'; $("#vidOverlayAudio").append(videoEl); //console.log('📹 Local video preview added.'); } for (const track of allTrack) { await room.localParticipant.publishTrack(track); } $("#prompt-details").text(payloaddata.rolePlaydata.promts); $("#scenario-details").text(scenario); $("#loadingMsg").text('Agent Connecting ....') setProgress(0, '#38A06C', 0,payloaddata.rolePlaydata.Duration); recordingTimer = new TimerUI(); SendCallBackStartSession(); await SendPromptAndScenaroi() } function ConnectToLiveKit(onconnectionSuccess) { const token = payloaddata.token; const url = payloaddata.wsurl; // creates a new room with options room = new Room(roomOptions); console.log(token); console.log(url) // pre-warm connection, this can be called as early as your page is loaded room.prepareConnection(url, token); SetupRoomListner(); SetupMsgListner(); try { room.connect(url, token,connectOptions) .then(function () { console.log('✅ Connected to LiveKit room:', room.name); room.localParticipant.enableCameraAndMicrophone() .then(function () { console.log('🎥 Camera and Mic enabled.'); onconnectionSuccess(); }) .catch(function (err) { console.error('❌ Failed to enable camera/mic:', err); }); }) .catch(function (err) { console.error('❌ Connection failed:', err); }); } catch (e) { console.error('❌ Error in ConnectToLiveKit:', e); } } above code, i need to handle orientation
t
Thanks — you're asking how to handle video orientation for the code you shared (web in a WebView). I can help. A couple quick clarifications so I give exact code that fits your setup: 1. Do you need to fix the local preview only, the remote published stream, or both? 2. Are you drawing hand‑tracking overlays on a
<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:
Copy code
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:
Copy code
// 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:
Copy code
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).
w
local
t
You're fixing local preview rotation in a WebView — here are concise, ready-to-use options you can drop into your code. 1) Simple CSS rotate on the attached video (quickest) • After attaching the track, apply transform based on device orientation:
Copy code
const 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)
Copy code
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:
Copy code
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:
Copy code
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.
w
VideoPresets.h360.resolution width height?
t
VideoPresets.h360
resolution is 640 (width) × 360 (height). Sources: Codecs and more | LiveKit docs
w
how reduce the size of video
t
You can reduce video size two ways — change the displayed size (UI) or reduce the actual encoded stream (bandwidth). Pick which you want; below are concise options and exact snippets you can drop into your code. 1) UI-only (CSS) — fastest, no bandwidth change Add after attaching the track:
Copy code
const videoEl = videoTrack.attach();
videoEl.autoplay = true;
videoEl.muted = true;
videoEl.playsInline = true;
videoEl.className = 'video-preview';
$("#vidOverlayAudio").append(videoEl);
CSS:
Copy code
.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):
Copy code
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:
Copy code
const room = new Room({ videoCaptureDefaults: { resolution: VideoPresets.h360.resolution } });
3) Custom resolution + encoding (fine control)
Copy code
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:
Copy code
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&#39;s end-to-end optimizations to WebRTC
w
const localTracks = await LivekitClient.createLocalTracks({ audio: true, video: true, }); and room option this const roomOptions = { adaptiveStream: true, dynacast: true, videoCaptureDefaults: { resolution: VideoPresets.h360.resolution, } }; i want add echoCancellation: true, noiseSuppression: true,
t
You can pass audio constraints into
createLocalTracks
and keep your
roomOptions
as-is. Example:
Copy code
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.