trunk/3rdparty/srs-docs/blog/2023-03-07-Lets-Do-H265-Live-Streaming.md
Written by Winlin, runner365, yinjiaoyuan, PieerePi, qichaoshen82, ZSC714725, bluestn, mapengfei53, chundonglinlin, duiniuluantanqin, panda1986
SRS 6.0 supports HEVC(H.265), for RTMP, HTTP-FLV, HTTP-TS, HLS, MPEG-DASH, WebRTC(Safari), DVR FLV, DVR MP4 and WordPress SrsPlayer, etc.
Generally, H.265 is 50% off than H.264, so you only need to pay 50% bills if H.265.
<!--truncate-->Now, you're able to use HEVC(H.265) in live streaming.
H.265 uses less bandwidth than H.264, which means lower bandwidth cost, or higher quality in same bandwidth.
Furthermore, if want 8K live streaming, you must use H.265, because H.264 doesn't support 8K resolution.
Please note that there are still some traps for H.265 live streaming.
The status of H.265, for different use scenarios.
Part 1, publisher or encoder for H.265.
Part 2, play stream by FFmpeg/ffplay for H.265.
Part 3, play stream by H5 MSE for H.265.
Part 4, play stream by VLC for H.265.
Part 5, other features for H.265.
If native iOS or Android application, please use FFmpeg.
Appreciate the patch for Chrome 105 to support HEVC for MSE, it makes the HEVC live streaming possible.
MSE HEVC requires GPU hardware decoding, please open chrome://gpu then search hevc, and it should work if matched.
This is an example fo H.265 live streaming.
First, run SRS in docker:
docker run --rm -it -p 1935:1935 -p 8080:8080 ossrs/srs:6 \
./objs/srs -c conf/docker.conf
Use FFmepg to publish HEVC over RTMP, see FFmpeg Tools:
# For macOS
docker run --rm -it ossrs/srs:encoder ffmpeg -stream_loop -1 -re -i doc/source.flv \
-acodec copy -vcodec libx265 -f flv rtmp://host.docker.internal/live/livestream
# For linux
docker run --net=host --rm -it ossrs/srs:encoder ffmpeg -stream_loop -1 -re -i doc/source.flv \
-acodec copy -vcodec libx265 -f flv rtmp://127.0.0.1/live/livestream
Note: Please change the ip
host.docker.internalto your SRS's IP.
Done, please open links bellow in browser:
http://localhost:8080/live/livestream.m3u8Note: Please use VLC or ffplay to play HLS, because hls.js doesn't support it.
Please follow wiki of SRS to use other protocols.
Right now, at 2023.03, only Safari support HEVC over WebRTC, neither Chrome nor Firefox supports it.
And, you should enable the HEVC for Safari by clicking Develop > Experimental Features > WebRTC H265 codec.
For detail usage, please follow #465.
Beside HEVC, WebRTC has better support for AV1, Safari/Chrome/Firefox supports AV1, please read #1070 for detail. Note that MSE doesn't support AV1.
Note: Media Source Extensions (MSE) is H5 API for media streaming, on which mpegts.js, hls.js and dash.js bases. Please see MDN: MSE.
FFmpeg 6 has supported HEVC over RTMP, if you want to build from code, please see FFmpeg Tools.
SRS dev-docker already patched FFmpeg, ffplay and ffprobe, so user can use it:
# For macOS
docker run --rm -it ossrs/srs:encoder ffmpeg -stream_loop -1 -re -i doc/source.flv \
-acodec copy -vcodec libx265 -f flv rtmp://host.docker.internal/live/livestream
# For linux
docker run --net=host --rm -it ossrs/srs:encoder ffmpeg -stream_loop -1 -re -i doc/source.flv \
-acodec copy -vcodec libx265 -f flv rtmp://127.0.0.1/live/livestream
Please see FFmpeg Tools for detail.
The known issues for HEVC live streaming:
On some use scenario, HEVC is available now, please evaluate it by yourself.
At SRS, our goal is to establish a non-profit, open-source community dedicated to creating an all-in-one, out-of-the-box, open-source video solution for live streaming and WebRTC online services.
Additionally, we offer a Cloud service for those who prefer to use cloud service instead of building from scratch. Our cloud service features global network acceleration, enhanced congestion control algorithms, client SDKs for all platforms, and some free quota.
To learn more about our cloud service, click here.
There are some developers that contributed to SRS HEVC feature:
Really appreciated for mpegts.js, which supports HEVC for HTTP-FLV and HTTP-TS.
Welcome for more discussion at discord.