Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Guide: How to discover the latency issue. #2742

Closed
dzhcool opened this issue Nov 17, 2021 · 0 comments
Closed

Guide: How to discover the latency issue. #2742

dzhcool opened this issue Nov 17, 2021 · 0 comments
Assignees
Labels
Discussion Discussion or questions. EnglishNative This issue is conveyed exclusively in English. Won't fix We won't fix it.
Milestone

Comments

@dzhcool
Copy link

dzhcool commented Nov 17, 2021

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

@winlinvip winlinvip self-assigned this Nov 18, 2021
@winlinvip winlinvip added Discussion Discussion or questions. Won't fix We won't fix it. labels Nov 18, 2021
@winlinvip winlinvip added this to the Future milestone Nov 18, 2021
@winlinvip winlinvip changed the title 关于如何测试延迟问题整理 Guide: 关于如何测试延迟问题整理 Nov 18, 2021
@winlinvip winlinvip changed the title Guide: 关于如何测试延迟问题整理 Guide: How to discover the latency issue. 关于如何排查延迟问题。 Nov 18, 2021
@winlinvip winlinvip changed the title Guide: How to discover the latency issue. 关于如何排查延迟问题。 Guide: How to discover the latency issue. Jul 18, 2023
@ossrs ossrs locked and limited conversation to collaborators Jul 18, 2023
@winlinvip winlinvip converted this issue into discussion #3681 Jul 18, 2023
@winlinvip winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jul 29, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Discussion Discussion or questions. EnglishNative This issue is conveyed exclusively in English. Won't fix We won't fix it.
Projects
None yet
Development

No branches or pull requests

2 participants