HLS first user issue

Hi,

I m publishing the streams to origin servers and playing using HLS by edge servers. When a first user tries to view the stream, the stream can't be played in player and buffer gets stalled out.

If it is played again, then streams gets played. Based on this link https://docs.flashphoner.com/display/WCS52EN/In+a+browser+via+HLS#InabrowserviaHLS-Issues,
I configured below thing in edge servers,
hls_min_list_size=2
but still the first user issue still happens.

Any fix for this?
 
I have the same issue.
Our workarround was starting HLS by API one page before the first user access the player, like into a login screen.
 
Code:
    $data_array_a = array(
        
                        "name" => $player_id
                        
                         );


    $data_string = json_encode($data_array_a);//
    $ch = curl_init($api_url_server."/rest-api/hls/startup");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    //print_r($result);
    curl_close($ch);
 
Today we test few settings regarding CDN Profiles and notice if streamname requested by HLS is the same as profile on CDN transcoder, starting by API is not needed and first error not happen.
 

Max

Administrator
Staff member
Good day.
When a first user tries to view the stream, the stream can't be played in player and buffer gets stalled out.
Please check if HLS preloader is enabled
Code:
hls_preloader_enabled=true
Also, a stream published should provide a stable FPS and even keyframes flow. FPS for WebRTC publishing is set on client side:
Code:
    session.createStream({
        name: streamName,
        display: localVideo,
        cacheLocalResources: true,
        constraints: {
              video: {
                    frameRate: 30
              }
        }
        ...
    }).publish();
Regular keyframe (FIR) requests are set up on server side
Code:
periodic_fir_request = true
periodic_fir_request_interval = 2000
rtcp_pli_request_interval = 2000
In this case, server will request browser to send keyframe every 2 seconds. More often keyframe sending is not recommended because publisher channel may be overloaded due to bog amount of data passed.
Today we test few settings regarding CDN Profiles and notice if streamname requested by HLS is the same as profile on CDN transcoder, starting by API is not needed and first error not happen.
Yes, transcoding helps to equalize FPS and to receive keyframes regularly on players side. For example, this profile
YAML:
 -360p:
  video:
    height : 360
    bitrate : 400
    gop : 50
    codec : h264
    codecImpl : FF
provides keyframe every 2 seconds for 25 fps
and the following Transcoder server settings
Code:
video_filter_enable_fps=true
video_filter_fps=25
video_filter_fps_gop_synchronization=50
provide 25 FPS for streams transcoded
So HLS should play smoothly. HLS warming as Rafael do is not necessary if transcoding is used and preloader enabled on Edge servers.
 
Hello!

provide 25 FPS for streams transcoded
So HLS should play smoothly. HLS warming as Rafael do is not necessary if transcoding is used and preloader enabled on Edge servers.
Confirmed and very happy.
CND profiles works like a charm and not necessary to start by API, just removed it from our code.

Thanks Max!
 
@Max to use CDN profiles, do we need to use separate servers?
My streaming setup uses Origin and Edge servers where WebRTC is pusblished to Origin server and stream is viewed using HLS from Edge servers.
https://docs.flashphoner.com/display/WCS52EN/CDN+2.0

Is that fine to setup those CDN profiles in Edge servers?

Also @Rafael Ribeiro I have tried to start the HLS agent in my Edge servers after publishing the stream in origin servers but it not fixing the HLS first user issue.
I think since stream is published on origin, it is not possible to start the HLS agent in edge servers. right @Max
 
@manikandan did you setup cdn_profiles file on edge?
How are u calling the stream? It should be something like streamname-720p.m3mu
No. I haven't setup cdn_profiles on edge. I just want to start the HLS agent by using the REST API (hls/start_up) in edge servers. But it is not working.
Just to confirm, is separate transcoder server is required to call that API?
 
PHP:
$data_array_a = array(
    
    "name" => $webrtcstreamname
                
);


