Introduction
The popularity of high definition televisions, computer
monitors and online streaming has caused the average size of multimedia files
to skyrocket, and with it, the time it takes to convert those files. Files
greater than a GB are not uncommon, and even codecs with optimizations for
multiple CPU cores can take more than 20 minutes to convert those files from
one format to another.
One solution is to break up the file and convert each piece
in parallel across multiple computers. For example, a file over 1.5 GB which
takes over 30 minutes to convert on a single 8 core machine can be reduced down
to ~5 minutes when spread across networked computers. The benefits of grid and
distributed computing are well established and indisputable. However, implementing
them can be a nightmare – converting audio/video files in separate chunks can
result in video hiccups and out of sync audio – but not with LEADTOOLS!
LEAD Technologies, Inc. has been a long time provider of
programmer friendly DirectShow tools, processing filters and codecs. The
latest additions to LEAD’s Multimedia
product line are the Elementary Stream DirectShow Filters and Cloud
SDK. Together, these technologies can create a powerful and robust
solution for handling a large volume of multimedia transcoding jobs in less
time and with more efficient use of computing resources.
Key Multimedia Features in LEADTOOLS SDKs
-
Play, capture and convert any DirectShow stream using high level
.NET, COM and C++ programming interfaces
-
High performance audio and video codecs for H.264, H.263, MPEG-4,
MPEG-2, MJPEG, MJPEG2000, AAC, AC3 and more
-
MPEG-2 Transport Stream with KLV
-
Over 100 DirectShow processing filters
-
Video Streaming and Conferencing
-
Live capture with DVR
-
Seamless integration with LEADTOOLS Cloud SDK for distributed
computing applications
-
Windows Media Foundation SDK in development and coming soon!
SDK Products that Include Multimedia Technology
The Multimedia Conversion Code
The example attached to this article emulates a server farm
where each individual virtual machine (FrmTranscoder)
is given a piece of the audio/video file to convert.
DirectShow Transcoding
LEADTOOLS Multimedia SDKs include a high level .NET
interface that simplifies the development difficulties of DirectShow
programming by automatically building graphs, connecting pins, setting encoder
properties, etc. To convert a file, one simply creates a Leadtools.Multimedia.ConvertCtrl,
sets the conversion settings such as audio/video encoders and
source/destination files, and LEADTOOLS does the rest. Here’s a snippet from
the FrmTranscoder_Load event in our example:
_transcodeData.TranscodeResult.Status = LTESHelper.Status.Working;
convertCtrl1 = new ConvertCtrl();
convertCtrl1.LoadSettingsFromFile(_transcodeData.SettingsFile, ConvertSettings.Compressors);
convertCtrl1.TargetFormat = TargetFormatType.LTES;
convertCtrl1.Complete += new EventHandler(convertCtrl1_Complete);
convertCtrl1.ErrorAbort += new ErrorAbortEventHandler(convertCtrl1_ErrorAbort);
convertCtrl1.Progress += new ProgressEventHandler(convertCtrl1_Progress);
convertCtrl1.SourceFile = _transcodeData.Sourcefile;
convertCtrl1.TargetFile = _transcodeData.DestFile;
convertCtrl1.StartConvert();
Elementary Stream Filters
The LEAD Elementary Stream Source and Writer filters
intelligently choose and synchronize the split/merge points. They allow large
files to be broken up, converted separately, and joined back together into a
file that is indistinguishable from one converted by single process.
The conversion task is started by using a ConvertCtrl
with the TargetFormat property set to TargetFormatType.LTES.
When you call StartConvert, the Elementary Stream
Writer goes to work and splits the audio and video streams into separate files
and also saves the catalog XML file which is used to keep track of where each
clip or piece is located. As you can see below, four clips were made from a
single file (3 video & 1 audio):
="1.0" ="utf-8"
<ltesCatalog>
<stream id="stream 1" type="{73646976-0000-0010-8000-00AA00389B71}" >
<clip src="split-1-c1.ltes" start="0" duration="1349333333" />
<clip src="split-1-c2.ltes" start="0" duration="1350000000" />
<clip src="split-1-c3.ltes" start="0" duration="1337333334" />
</stream>
<stream id="stream 2" type="{73647561-0000-0010-8000-00AA00389B71}" >
<clip src="split-2.ltes" start="0" duration="4037021315" />
</stream>
</ltesCatalog>
Now that the source file is divided, each chunk can be
divvyed up between the computers (in this example, FrmTranscoder).
After each virtual machine has finished, the Elementary Stream Reader is used
to combine them back together for the final result.
int machineCounter = 1;
for (int streamIndex = 0; streamIndex < splitCatalogStreams.Length; streamIndex++)
{
for (int clipIndex = 0; clipIndex < splitCatalogStreams[streamIndex].Clips.Length; clipIndex++)
{
LTESHelper.TranscodeData transcodeData = new LTESHelper.TranscodeData();
transcodeData.Sourcefile = Path.Combine(_txtTempFolder.Text,
splitCatalogStreams[streamIndex].Clips[clipIndex].SourcePath);
string newFilename = splitCatalogStreams[streamIndex].Clips[clipIndex].SourcePath.Replace("split", "merge");
transcodeData.DestFile = Path.Combine(_txtTempFolder.Text, newFilename);
mergeCatalogStreams[streamIndex].Clips[clipIndex].SourcePath = newFilename;
transcodeData.SettingsFile = _conversionSettingsPath;
transcodeData.MachineName = splitCatalogStreams[streamIndex].Type ==
Constants.MEDIATYPE_Video ? String.Format("Transcoder {0} (Video)",
machineCounter) : String.Format("Transcoder {0} (Audio)", machineCounter);
transcodeData.TargetFormat = LTMMFormatToLTESFormat(tempConverter.TargetFormat);
FrmTranscoder transcoder = new FrmTranscoder();
transcodeMachines.Add(transcoder);
transcoder.TranscodeData = transcodeData;
transcoder.PreviewVisible = _chkEnablePreview.Checked;
transcoder.MdiParent = this.MdiParent;
transcoder.FormClosed += new FormClosedEventHandler(transcoder_FormClosed);
transcoder.Show();
Log(String.Format("Sent {0} to {1}", transcodeData.Sourcefile, transcodeData.MachineName));
machineCounter++;
}
}
Cloud Integration
Even on the same machine, the solution above can
dramatically decrease the total conversion time since you can utilize more of
the CPU. If more processing power is needed, the Cloud SDK provides an easy to
use framework to manage distributed tasks among any number of worker machines.
Though the attached example project is just an emulator, it
can be easily ported to use the LEADTOOLS Cloud SDK where FrmMain
and FrmSettings make up the central server and FrmTranscoder is refactored to a DLL that gets executed on
each individual worker machine.
Conclusion
LEADTOOLS provides developers with access to the world’s
best performing and most stable imaging libraries in an easy-to-use, high-level
programming interface enabling rapid development of business-critical
applications.
Multimedia/DirectShow Transcoding is only one of the many
technologies LEADTOOLS has to offer. For more information on our other
products, be sure to visit our home
page, download a free fully functioning evaluation SDK, and take advantage
of our free technical support during your evaluation.
Download the Full Multimedia Example
You can download a fully functional demo which includes the
features discussed above. To run this example you will need the following:
Support
Need help getting this sample up and going? Contact
our support team for free technical support! For pricing or licensing
questions, you can contact our sales team (sales@leadtools.com)
or call us at 704-332-5532.