how to generate multiple bitrate HLS content from live rtsp stream?

5

3

I am gerating single bitrate live hls content from live rtsp stream . I am using the following command

ffmpeg -v verbose -i rtsp://127.0.0.1:8080/test.sdp \
 -vcodec libx264 -acodec aac -ac 1 -strict -2 -crf 18 -profile:v baseline \
 -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header \
 -hls_time 10 -hls_list_size 3 -hls_wrap 4 -hls_flags delete_segments \
 -start_number 1 /usr/local/apache-tomcat-7.0.53/webapps/ROOT/hls/index1.m3u8

How can I modify the above ffmpg command to generate multiple bitrate output content ? Please help me.

prashantas

Posted 2015-02-09T10:26:23.897

Reputation: 63

Answers

7

ffmpeg -v verbose -i rtsp://127.0.0.1:8080/test.sdp \
-vcodec libx264 -acodec aac -ac 1 -strict -2 -crf 18 \
-profile:v baseline -maxrate 400k -bufsize 1835k \
-pix_fmt yuv420p -flags -global_header \
-hls_time 10 -hls_list_size 3 -hls_wrap 4 -hls_flags delete_segments \
-start_number 1 /usr/local/apache-tomcat-7.0.53/webapps/ROOT/hls/index1.m3u8 \
-vcodec libx264 -acodec aac -ac 1 -strict -2 -crf 18 \
-profile:v baseline -maxrate 700k -bufsize 1835k \
-pix_fmt yuv420p -flags -global_header \
-hls_time 10 -hls_list_size 3 -hls_wrap 4 -hls_flags delete_segments \
-start_number 1 /usr/local/apache-tomcat-7.0.53/webapps/ROOT/hls/index2.m3u8

and create index.m3u8 pointing to the streams above:

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=400000
hls/index1.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=700000
hls/index2.m3u8

vayvanne

Posted 2015-02-09T10:26:23.897

Reputation: 71

Welcome to Super User. Can you expand your answer to explain what this code does and how it addresses the problem? Unexplained code is discouraged, because it doesn't teach the solution. Thanks.

– fixer1234 – 2016-02-13T03:35:58.993

We are adding the second output with the same parameters as first but -maxrate 700k and then creating multi bitrate index,m3u8 for both HLS streams. – vayvanne – 2016-02-13T03:39:53.520

3

The concept you need for generating multiple outputs from a single input with ffmpeg is demonstrated very clearly (at least for me it was) at https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs

basically, ffmpeg -i someinput [output_options] someoutput1 [output2_options] someoutput2 is the pattern. It looks like you already know how to use the rtsp as an input and you know how to generate a single output with a given bitrate. You wan too repeat the entire output block (everything after your rtsp input string), and each time change your resolution with -s and your bitrate (you're using -crf so you'd want to decrease it for higher res/higher quality and increase it for lower-res, lower quality).

Personally, I would use crf for HLS renditions and with libx265, the rule I use is frame_width * frame_height * frame_rate * 0.1 to get the "ideal" bitrate for a given frame size. you'll have to flip the equation if you want to select bitrates to target, then figure out the framesize from that. The ".1" value can go higher, but you won't see much benefit in general (more complex content will better use a higher value) and I rarely go below 0.07.

rainabba

Posted 2015-02-09T10:26:23.897

Reputation: 256