Skip to content

Guide: How to discover the latency issue. #2742

Description

@dzhcool

This article describes how to troubleshoot high latency, with the main steps as follows:

  1. Start SRS in low latency mode, refer to v4_CN_SampleRealtime or v4_EN_SampleRealtime.
  2. Write timestamps to the video stream using the method described below.
  3. Open the player to play streams from different links and compare the latency.

Note: Latency is a difficult issue. Don't start with random attempts and follow the documentation step by step to create a low-latency environment. For WebRTC, refer to #307. For live streaming, refer to v4_CN_SampleRealtime or v4_EN_SampleRealtime.

Note: If you can't achieve low latency following the documentation, it's because each link can cause latency. You need to be able to analyze the problem yourself. This article provides a method to troubleshoot latency using timestamps.

FFmpeg

You can use FFmpeg to capture local time and write it to the video stream. This way, you can compare the images from different links to determine where the latency is.

You can use FFmpeg filters to achieve this. For specific filter parameters, please refer to FFmpeg.org:

-vf drawtext="fontfile=arial.ttf:text='%{localtime\:%X}':x=10:y=10:fontsize=40:fontcolor=white"

For example, a specific example:

ffmpeg -re -stream_loop -1 -threads 6 -i doc/source.flv \
    -c:a copy -c:v libx264 -b:v 1800k -tune zerolatency -g 25 -bf 0 -preset fast \
    -vf drawtext="fontfile=arial.ttf:text='%{localtime\:%X}':x=10:y=10:fontsize=40:fontcolor=white" \
    -f flv "rtmp://localhost/live/livestream"

Open the player: http://localhost:8080/players/srs_player.html?autostart=true

time2

OBS Stopwatch

Open a stopwatch webpage in your browser, capture the browser window with OBS, and observe the difference between the stopwatch numbers in the streaming video and the stopwatch browser.

For example, a stopwatch page, timeanddate, there are two ways to capture:

  • Use Window Capture to directly capture the browser window.
  • Use OBS's Browser to open the page in OBS's browser, and click Interact to start the stopwatch.

142176119-04bf11f0-8775-448d-941d-c9becc823574

After capturing in OBS, you can crop the window by holding down ALT or Option and dragging the window for quick cropping.

OBS Device

Capture video with OBS video capture device

You need to add a timer or time to the OBS source. There are many ways to do this, such as using a Lua script or a browser implementation, etc. For example, a web page clock implementation, add a new browser in OBS source, and enter the URL (web page parameter description):

https://gists.rawgit.com/sam0737/a0ee8ca253fc5c84b2aa2ac018f7b8ad/raw/108196e17c2c9d79ff60ed3bf788973ab94da9af/clock.html?format=YYYY-MM-DD%20HH:mm:ss&style=font-weight:bold;font-size:80px;color:lightgray;display:inline-block;border-radius:5px;padding:2px%205px;background-color:rgba(0,0,0,0.5)

Don't worry about custom CSS, the web page style in this example is passed through the get parameter style.

Note: Test the URL in Chrome or another browser first to debug the style, then copy it to the OBS browser source URL input box, otherwise, it may cause problems.

142183444-4d0f7ebe-31aa-4b66-b067-fe9ceb26dbb0

Activity

  1. self-assigned this
    on Nov 18, 2021
  2. added this to the Future milestone on Nov 18, 2021
  3. changed the title [-]关于如何测试延迟问题整理[/-] [+]Guide: 关于如何测试延迟问题整理[/+] on Nov 18, 2021
  4. changed the title [-]Guide: 关于如何测试延迟问题整理[/-] [+]Guide: How to discover the latency issue. 关于如何排查延迟问题。[/+] on Nov 18, 2021
  5. changed the title [-]Guide: How to discover the latency issue. 关于如何排查延迟问题。[/-] [+]Guide: How to discover the latency issue.[/+] on Jul 18, 2023
  6. locked and limited conversation to collaborators on Jul 18, 2023
  7. converted this issue into a discussionon Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DiscussionDiscussion or questions.EnglishNativeThis issue is conveyed exclusively in English.Won't fixWe won't fix it.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions