transcode segment files without stutter for http live streaming

2.1k Views Asked by At

I segmented a multicast video stream into small ts files for my HTTP live streaming service and it worked quite well. Then I found the bitrate of the source was too high (1.5mbps) so I set up a background job to transcode the ts files to a smaller bitrate (500kbps) using FFmpeg. The problem is that the 500k .m3u8 playback stutters(on every new file's loading) and is not as smooth as the 1.5mbps one.

My transcoding command line is like following:

ffmpeg -i /home/rca/tst.ts -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -vcodec libx264 -b 500k /home/rca/tst.ts

Any ideas for this? Thank you!

1

There are 1 best solutions below

0
On

Lower the resolution and or drop frames. That's your trade space for lower bandwidth connections.

Luckily a coworker (@enobrev) just did some great work in reviewing various ways to drop bandwidth:

Starting from the raw unencoded format is best, otherwise setting a bit rate in ffmpeg won't do much (lowering resolution and frame rates will though).

ffmpeg -i audio.wav -i "concat:0.avi|1.avi|2.avi" -vcodec libx264 -preset fast -crf 23 -threads 0 -b:v 64000 -r 10 -vf "scale=240:-1" -ab 24k -ar 22050 -map 0 -vbsf h264_mp4toannexb -f segment -segment_time 10 -segment_format mpegts -segment_list autoStream.m3u8 -segment_list_type m3u8 out_lowres_64kbps%d.ts

ffmpeg -i audio.wav -i "concat:0.avi|1.avi|2.avi" -vcodec libx264 -preset fast -crf 23 -threads 0 -b:v 300000 -r 24 -vf "scale=480:-1" -ab 96k -ar 22050 -map 0 -vbsf h264_mp4toannexb -f segment -segment_time 10 -segment_format mpegts -segment_list autoStream.m3u8 -segment_list_type m3u8 out_midres_300kbps%d.ts

ffmpeg -i audio.wav -i "concat:0.avi|1.avi|2.avi" -vcodec libx264 -preset fast -crf 23 -threads 0 -b:v 1200000 -r 24 -vf "scale=640:-1" -ab 192k -ar 44100 -map 0 -vbsf h264_mp4toannexb -f segment -segment_time 10 -segment_format mpegts -segment_list autoStream.m3u8 -segment_list_type m3u8 out_hires_1.2mbps%d.ts

there are many more parameters you can tune, but in the above I'm setting bit rate -b:v, frame rate -r, video resolution -vf, and audio bit rate -ab (I think), and audio sample rate -ar