[FFmpeg-user] HTML5 live streaming

Andrew Sinclair ajsinclair at gmail.com
Wed May 1 01:31:59 CEST 2013


3 seconds in the -hls_time setting is an unusual value, Apple recommend 10
though lower values generally work OK.

Note that for this to really work effectively you need to force key frames
to occur at the boundary of every segment otherwise you will find that the
segmenter will need to choose a segment size that matches where the key
frame is.

You should also look at the -segment muxer for a more complete list of
options where m3u8 is the HLS format.
http://ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment


On 30 April 2013 10:59, Jonathan Isom <jeisom at gmail.com> wrote:

> On Mon, Apr 22, 2013 at 9:19 PM, Ricardo Kleemann
> <ricardo at americasnet.com> wrote:
> > Hi Jonathan,
> >
> > This is awesome! It worked! :-)
> >
> > so my next step... how do I do adaptive bitrate? For example, I want to
> > have a stream for iPad, a stream for iPhone, Android...
>
> Found this link
> <http://ffmpeg.org/trac/ffmpeg/wiki/Creating%20multiple%20outputs> on
> streaming to multiple outputs. Here is a script that I am messing
> around with that should do adaptive streaming.  I used variables to
> simplify it a little. As always adjust to your needs.
>
> ----------->8-------------
> #!/bin/bash
> VIDSOURCE="$1"
> RESOLUTION="854x480"
> BITRATE1="800000"
> BITRATE2="600000"
> BITRATE3="400000"
>
> AUDIO_OPTS="-c:a libfaac -b:a 160000 -ac 2"
> VIDEO_OPTS1="-s $RESOLUTION -c:v libx264 -b:v $BITRATE1 -vprofile
> baseline -preset medium -x264opts level=41"
> VIDEO_OPTS2="-s $RESOLUTION -c:v libx264 -b:v $BITRATE2 -vprofile
> baseline -preset medium -x264opts level=41"
> VIDEO_OPTS3="-s $RESOLUTION -c:v libx264 -b:v $BITRATE3 -vprofile
> baseline -preset medium -x264opts level=41"
> OUTPUT_HLS="-hls_time 3 -hls_list_size 10 -hls_wrap 30 -start_number 1"
>
> ffmpeg -i "$VIDSOURCE" -y -threads 4 \
>        $AUDIO_OPTS $VIDEO_OPTS1 $OUTPUT_HLS stream_hi.m3u8 \
>        $AUDIO_OPTS $VIDEO_OPTS2 $OUTPUT_HLS stream_med.m3u8 \
>        $AUDIO_OPTS $VIDEO_OPTS3 $OUTPUT_HLS stream_low.m3u8
>
> ----------->8-------------
>
> Add in a m3u8 playlist for the streams created in the script.
> Something like this should work.
> ----------->8-------------
> #EXTM3U
> #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=500000
> stream_low.m3u8
> #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=700000
> stream_med.m3u8
> #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=900000
> stream_hi.m3u8
> ----------->8-------------
>
> And point you player/ browser to the m3u8 playlist.
>
> HTH
>
> Jonathan
>
> > Another question... does m3u8 work for a desktop browser? I do I need an
> > embedded player like JWPlayer for desktop?
> >
> > Thanks so much!
> > Ricardo
> >
> > On Sun, Apr 21, 2013 at 9:30 PM, Jonathan Isom <jeisom at gmail.com> wrote:
> >
> >> On Sun, Apr 21, 2013 at 7:43 PM, Ricardo Kleemann
> >> <ricardo at americasnet.com> wrote:
> >> > That's great, I didn't realize it.
> >> >
> >> > I'm trying to convert the input to h.264 + AAC and output to the
> >> segmenter
> >> > but it's not working. Can you help me find the error in the command?
> >> >
> >> > ffmpeg -loglevel debug -threads 4 -i "rtmp://server1/live/livestream1"
> >> > -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 63 -qdiff 4 -trellis 0
> -vcodec
> >> > libx264 -s 480x270 -b:v 512k -b:a 56k -ar 22050 -map 0 -f segment
> >> > -segment_time 10 -segment_list live.m3u8 -segment_list_flags +live
> >> > live_%05d.ts
> >> >
> >>
> >> Here is the command I use which works with my iPad 3rd Gen. I cd into
> >> the directory that I want the files to load from on the server. My
> >> case is "/var/www/localhost/htdocs/stream/" which is
> >> "http://domain/stream/". You probably should lose all the extra
> >> options. for realtime encoding add "-re" to the command. You will want
> >> to change RESOLUTION BITRATE & VIDSOURCE to what you need. Also below
> >> is an example html file.
> >> This is with ffmpeg git from a week ago. notice the "-hls*" options
> >> instead of -segment.* options.
> >>
> >> ffmpeg  -i VIDSOURCE -y  -c:v libx264 -b:v BITRATE -vprofile baseline
> >> -preset medium -x264opts level=41 -threads 4 -s RESOLUTION -map 0:v
> >> -map 0:a:0  -c:a libfaac -b:a 160000 -ac 2   -hls_time 10
> >> -hls_list_size 6 -hls_wrap 18 -start_number 1 stream.m3u8
> >>
> >> index.htm:
> >> <html>
> >> <body>
> >>    <video  height="531"  width="945" autoplay="autoplay"
> >> controls="controls">
> >>     <source src="stream.m3u8" />
> >>    </video>
> >> </body>
> >> </html>
> >>
> >> Hope this is helpful.
> >>
> >> Jonathan
> >> _______________________________________________
> >> ffmpeg-user mailing list
> >> ffmpeg-user at ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >>
> >>
> >> ------------------------------------------------------
> >> Powered by Xeams. Visit xeams.com for more information
> >> ------------------------------------------------------
> >>
> > _______________________________________________
> > ffmpeg-user mailing list
> > ffmpeg-user at ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>


More information about the ffmpeg-user mailing list