Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EncodingAndPackagingExample] Add HLS output format support #226

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public async Task EncodeAndPackageAsync(Uri mp4BlobUri, Uri outputStorageUri, Ca

// Prepare ffmpeg command lines.
var mpdFile = $"{Path.GetFileNameWithoutExtension(inputFile)}.mpd";
var hlsFile = $"{Path.GetFileNameWithoutExtension(inputFile)}.m3u8";
FFMpegArgumentProcessor ffmpegCommand;

if (ffprobeAnalyse.VideoStreams != null)
Expand All @@ -105,16 +106,24 @@ public async Task EncodeAndPackageAsync(Uri mp4BlobUri, Uri outputStorageUri, Ca
.WithCustomArgument("-s:v:1 1280x720")
.WithCustomArgument("-s:v:2 1920x1080")
.WithCustomArgument("-adaptation_sets \"id=0,streams=v id=1,streams=a\"")
/* HLS related settings, comments out if you don't need generate hls playlist */
.WithCustomArgument("-hls_playlist 1")
.WithCustomArgument($"-hls_master_name {hlsFile}")
/* HLS settings done */
.ForceFormat("dash"));
}
else
else
{
// For audio only stream.
ffmpegCommand = FFMpegArguments
.FromFileInput(inputFile)
.OutputToFile(mpdFile, overwrite: true, args => args
.WithAudioCodec(AudioCodec.Aac)
.WithCustomArgument("-adaptation_sets \"id=0,streams=a\"")
/* HLS related settings, comments out if you don't need generate hls playlist */
.WithCustomArgument("-hls_playlist 1")
.WithCustomArgument($"-hls_master_name {hlsFile}")
/* HLS settings done */
.ForceFormat("dash"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public async Task EncodingAndPackagingToolTest()
await process.WaitForExitAsync();
Assert.Equal(0, process.ExitCode);

// Verify dash related files.
// We should have the output mpd file.
var blob = new BlobClient(new Uri($"{outputContainerUri}/bunny.640x480.15fps.mpd"), _azureCrendentail);
using (var stream = await blob.OpenReadAsync())
Expand Down Expand Up @@ -109,6 +110,24 @@ public async Task EncodingAndPackagingToolTest()
}
}

// Verify hls related files.
// We should have the output master hls file.
blob = new BlobClient(new Uri($"{outputContainerUri}/bunny.640x480.15fps.m3u8"), _azureCrendentail);
using (var stream = await blob.OpenReadAsync())
{
Assert.True(stream.Length > 400);
}

// We should have 4 hls playlist file.
for (var i = 0; i < 4; ++i)
{
blob = new BlobClient(new Uri($"{outputContainerUri}/media_{i}.m3u8"), _azureCrendentail);
using (var stream = await blob.OpenReadAsync())
{
Assert.True(stream.Length > 1000);
}
}

// Delete the container if success.
var container = new BlobContainerClient(new Uri(outputContainerUri), _azureCrendentail);
await container.DeleteAsync();
Expand Down
Loading