
Our test player loaded the HLS playlist and fetched the first video segment. It never displayed a frame. The playlist pointed to the wrong filename for the middle segment. This guide shows how to package one MP4 with FFmpeg, upload the playlist and segments together under a new version, and check the lesson from the learner’s side.
HTTP Live Streaming (HLS) lets a player fetch a video file in segments over HTTP. For a recorded lesson with a single resolution, FFmpeg produces one media playlist and a sequence of video segments that also carry the audio. An ordinary HTTP server or an object storage delivery endpoint can serve those files.
Start with a source video whose width and height are even, and an FFmpeg build with the H.264 encoder libx264. Put lesson.mp4 beside a new empty directory called package. Run the following from inside that directory in a shell such as Bash. It selects the first video track and includes the first audio track if present. For help choosing an encoder for a larger job, see our video transcoding guide.
ffmpeg -i ../lesson.mp4 -map 0:v:0 -map '0:a:0?' -vf fps=25 \
-c:v libx264 -pix_fmt yuv420p -flags +cgop -g 50 -sc_threshold 0 \
-c:a aac -b:a 96k -f hls -hls_time 2 -hls_playlist_type vod \
-hls_flags independent_segments -hls_segment_filename 'part%03d.ts' lesson.m3u8
At 25 frames per second, a group of 50 frames spans two seconds. Setting that interval and disabling scene-cut keyframes gives the segmenter predictable places to split. The setting -hls_time 2 is a target. FFmpeg starts the next segment at an eligible keyframe. The VOD option keeps the entire playlist, and independent_segments marks the segments as independently decodable. See the FFmpeg HLS muxer documentation.
Our six-second test clip produced this playlist. Each filename is relative to the playlist URL. If the player opens /lessons/intro/v1/lesson.m3u8, its second video request resolves to /lessons/intro/v1/part001.ts. Moving all four objects together preserves that relationship.
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXTINF:2.000000,
part000.ts
#EXTINF:2.000000,
part001.ts
#EXTINF:2.000000,
part002.ts
#EXT-X-ENDLIST
Give each release its own prefix, such as lessons/intro/v1/. Upload the three media objects first. Once those writes succeed, upload the playlist and then point the player at it. If an upload stops halfway, a fresh prefix keeps the previous lesson playable. Use a different prefix for the retry and give each uploader its own version.
Save the uploader alongside the package directory, using the script name shown in the command below. It checks the filenames locally, verifies that the destination prefix is empty and sets the response type on each object. It handles the single MPEG-TS media playlist produced above.
"""Upload one completed FFmpeg VOD package to a new version prefix."""
import argparse
from pathlib import Path
import re
import boto3
def upload(client, directory, bucket, prefix):
prefix = prefix.strip("/")
if not prefix:
raise ValueError("Use a new, nonempty version prefix")
playlist = directory / "lesson.m3u8"
lines = playlist.read_text(encoding="utf-8").splitlines()
if "#EXT-X-ENDLIST" not in lines or "#EXT-X-PLAYLIST-TYPE:VOD" not in lines:
raise ValueError("Expected a finished VOD media playlist")
names = [line for line in lines if line and not line.startswith("#")]
if not names or any(not re.fullmatch(r"part[0-9]+\.ts", n) for n in names):
raise ValueError("Expected relative MPEG-TS segment names from this example")
if any(not (directory / n).is_file() for n in names):
raise FileNotFoundError("A referenced segment is missing locally")
if client.list_objects_v2(Bucket=bucket, Prefix=prefix + "/", MaxKeys=1).get("KeyCount"):
raise ValueError("Choose a fresh prefix for this package")
for name in [*names, playlist.name]:
media_type = "application/vnd.apple.mpegurl" if name == playlist.name else "video/mp2t"
with (directory / name).open("rb") as data:
client.put_object(Bucket=bucket, Key=f"{prefix}/{name}", Body=data, ContentType=media_type)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("directory", type=Path)
parser.add_argument("bucket")
parser.add_argument("prefix")
parser.add_argument("--endpoint-url")
args = parser.parse_args()
upload(boto3.client("s3", endpoint_url=args.endpoint_url), args.directory, args.bucket, args.prefix)
Run these commands from the parent directory. Replace the bucket, prefix and S3 API endpoint with your test values. Configure Boto3’s usual credentials and region on the upload machine. The uploader needs permission to list this prefix and write its objects.
python -m pip install boto3
python upload_hls.py package my-test-bucket lessons/intro/v1 --endpoint-url https://s3.example.org
Use the HTTPS playback URL provided by your delivery service or CDN. The viewer needs read access to the playlist and each segment. For a private lesson, configure the delivery layer to authorize every request. A signature on a playlist URL does not carry over to relative segment URLs. The HLS specification describes how players resolve those references.
Save this as a player page and put the browser build hls.min.js from hls.js 1.7.4 next to it. Replace the sample playlist URL, serve the page over HTTP or HTTPS, then press Play. The player uses native HLS when the browser supports it and hls.js when Media Source Extensions are available.
<video id="lesson" controls playsinline></video>
<script src="hls.min.js"></script>
<script>
const video = document.getElementById("lesson");
const playlist = "https://media.example.org/lessons/intro/v1/lesson.m3u8";
if (video.canPlayType("application/vnd.apple.mpegurl")) {
video.src = playlist;
} else if (Hls.isSupported()) {
const player = new Hls();
player.loadSource(playlist);
player.attachMedia(video);
} else {
video.replaceWith("HLS playback is unavailable in this browser.");
}
</script>
If the player and the media use different origins, configure CORS on the delivery endpoint. Allow the player’s origin to read the playlist and segments with GET. Check the actual responses, including cached CDN responses. CORS controls browser access to the response and does not give anyone permission to read a private object. See S3’s CORS documentation.
Note the final spoken line or slide in the approved cut. Open the matching lesson version in the player learners will use. Play it from the start without skipping. When it ends, compare what you heard or saw with the cue you wrote down.
Pass the playback check if the lesson plays through to the expected cue. Hold the version if it stops early or ends on a different line or slide. Give production the lesson version, the player URL, and the last cue or playback time you reached. Keep the check pending if you’ve only opened the playlist URL or watched a local export.
The sample package carries video and audio only. If the lesson requires selectable captions, check the required caption track in the learner’s player on that same lesson version before release.
We uploaded a six-second H.264/AAC clip to a local S3-compatible test store and opened the player from a second origin. The playlist returned HTTP 200 with the playlist media type set by the uploader. Each of its three segments returned HTTP 200 with video/mp2t and the player’s allowed origin. The browser loaded all three segments and reached the end. Its video-frame counter reported 150, matching the frames FFmpeg decoded independently.
In a second copy, we changed only the middle filename in the playlist to missing.ts. The playlist and first segment both still returned 200. The browser requested the new name, got a 404 and reported a fragment load error. To diagnose your own lesson, use a fresh browser session, open the Network panel and play through the end. On a 404, resolve the exact filename relative to the playlist and compare it with the stored object key, including case. On a 403, check read access for that object. If the URL opens directly but the player reports a CORS error, inspect the response from the player’s origin.
To evaluate Object Storage with Hivenet for a video library, start with one lesson in a test bucket. Use your intended delivery URL and player domain, then confirm the last segment plays before uploading the rest. We checked the six-second clip in one desktop browser against a local S3-compatible store. Playback on a phone, in a production course player, and through Hivenet’s production delivery service remains untested.
Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.