$data_string = json_encode($data_array_a);//
$ch = curl_init("https://yourwcsserver:8444/rest-api/hls/startup");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
//print_r($result);
curl_close($ch);
Then you can open your stream into HLS player


If you decides use CDN profiles, just open stream like this:
 

Max

Administrator
Staff member
So a separate server has to be used for trancoding process for this HLS first user issue. right?
A separate Transcoder server is necessary to use CDN transcoding profiles like this
Code:
https://edge:8445/test-480p/test-480p.m3u8
I just want to start the HLS agent by using the REST API (hls/start_up) in edge servers. But it is not working.
Let's clarify again.
To play WebRTC stream as HLS smoothly, there must be regular keyframes flow in the stream, and regular FPS.
HLS segments are cut by keyframe, so if keyframe is not received in, for example, 20 seconds, HLS will not be started until keyframe is received, and preloader will roll (if used) during this 20 seconds. And, when HLS segment is started, it will be written until the next keyframe is received even if fixed segment size is set.
And this behavior will be the same whatever you use to start HLS playback REST API /hls/startup or curl invocation. So HLS warming (preliminary HLS requesting on edge server before subscribers connect) can help to reduce playback starting delay for subscribers, but does not help to play smoothly.
Also HLS segments are written frame by frame, so, if FPS drops, there will be freezes while playing HLS.
That's why transcoding may be useful to play WebRTC as HLS.
But, if you decide to use CDN transcoding profiles, you should deploy Transcoder servers to CDN or allow transcoding on Origin (so, Origin should be powerful enough to do this) by setting the following parameter on Edge server
Code:
cdn_origin_allowed_to_transcode=true
Then you can open your stream into HLS player
https://yourwcsserver:8445/streamname/streamname.m3u8
This is HLS warming example. You can use simple curl request without REST API, the result will be the same: HLS cut will start if the stream is available
PHP:
$ch = curl_init("https://yourwcsserver:8445/".$webrtcstreamname."/".$webrtcstreamname."m3u8");
 
PHP:
$data_array_a = array(
   
    "name" => $webrtcstreamname
               
);


$data_string = json_encode($data_array_a);//
$ch = curl_init("https://yourwcsserver:8444/rest-api/hls/startup");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
//print_r($result);
curl_close($ch);
Then you can open your stream into HLS player


If you decides use CDN profiles, just open stream like this:
Thank you @Rafael Ribeiro
 
A separate Transcoder server is necessary to use CDN transcoding profiles like this
Code:
https://edge:8445/test-480p/test-480p.m3u8
Let's clarify again.
To play WebRTC stream as HLS smoothly, there must be regular keyframes flow in the stream, and regular FPS.
HLS segments are cut by keyframe, so if keyframe is not received in, for example, 20 seconds, HLS will not be started until keyframe is received, and preloader will roll (if used) during this 20 seconds. And, when HLS segment is started, it will be written until the next keyframe is received even if fixed segment size is set.
And this behavior will be the same whatever you use to start HLS playback REST API /hls/startup or curl invocation. So HLS warming (preliminary HLS requesting on edge server before subscribers connect) can help to reduce playback starting delay for subscribers, but does not help to play smoothly.
Also HLS segments are written frame by frame, so, if FPS drops, there will be freezes while playing HLS.
That's why transcoding may be useful to play WebRTC as HLS.
But, if you decide to use CDN transcoding profiles, you should deploy Transcoder servers to CDN or allow transcoding on Origin (so, Origin should be powerful enough to do this) by setting the following parameter on Edge server
Code:
cdn_origin_allowed_to_transcode=true
This is HLS warming example. You can use simple curl request without REST API, the result will be the same: HLS cut will start if the stream is available
PHP:
$ch = curl_init("https://yourwcsserver:8445/".$webrtcstreamname."/".$webrtcstreamname."m3u8");
Thank you Max for the explanation. Will check on that.
 
Top