HLS output
HLS sink block can be used to create an HLS server from any video/audio source. SDK includes an optional HTTP server. Alternatively, you can use IIS, Nginx, Apache, or any other web server.
Use the HLSSinkSettings
class to set the parameters.
Block info
Name: HLSSinkBlock.
Pin direction | Media type | Pins count |
---|---|---|
Input audio | audio/x-raw | one |
audio/x-ac3 | ||
audio/x-aac | ||
audio/x-mp3 | ||
Input video | video/x-raw | one |
video/x-h264 | ||
video/x-h265 |
The sample pipeline
Sample code
// Pipeline
var pipeline = new MediaBlocksPipeline();
pipeline.OnError += Pipeline_OnError;
// video and audio sources
var virtualVideoSource = new VirtualVideoSourceSettings
{
Width = 1280,
Height = 720,
FrameRate = VideoFrameRate.FPS_25,
};
var videoSource = new VirtualVideoSourceBlock(virtualVideoSource);
var virtualAudioSource = new VirtualAudioSourceSettings
{
Channels = 2,
SampleRate = 44100,
};
var audioSource = new VirtualAudioSourceBlock(virtualAudioSource);
// H264/AAC encoders
var h264Settings = new OpenH264EncoderSettings();
var h264Encoder = new H264EncoderBlock(h264Settings);
var aacEncoder = new AACEncoderBlock();
pipeline.Connect(videoSource.Output, h264Encoder.Input);
pipeline.Connect(audioSource.Output, aacEncoder.Input);
// 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 = "http://localhost:8088/",
SendKeyframeRequests = true,
TargetDuration = 5,
Custom_HTTP_Server_Enabled = true,
Custom_HTTP_Server_Port = 8088
};
var hlsSink = new HLSSinkBlock(settings);
// Connect everything
pipeline.Connect(videoSource.Output, h264Encoder.Input);
pipeline.Connect(audioSource.Output, aacEncoder.Input);
pipeline.Connect(h264Encoder.Output, hlsSink.CreateNewInput(MediaBlockPadMediaType.Video));
pipeline.Connect(aacEncoder.Output, hlsSink.CreateNewInput(MediaBlockPadMediaType.Audio));
// Start
pipeline.Start();
Sample applications
Platforms
Windows, macOS, Linux, iOS, Android.