Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video quality degradation after upgrading LiveKit libraries #1224

Open
quoctuanck99 opened this issue Dec 13, 2024 · 4 comments
Open

Video quality degradation after upgrading LiveKit libraries #1224

quoctuanck99 opened this issue Dec 13, 2024 · 4 comments
Labels
question Further information is requested

Comments

@quoctuanck99
Copy link

I tried updating the livekit-agents library and some related libraries (such as livekit, livekit-api, livekit-plugins-deepgram) to their latest versions. Here are the old and new versions:
Old versions:

livekit==0.17.4
livekit-agents==0.10.0
livekit-api==0.6.0
livekit-plugins-deepgram==0.6.7

New versions:

livekit==0.18.2
livekit-agents==0.12.2
livekit-api==0.8.0
livekit-plugins-deepgram==0.6.14

After upgrading, we encountered an issue where the video stream quality deteriorated. The video now has lower resolution and a reduced frame rate.

With the old library versions, the video output was 540x960 resolution at 25 fps, which met our expectations. However, with the new versions, the resolution has dropped to 180x320 and the frame rate to 15 fps. Below is a comparison:

video output analytics result
old libraries Screenshot 2024-12-13 at 11 07 33 AM Screenshot 2024-12-13 at 11 18 00 AM
new libraries Screenshot 2024-12-13 at 11 30 42 AM Screenshot 2024-12-13 at 11 30 42 AM

My application was initially based on this example, but instead of using color, we are publishing video and we are using livekit cloud server.
https://github.com/user-attachments/assets/8f46fddb-f5c0-4a23-916f-cbd2316403f8

Is there a reason for this difference in video quality with the new versions? If so, is there a way to restore the previous resolution and frame rate?

We cannot proceed with the latest version until this is resolved.
Thank you for your help!

@quoctuanck99 quoctuanck99 added the question Further information is requested label Dec 13, 2024
@quoctuanck99 quoctuanck99 changed the title Video Quality Degradation After Upgrading LiveKit Libraries Video quality degradation after upgrading LiveKit libraries Dec 13, 2024
@quoctuanck99
Copy link
Author

@theomonnom could you please help with this?

@theomonnom
Copy link
Member

Hey, we're going to take a look at this this week

@davidzhao
Copy link
Member

@quoctuanck99 are you able to reproduce this with our example apps? and could you share the publish parameters?

@quoctuanck99
Copy link
Author

quoctuanck99 commented Dec 19, 2024

@davidzhao Thanks you for your reply. Here is an example code snippet that demonstrates the issue:

import asyncio
import logging
import cv2

from dotenv import load_dotenv
from livekit import rtc
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.rtc import VideoCodec

# Load environment variables
load_dotenv()

WIDTH = 540
HEIGHT = 960


async def entrypoint(job: JobContext):
    await job.connect()

    room = job.room
    source = rtc.VideoSource(WIDTH, HEIGHT)
    track = rtc.LocalVideoTrack.create_video_track("single-color", source)
    options = rtc.TrackPublishOptions(
        source=rtc.TrackSource.SOURCE_CAMERA, video_codec=VideoCodec.VP9
    )
    publication = await room.local_participant.publish_track(track, options)
    logging.info("published track", extra={"track_sid": publication.sid})
    video_capture = cv2.VideoCapture("./source.mp4")

    async def _publish_video():
        argb_frame = bytearray(WIDTH * HEIGHT * 4)
        while True:
            await asyncio.sleep(0.04)  # 100ms
            ret, frame = video_capture.read()
            if not ret:
                video_capture.set(cv2.CAP_PROP_POS_FRAMES, 0)
                _, frame = video_capture.read()
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            frame = rtc.VideoFrame(WIDTH, HEIGHT, rtc.VideoBufferType.RGB24, frame)
            source.capture_frame(frame)

    await _publish_video()


if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
source.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants