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

FFmpeg: Add Whip Muxer support for subsecond latency streaming #1

Open
wants to merge 60 commits into
base: feature/whip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ae07b06
WHIP: Add WebRTC WHIP muxer.
winlinvip Apr 16, 2023
f090d64
WHIP: Only support h264+opus codec.
winlinvip Apr 16, 2023
edaf213
WHIP: Generate and exchange offer server to get answer.
yangrtc Apr 21, 2023
83202f7
WHIP: Support parse ice from answer.
winlinvip Apr 22, 2023
8a63f74
WHIP: Refine code.
winlinvip Apr 22, 2023
67bccbf
WHIP: Support ICE handshake by binding.
winlinvip May 1, 2023
9db6961
WHIP: Support fast retransmit for binding request.
winlinvip May 1, 2023
1496684
WHIP: Update the dependency, requires openssl.
winlinvip May 2, 2023
0522db8
WHIP: Support DTLS handshake by openssl
winlinvip May 2, 2023
4ee4ca5
WHIP: Setup SRTP with key material generated by DTLS
winlinvip May 3, 2023
67f9942
WHIP: Refine code.
winlinvip May 3, 2023
ff5ef96
WHIP: Support mux and send audio by RTP
winlinvip May 3, 2023
98fca74
WHIP: Support mux and send video by RTP
winlinvip May 4, 2023
9ecbef0
WHIP: Support audio or video only
winlinvip May 4, 2023
40c385a
WHIP: Support video annexb format.
winlinvip May 4, 2023
fc0974a
WHIP: Refine code.
winlinvip May 5, 2023
fae7b40
WHIP: Dispose resource when write trailer.
winlinvip May 5, 2023
5e400cd
WHIP: Check alloc fail and return EMOMEM.
winlinvip May 5, 2023
d9c7dc7
WHIP: Always dispose resource by WHIP.
winlinvip May 5, 2023
235aaa0
WHIP: Refine macros.
winlinvip May 6, 2023
34fd9f9
WHIP: Support set parameters by options.
winlinvip May 6, 2023
2bfdb67
WHIP: Eliminate the unused write_trailer.
winlinvip May 6, 2023
e3fdedd
WHIP: Refine code.
winlinvip May 6, 2023
b4574d6
WHIP: Check for null string to avoid strlen crash, scanned by ASAN
winlinvip May 11, 2023
248243a
WHIP: Improve macro and options comments with more background details
winlinvip May 11, 2023
d801061
WHIP: Remote password should be used to generate the message integrity.
winlinvip May 12, 2023
a1a8335
Use AVPrint to generate the offer and answer for WebRTC SDP.
winlinvip May 12, 2023
ff72920
WHIP:Support send sctp
duiniuluantanqin May 12, 2023
fc3a4a2
WHIP: Refining SRTP context selection.
winlinvip May 12, 2023
45e6ece
WHIP: Refine code.
winlinvip May 13, 2023
6f965d6
Add bidirectional ICE binding, DTLS with ECDSA, and compatibility imp…
cloudwebrtc May 13, 2023
3fd6767
Add missing quotation string to error message
winlinvip May 15, 2023
68ef7ad
WHIP: Extract DTLSContext from RTContext.
winlinvip May 17, 2023
c7b146b
WHIP: Reorder functions, nothing changed.
winlinvip May 17, 2023
2dedc86
WHIP: Remove the macro that suppresses warnings for the SSL deprecate…
winlinvip May 18, 2023
1054bed
WHIP: Merge write header to init.
winlinvip May 18, 2023
b31e0c0
WHIP:Support baseline/main/high profile without B frames (#2)
duiniuluantanqin May 19, 2023
b3f5c27
WHIP: Fix the SSL deprecated warning by replacing EC_KEY_new with EVP…
winlinvip May 23, 2023
85c5680
WHIP: Refine the code to be shorter.
winlinvip May 23, 2023
71ee877
WHIP: Increase the base timeout and thereby reduce the number of unne…
winlinvip May 23, 2023
726bb67
WHIP: Refine ARQ for DTLS with bug fixed.
winlinvip May 23, 2023
6e1fbb5
WHIP: Update muxers.texi for RTC.
winlinvip May 29, 2023
86b361c
WHIP: Fix bugs causing build OpenSSL error, to work with Pion
winlinvip May 30, 2023
ea74e3c
Optimize DTLS Handshake and ICE Handling for Improved Performance (#3)
winlinvip Jun 7, 2023
680ed49
Roundtrip3: Refinements Based on Derek Buitenhuis' Comments (#4)
winlinvip Jun 9, 2023
2ac4100
WHIP: Do not hardcode codec for SDP. (#5)
winlinvip Jun 9, 2023
5819297
WHIP: Parse profile and level from extradata.
winlinvip Jun 9, 2023
0c4a158
WHIP: Insert SPS and PPS before IDR frames in annexb format due to h2…
winlinvip Jun 10, 2023
812932e
WHIP: Failed immediately if there is no profile and extradata present.
winlinvip Jun 10, 2023
aaf26ef
WHIP: Refine names and comments.
winlinvip Jun 19, 2023
66a064f
WHIP: Free buffer leak of pb for RTP muxer.
winlinvip Jun 20, 2023
9c7a091
WHIP: Use options for passing parameters to the HTTP or UDP context.
winlinvip Jun 21, 2023
de33fcc
WHIP: Enhance security by using BearToken for delete API.
winlinvip Jun 21, 2023
8971a1f
WHIP: Support user specified certificate and key file.
winlinvip Jun 21, 2023
0bd6867
WHIP: Read DTLS certificate file by ffurl.
winlinvip Jul 4, 2023
0b95312
WHIP: Free bio_in if ENOMEM.
winlinvip Jul 8, 2023
63e3a55
WHIP: Refine DTLS, extract DTLS APIs.
winlinvip Aug 24, 2023
172d34b
Sync with FFmpeg master 5ddab49d48
winlinvip Oct 17, 2023
d3561e6
Extract DTLS to dtls.c
winlinvip Oct 17, 2023
3b15ba1
Change some important step log level to info.
winlinvip Oct 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,8 @@ wav_demuxer_select="riffdec"
wav_muxer_select="riffenc"
webm_chunk_muxer_select="webm_muxer"
webm_dash_manifest_demuxer_select="matroska_demuxer"
# TODO: Support libtls, mbedtls, and gnutls.
whip_muxer_deps_any="openssl"
wtv_demuxer_select="mpegts_demuxer riffdec"
wtv_muxer_select="mpegts_muxer riffenc"
xmv_demuxer_select="riffdec"
Expand Down Expand Up @@ -6912,6 +6914,14 @@ enabled rkmpp && { require_pkg_config rkmpp rockchip_mpp rockchip/r
}
enabled vapoursynth && require_pkg_config vapoursynth "vapoursynth-script >= 42" VSScript.h vsscript_init

enabled openssl && {
enabled whip_muxer && {
$pkg_config --exists --print-errors "openssl >= 1.0.1k" ||
require_pkg_config openssl "openssl >= 1.0.1k" openssl/ssl.h SSL_library_init ||
require_pkg_config openssl "openssl >= 1.0.1k" openssl/ssl.h OPENSSL_init_ssl
}
}


if enabled gcrypt; then
GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
Expand Down
47 changes: 47 additions & 0 deletions doc/muxers.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2846,4 +2846,51 @@ ffmpeg -f webm_dash_manifest -i video1.webm \
manifest.xml
@end example

@anchor{whip}
@section whip

WebRTC (Real-Time Communication) muxer that supports sub-second latency streaming according to
the WHIP (WebRTC-HTTP ingestion protocol) specification.

It uses HTTP as a signaling protocol to exchange SDP capabilities and ICE lite candidates. Then,
it uses STUN binding requests and responses to establish a session over UDP. Subsequently, it
initiates a DTLS handshake to exchange the SRTP encryption keys. Lastly, it splits video and
audio frames into RTP packets and encrypts them using SRTP.

Ensure that you use H.264 without B frames and Opus for the audio codec. For example, to convert
an input file with @command{ffmpeg} to WebRTC:
@example
ffmpeg -re -i input.mp4 -acodec libopus -ar 48000 -ac 2 \
-vcodec libx264 -profile:v baseline -tune zerolatency -threads 1 -bf 0 \
-f whip "http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream"
@end example

For this example, we have employed low latency options, resulting in an end-to-end latency of
approximately 150ms.

@subsection Options

This muxer supports the following options:

@table @option

@item handshake_timeout @var{integer}
Set the timeout in milliseconds for ICE and DTLS handshake.
Default value is 5000.

@item pkt_size @var{integer}
Set the maximum size, in bytes, of RTP packets that send out.
Default value is 1500.

@item authorization @var{string}
The optional Bearer token for WHIP Authorization.

@item cert_file @var{string}
The optional certificate file path for DTLS.

@item key_file @var{string}
The optional private key file path for DTLS.

@end table

@c man end MUXERS
1 change: 1 addition & 0 deletions libavformat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o
OBJS-$(CONFIG_WEBP_MUXER) += webpenc.o
OBJS-$(CONFIG_WEBVTT_DEMUXER) += webvttdec.o subtitles.o
OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o
OBJS-$(CONFIG_WHIP_MUXER) += whip.o dtls.o avc.o http.o srtp.o
OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o
OBJS-$(CONFIG_WSAUD_MUXER) += westwood_audenc.o
OBJS-$(CONFIG_WSD_DEMUXER) += wsddec.o rawdec.o
Expand Down
1 change: 1 addition & 0 deletions libavformat/allformats.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ extern const FFOutputFormat ff_webm_chunk_muxer;
extern const FFOutputFormat ff_webp_muxer;
extern const AVInputFormat ff_webvtt_demuxer;
extern const FFOutputFormat ff_webvtt_muxer;
extern const FFOutputFormat ff_whip_muxer;
extern const AVInputFormat ff_wsaud_demuxer;
extern const FFOutputFormat ff_wsaud_muxer;
extern const AVInputFormat ff_wsd_demuxer;
Expand Down
Loading