Skip to content

Commit 88758c6

Browse files
encoded_video_ingest
1 parent 7abd4b9 commit 88758c6

7 files changed

Lines changed: 1171 additions & 46 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ add_subdirectory(platform_audio)
9494
add_subdirectory(ping_pong/ping ping_pong_ping)
9595
add_subdirectory(ping_pong/pong ping_pong_pong)
9696
add_subdirectory(frame_metadata)
97+
add_subdirectory(encoded-video-ingest)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2026 LiveKit, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
add_executable(EncodedVideoIngestProducer
16+
producer.cpp
17+
)
18+
19+
target_include_directories(EncodedVideoIngestProducer PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
20+
target_link_libraries(EncodedVideoIngestProducer PRIVATE ${LIVEKIT_CORE_TARGET})
21+
22+
if(WIN32)
23+
target_link_libraries(EncodedVideoIngestProducer PRIVATE ws2_32)
24+
endif()
25+
26+
livekit_copy_windows_runtime_dlls(EncodedVideoIngestProducer)
27+
28+
add_executable(EncodedVideoIngestConsumer
29+
consumer.cpp
30+
../simple_room/sdl_video_renderer.cpp
31+
../simple_room/sdl_video_renderer.h
32+
)
33+
34+
target_include_directories(EncodedVideoIngestConsumer PRIVATE
35+
${CMAKE_CURRENT_SOURCE_DIR}
36+
${CMAKE_CURRENT_SOURCE_DIR}/../simple_room
37+
)
38+
target_link_libraries(EncodedVideoIngestConsumer PRIVATE ${LIVEKIT_CORE_TARGET} SDL3::SDL3)
39+
40+
livekit_copy_windows_runtime_dlls(EncodedVideoIngestConsumer)

‎encoded-video-ingest/README.md‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# encoded-video-ingest
2+
3+
End-to-end encoded video ingest demo for the LiveKit C++ SDK. GStreamer serves
4+
an encoded bytestream over TCP; the producer reads that stream, splits complete
5+
frames, pushes them into an `EncodedVideoSource`, and publishes a normal local
6+
video track. The consumer subscribes to the decoded track and renders it with
7+
SDL.
8+
9+
This example intentionally does not use the removed `EncodedTcpIngest` helper.
10+
TCP reconnect and bytestream framing are application code. The producer creates
11+
an `EncodedVideoSource(codec, width, height)`, submits each access unit as an
12+
`EncodedVideoSource::Frame` with `captureFrame()`, and polls `takeFeedback()`
13+
for keyframe and rate-control requests. It publishes the track with
14+
`VideoEncoderBackend::PreEncoded`.
15+
16+
## Prerequisites
17+
18+
- A LiveKit server, such as `livekit-server --dev`.
19+
- GStreamer 1.22+ with `good`, `bad`, `ugly`, and `libav` plugins.
20+
- Producer and consumer tokens for the same room.
21+
22+
```bash
23+
export LIVEKIT_URL=ws://localhost:7880
24+
export PRODUCER_TOKEN="$(lk token create -r encoded-video-demo -i encoded-sender --join --publish)"
25+
export CONSUMER_TOKEN="$(lk token create -r encoded-video-demo -i encoded-receiver --join --subscribe)"
26+
```
27+
28+
## H.264
29+
30+
Start a camera pipeline that serves AUD-delimited Annex-B H.264 on TCP port
31+
5005:
32+
33+
```bash
34+
gst-launch-1.0 -v \
35+
avfvideosrc device-index=0 ! \
36+
video/x-raw,width=640,height=480,format=NV12,framerate=30/1 ! \
37+
videoconvert ! \
38+
x264enc tune=zerolatency speed-preset=ultrafast bitrate=1000 key-int-max=60 aud=true ! \
39+
h264parse config-interval=1 ! \
40+
video/x-h264,stream-format=byte-stream,alignment=au ! \
41+
tcpserversink host=0.0.0.0 port=5005 sync=false async=false
42+
```
43+
44+
Linux: replace `avfvideosrc device-index=0` with
45+
`v4l2src device=/dev/video0`. Windows: use `mfvideosrc device-index=0`.
46+
47+
Run the producer:
48+
49+
```bash
50+
LIVEKIT_URL=ws://localhost:7880 LIVEKIT_TOKEN="$PRODUCER_TOKEN" \
51+
./build-release/cpp-example-collection/encoded-video-ingest/EncodedVideoIngestProducer \
52+
--tcp-host 127.0.0.1 --tcp-port 5005 \
53+
--width 640 --height 480 \
54+
--codec h264
55+
```
56+
57+
Run the consumer:
58+
59+
```bash
60+
LIVEKIT_URL=ws://localhost:7880 LIVEKIT_TOKEN="$CONSUMER_TOKEN" \
61+
./build-release/cpp-example-collection/encoded-video-ingest/EncodedVideoIngestConsumer \
62+
--from encoded-sender \
63+
--track-name encoded-h264
64+
```
65+
66+
## Other Codecs
67+
68+
H.265 uses the same Annex-B framing path:
69+
70+
```bash
71+
gst-launch-1.0 -v \
72+
avfvideosrc device-index=0 ! \
73+
video/x-raw,width=640,height=480,format=NV12,framerate=30/1 ! \
74+
videoconvert ! \
75+
x265enc tune=zerolatency speed-preset=ultrafast bitrate=1000 key-int-max=60 \
76+
option-string="aud=1:repeat-headers=1" ! \
77+
h265parse config-interval=1 ! \
78+
video/x-h265,stream-format=byte-stream,alignment=au ! \
79+
tcpserversink host=0.0.0.0 port=5005 sync=false async=false
80+
```
81+
82+
Pass `--codec h265` and use `--track-name encoded-h265` on the consumer.
83+
84+
VP8 and AV1 use IVF framing:
85+
86+
```bash
87+
gst-launch-1.0 -v \
88+
avfvideosrc device-index=0 ! \
89+
video/x-raw,width=640,height=480,format=NV12,framerate=30/1 ! \
90+
videoconvert ! \
91+
vp8enc deadline=1 target-bitrate=1000000 keyframe-max-dist=60 ! \
92+
ivfmux ! \
93+
tcpserversink host=0.0.0.0 port=5005 sync=false async=false
94+
```
95+
96+
Pass `--codec vp8` and use `--track-name encoded-vp8`. For AV1, replace the
97+
encoder with `av1enc`, `svtav1enc`, or `rav1enc`, pass `--codec av1`, and use
98+
`--track-name encoded-av1`.
99+
100+
VP9 is intentionally omitted from this example because the current passthrough
101+
path does not yet provide the VP9 RTP descriptor plumbing needed for reliable
102+
ingest.

0 commit comments

Comments
 (0)