#
How to perform HLS network streaming?
Video Capture SDK .Net Video Edit SDK .Net Media Blocks SDK .Net Media Player SDK .Net
HTTP Live Streaming (HLS) is an adaptive streaming communications protocol developed by Apple. HLS breaks the overall stream into a sequence of small HTTP-based file downloads, allowing for efficient, high-quality streaming of digital media over the internet. It adjusts video quality dynamically according to available bandwidth, ensuring optimal user experience.
HLS is based on HTTP, and you need to install an HTTP server or use small internal server provided by SDK.
#
Media Blocks SDK sample
This sample demonstrates how to perform HLS network streaming using Media Blocks SDK.
// Set URL
const string URL = "http://localhost:8088/";
// Create H264 encoder
var h264Settings = new OpenH264EncoderSettings();
var h264Encoder = new H264EncoderBlock(h264Settings);
// Create AAC encoder
var aacEncoder = new AACEncoderBlock();
// Create HLS sink
var settings = new HLSSinkSettings
{
Location = Path.Combine(AppContext.BaseDirectory, "segment_%05d.ts"),
MaxFiles = 10,
PlaylistLength = 5,
PlaylistLocation = Path.Combine(AppContext.BaseDirectory, "playlist.m3u8"),
PlaylistRoot = URL,
SendKeyframeRequests = true,
TargetDuration = 5,
Custom_HTTP_Server_Enabled = true, // Use internal HTTP server
Custom_HTTP_Server_Port = 8088 // Port for internal HTTP server
};
var hlsSink = new HLSSinkBlock(settings);
// Connect video and audio sources to encoders (we assume that videoSource and audioSource are already created)
pipeline.Connect(videoSource.Output, h264Encoder.Input);
pipeline.Connect(audioSource.Output, aacEncoder.Input);
// Connect encoders to HLS sink
pipeline.Connect(h264Encoder.Output, hlsSink.CreateNewInput(MediaBlockPadMediaType.Video));
pipeline.Connect(aacEncoder.Output, hlsSink.CreateNewInput(MediaBlockPadMediaType.Audio));
// Start
await pipeline.StartAsync();
You can use the Media Blocks SDK to stream live video or existing files to HLS. The SDK provides a flexible and powerful API for creating custom media processing pipelines.
#
Video Capture SDK .Net sample
Video Capture SDK .Net provide a simple way to perform HLS network streaming from live video sources.
#
VideoCaptureCoreX engine
// Create HLS sink settings
var settings = new HLSSinkSettings
{
Location = Path.Combine(AppContext.BaseDirectory, "segment_%05d.ts"),
MaxFiles = 10,
PlaylistLength = 5,
PlaylistLocation = Path.Combine(AppContext.BaseDirectory, "playlist.m3u8"),
PlaylistRoot = edStreamingKey.Text,
SendKeyframeRequests = true,
TargetDuration = 5,
Custom_HTTP_Server_Enabled = true,
Custom_HTTP_Server_Port = new Uri(edStreamingKey.Text).Port
};
// Create HLS output
var hlsOutput = new HLSOutput(settings);
// Create video and audio encoders with default settings
hlsOutput.Video = new OpenH264EncoderSettings();
hlsOutput.Audio = new VOAACEncoderSettings();
// Add HLS output to video capture object
videoCapture.Outputs_Add(hlsOutput, true);
#
VideoCaptureCore engine
VideoCapture1.Network_Streaming_Enabled = true;
VideoCapture1.Network_Streaming_Audio_Enabled = true;
VideoCapture1.Network_Streaming_Format = NetworkStreamingFormat.HLS;
var hls = new HLSOutput
{
HLS =
{
SegmentDuration = 10, // Segment duration in seconds
NumSegments = 5, // Number of segments in playlist
OutputFolder = "c:\\hls\\", // Output folder
PlaylistType = HLSPlaylistType.Live, // Playlist type
Custom_HTTP_Server_Enabled = true, // Use internal HTTP server
Custom_HTTP_Server_Port = 8088 // Port for internal HTTP server
}
};
VideoCapture1.Network_Streaming_Output = hls;
#
Video Edit SDK .Net sample
Using Video Edit SDK .Net, you can perform HLS network streaming from existing video files.
#
VideoEditCore engine
VideoEdit1.Network_Streaming_Enabled = true;
VideoEdit1.Network_Streaming_Audio_Enabled = true;
VideoEdit1.Network_Streaming_Format = NetworkStreamingFormat.HLS;
var hls = new HLSOutput
{
HLS =
{
SegmentDuration = 10, // Segment duration in seconds
NumSegments = 5, // Number of segments in playlist
OutputFolder = "c:\\hls\\", // Output folder
PlaylistType = HLSPlaylistType.Live, // Playlist type
Custom_HTTP_Server_Enabled = true, // Use internal HTTP server
Custom_HTTP_Server_Port = 8088 // Port for internal HTTP server
}
};
VideoEdit1.Network_Streaming_Output = hls;
All applications should include an HTML file with a video player. Example player available in the GitHub repository.
Visit our GitHub page to get more code samples.