Skip to content

Instantly share code, notes, and snippets.

@andrej-peterka
Created December 15, 2011 07:27
Show Gist options
  • Save andrej-peterka/1480198 to your computer and use it in GitHub Desktop.
Save andrej-peterka/1480198 to your computer and use it in GitHub Desktop.
SmoothTransmuxer concurrent / consecutive processing benchmark
using System;
using System.IO;
using HighPerformanceTimer;
using Microsoft.Web.Media.TransformManager.MP4toSmooth;
namespace TransPepe
{
class Program
{
static void Main(string[] args)
{
/* define source files */
string[] source_files = new[]
{
@"o:\transform_test\bbb_sd_1900.mp4",
@"o:\transform_test\bbb_sd_1465.mp4",
@"o:\transform_test\bbb_sd_1130.mp4",
@"o:\transform_test\bbb_sd_800.mp4",
@"o:\transform_test\bbb_sd_600.mp4",
@"o:\transform_test\bbb_sd_530.mp4",
@"o:\transform_test\bbb_sd_400.mp4",
@"o:\transform_test\bbb_stereo_128k.m4a"
};
/* define output manifests */
string ism_file = @"o:\transform_test\bbb_sd.ism";
string ismc_file = @"o:\transform_test\bbb_sd.ismc";
/*
* The following two code blocks mimic the use of the code found in the file
* %ProgramFiles%\IIS\Transform Manager\Microsoft.Web.Media.TransformManager.MP4toSmooth.dll
*
* to convert MP4 files to Smooth Streaming (ISMV and ISMA files).
*
* The first one processes the files as they are processed by the task.
* That is, opens all the MP4 files *at once* and starts writing ISMV files.
*
* It's basically reading each MP4 file and transmuxing it to ISMV. But all 7 files at once. Bad for performance.
* This method, of course, produces valid ISMV files and manifests.
* (though I disabled the generation of manifests for benchmarking purposes)
*
* The second block is a hack. It processes one MP4 file at a time.
* By doing this, we can achieve ~30% performance improvement on a 7200RPM SATA drive.
*
* But since it's not the way the SmoothTransmuxer class was supposed to be used, it doesn't produce valid manifests.
*
* Also, generated ISMV files differ from the ones generated by the first block.
* I'm not sure whether they are valid or not, but that's beyond the scope of this test, which just benchmarks the speed of conversion.
*
*/
/* concurrent processing */
HiPerfTimer hpt = new HiPerfTimer();
hpt.Start();
using (SmoothTransmuxer trans_conc = new SmoothTransmuxer())
{
MP4SourceTrackCollection[] source_tracks_conc = new MP4SourceTrackCollection[source_files.Length];
for (int i = 0; i < source_tracks_conc.Length; i++)
{
source_tracks_conc[i] = new MP4SourceTrackCollection(source_files[i]);
foreach (MP4SourceTrack mp4 in source_tracks_conc[i])
{
string out_file = mp4.Format.IsAudio ? Path.ChangeExtension(source_files[i], ".isma") : Path.ChangeExtension(source_files[i], ".ismv");
trans_conc.AddQualityLevel(mp4, mp4.AverageBitrate, 0, File.Open(out_file, FileMode.Create));
}
}
/* start remuxing */
do ; while (trans_conc.ExecuteNextTask());
/* write server & client manifests
* disabled for benchmarking purposes, since the second method can't write manifests
*/
//using (FileStream server_manifest = File.Open(ism_file, FileMode.Create),
// client_manifest = File.Open(ismc_file, FileMode.Create))
//{
// trans_conc.WriteManifests(server_manifest, client_manifest);
//}
trans_conc.Close();
}
hpt.Stop();
Console.WriteLine("concurrent: {0:F4} seconds", hpt.Duration);
hpt = new HiPerfTimer();
hpt.Start();
/* consecutive processing */
SmoothTransmuxer trans_cons = new SmoothTransmuxer();
MP4SourceTrackCollection[] source_tracks = new MP4SourceTrackCollection[source_files.Length];
for (int i = 0; i < source_tracks.Length; i++)
{
source_tracks[i] = new MP4SourceTrackCollection(source_files[i]);
foreach (MP4SourceTrack mp4 in source_tracks[i])
{
string out_file = mp4.Format.IsAudio ? Path.ChangeExtension(source_files[i], ".isma") : Path.ChangeExtension(source_files[i], ".ismv");
trans_cons = new SmoothTransmuxer();
trans_cons.AddQualityLevel(mp4, mp4.AverageBitrate, 0, File.Open(out_file, FileMode.Create));
}
/* start remuxing */
do ; while (trans_cons.ExecuteNextTask());
trans_cons.Close();
trans_cons.Dispose();
}
hpt.Stop();
Console.WriteLine("consecutive: {0:F4} seconds", hpt.Duration);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment