Open nicolaslevy opened 1 week ago
I'm trying to set up a local ad server to test HLS live streams with interstitials. I'm not being able to make it work with hls.js
v1.6.0-beta.1.
These are the steps I followed:
git clone https://github.com/Eyevinn/test-adserver.git
cd test-adserver
npm install
.env
file to use 3333
HOST=localhost
PORT=3333
HOSTDOMAIN
npm start
to run the server.Prerequisites:
ffmpeg
Steps:
Download mp4 video For example: http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4 More videos at: https://gist.github.com/jsturgis/3b19447b304616f18657
Create a live stream Use the downloaded mp4 video.
# Use ffmpeg to create a simple HLS Live stream under the "test" directory
ffmpeg -y -re -stream_loop -1 -i Sintel.mp4 \
-preset slow -g 48 -sc_threshold 0 \
-map 0:0 -map 0:1 -map 0:0 -map 0:1 \
-s:v:0 640x360 -c:v:0 libx264 -b:v:0 365k \
-s:v:1 960x540 -c:v:1 libx264 -b:v:1 2000k \
-c:a copy \
-var_stream_map "v:0,a:0 v:1,a:1" \
-master_pl_name master.m3u8 \
-f hls -hls_time 4 -hls_list_size 8 -hls_flags round_durations+program_date_time+delete_segments \
-hls_segment_filename "test/v%v/fileSequence%d.ts" test/v%v/media.m3u8
Download a interstitial sample
Download an HLS content and paste it under the same folder as the HLS live stream (test/
) and rename it to `interstitials.m3u8``
Serve the HLS live stream and interstitial.m3u8
# Serve the HLS Live stream using a simple http server *above* the "test" directory
cd test
python -m http.server 8001
# Now you can access the HLS stream at http://127.0.0.1:8001/test/master.m3u8
cargo run --bin ad_proxy 127.0.0.1 3333 http://localhost:8001/master.m3u8 \
"http://localhost:3333/api/v1/vast?dur=[template.duration]&uid=[template.sessionId]&ps=[template.pod]&min=5&max=5" \
--ad-insertion-mode static --interstitials-address http://localhost:8001
[!NOTE] Notice that I set
--ad-insertion-mode
and--interstitials-address
options
Options:
-a, --ad-insertion-mode <AD_INSERTION_MODE>
Ad insertion mode to use:
1) static - add interstitial every 30 seconds (100 in total).
2) dynamic - add interstitial when requested (Live Content only). [default: static] [possible values: static, dynamic]
-i, --interstitials-address <INTERSTITALS_ADDRESS>
Base URL for interstitials (protocol://ip:port)
If not provided, the server will use 'localhost' and the 'listen port' as the base URL
e.g., http://localhost:${LISTEN_PORT} [default: ]
If --add-insertion-mode
is set to dynamic, a get request can be done to add interstitials with desired specifications as follows:
curl "http://127.0.0.1:3333/command?in=5&dur=30&pod=2"
Response:
{
"status": "success",
"command": {
"index": 2,
"in_sec": 5,
"duration": 30,
"pod_num": 2
}
}
Resulting in a modified playlist:
#EXTM3U
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:4417
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:20.836-0300
#EXTINF:4,
fileSequence4417.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:24.836-0300
#EXTINF:4,
fileSequence4418.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:28.836-0300
#EXTINF:4,
fileSequence4419.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:32.836-0300
#EXTINF:4,
fileSequence4420.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:36.836-0300
#EXTINF:4,
fileSequence4421.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:40.836-0300
#EXTINF:4,
fileSequence4422.ts
#EXT-X-DATERANGE:ID="ad_slot2",CLASS="com.apple.hls.interstitial",START-DATE="2024-11-20T16:01:43.013-03:00",DURATION=30,CUSTOM-DROP-OFFSET=0,X-ASSET-LIST="http://localhost:8001/interstitials.m3u8?_HLS_interstitial_id=ad_slot2",X-RESTRICT="SKIP,JUMP",X-SNAP="IN,OUT"
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:44.836-0300
#EXTINF:4,
fileSequence4423.ts
#EXT-X-PROGRAM-DATE-TIME:2024-11-20T16:01:48.836-0300
#EXTINF:4,
fileSequence4424.ts
Currently, I'm getting the following error with hls.js
player (v1.6.0-beta.1) when it identifies the interstitial.
Also, tried to use the couchdb
endpoint to get the ads:
cargo run --bin ad_proxy 127.0.0.1 3333 http://localhost:8001/master.m3u8 \
"http://localhost:8080/api/v1/vast?dur=[template.duration]&uid=[template.sessionId]&ps=[template.pod]&min=5&max=5" \
--ad-insertion-mode dynamic --couchdb-endpoint https://eyevinn-sgai.apache-couchdb.auto.prod.osaas.io/
As a result, hls.js
player instantiates another player, but it throws the following error:
We need a testing tool to simulate the insertion of interstitial (e.g., ads or alternate segments) into HLS (HTTP Live Streaming) content. This tool will help in testing and development workflows, particularly for live content scenarios.
We should check if Eyevinn sgai-ad-proxy tool is usefull for this (https://github.com/Eyevinn/sgai-ad-proxy to know if this tool)