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

For HLS Adaptive Bitrate, add this to HLS docs #1845

Closed
r-t-k opened this issue Jul 9, 2020 · 5 comments
Closed

For HLS Adaptive Bitrate, add this to HLS docs #1845

r-t-k opened this issue Jul 9, 2020 · 5 comments
Assignees
Labels
Codec HEVC, FFmpeg for ingesting, trascoding or codec. TransByAI Translated by AI/GPT. Won't fix We won't fix it.
Milestone

Comments

@r-t-k
Copy link

r-t-k commented Jul 9, 2020

For people how needs this feature: you can realize this now already with srs:

  • prepare your defaultVhost with transcoding:
transcode live/stream {
        enabled     on;
        ffmpeg      /usr/local/bin/ffmpeg;
        engine half {
            enabled         on;
            iformat         live_flv;
            vfilter {
                v           quiet;
            }

            vcodec          libx264;
            vfps            25;
            vwidth          512;
            vheight         288;
            vprofile        main;
            vpreset         medium;

            vparams {
                crf         23;
                x264opts    keyint=50:min-keyint=50:no-scenecut;
                maxrate     650k;
                bufsize     1300k;
            }

            acodec          copy;
            oformat         flv;
            output          rtmp://localhost:1935/live/half;
        }
    }

    hls {
        enabled         on;
        hls_path        /var/www/srs/live;
        hls_fragment    6;
        hls_window      1800;
        hls_cleanup     on;
        hls_dispose     5;
        hls_m3u8_file   [stream]_hq.m3u8;
        hls_ts_file     [stream]_hq-[seq].ts;
    }
  • then add a second vhost for localhost and add there a new hls statement:
    hls {
        enabled         on;
        hls_path        /var/www/srs/live;
        hls_fragment    6;
        hls_window      1800;
        hls_cleanup     on;
        hls_dispose     5;
        hls_m3u8_file   [stream]_lq.m3u8;
        hls_ts_file     [stream]_lq-[seq].ts;
    }
  • then create a master.m3u8:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:15
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2149280,CODECS="mp4a.40.2,avc1.64001f",RESOLUTION=1024x576,NAME="1024"
live/stream_hq.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=460560,CODECS="mp4a.40.5,avc1.420016",RESOLUTION=512x288,NAME="512"
live/half_lq.m3u8
  • set the correct BANDWIDTH

If you need more resolutions just add in transcode more outputs under vparams, maybe like this:

...
s           1024x576;
crf         23;
x264opts    keyint=50:min-keyint=50:no-scenecut;
maxrate     1300k;
bufsize     2600k;
f           flv;
c:a         copy;
y           rtmp://127.0.1.1:1935/live/big;
crf         23;
x264opts    keyint=50:min-keyint=50:no-scenecut;
maxrate     650k;
bufsize     1300k;
...

and add more vhosts.

Here is a working gist

Originally posted by @jb-alvarado in #463 (comment)

@johnlanz
Copy link

johnlanz commented Jul 10, 2020

this kind of transcoding uses ffmpeg which uses a lot of cpu. Mine consumes 200% cpu from livestream.
is there a way to make it use less cpu maybe less than 10% just like what srs did when converting to hls?

@r-t-k
Copy link
Author

r-t-k commented Jul 10, 2020 via email

@jb-alvarado
Copy link
Contributor

jb-alvarado commented Jul 10, 2020

is there a way to make it use less cpu maybe less than 10% just like what srs did when converting to hls?

srs is not transcoding to hls, it just copy the stream to a new container. The same would happen, when you use stream copy in ffmpeg, but as soon as you want to change the resolution you have to re-encode the stream and of course this uses more cpu power. There is no cheaper way.

@saeed-parsaee
Copy link

saeed-parsaee commented Aug 21, 2020

I had used your solution from provided gist and works fine. However when i try to transcode whole app streams it does not work as expected.
For example

            vparams {     
                crf         23;    
                x264-params keyint=50:min-keyint=25:scenecut=-1;    
                maxrate     650k;    
                bufsize     1300k;    
                refs        3;    
                c:a         copy;    
                f           flv;    
                y           rtmp://stream-low/[app]/[stream]-low;     
                c:v         copy;    
            }     
            acodec          copy;    
            oformat         flv;    
            output          rtmp://stream-high/[app]/[stream]-high;    

This does not work and The main problem is that [app]/[stream] inside vparams doesn't work and ts files not created for any of incoming streams and resolutions.

And another example

           vparams {
               ...
                y           rtmp://stream-low/live/low;
                ...
            }
            acodec          copy;
            oformat         flv;
            output          rtmp://stream-high/[app]/[stream]-high;

this will create low-[seq].ts and [stream]-high-[seq].ts
how can i have [stream]-low-[seq].ts as well?

@winlinvip
Copy link
Member

Good job!

@winlinvip winlinvip self-assigned this Sep 2, 2021
@winlinvip winlinvip added Codec HEVC, FFmpeg for ingesting, trascoding or codec. Won't fix We won't fix it. labels Sep 2, 2021
@winlinvip winlinvip added this to the 3.0 milestone Sep 4, 2021
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Codec HEVC, FFmpeg for ingesting, trascoding or codec. TransByAI Translated by AI/GPT. Won't fix We won't fix it.
Projects
None yet
Development

No branches or pull requests

5 participants