Click here to Skip to main content
15,897,519 members
Articles / Multimedia

Multimedia Transcoding Across Multiple Computers with LEADTOOLS

7 Jan 2013CPOL4 min read 35.2K   442   5  
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!

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Leadtools.Multimedia;
using LTESWriterLib;
using System.Runtime.InteropServices;

namespace MultiMachineTranscoding
{
   public partial class FrmTranscoder : Form
   {
      public FrmTranscoder()
      {
         InitializeComponent();
      }

      private LTESHelper.TranscodeData _transcodeData;
      public LTESHelper.TranscodeData TranscodeData
      {
         get { return _transcodeData; }
         set { _transcodeData = value; }
      }

      private bool _previewVisible;
      public bool PreviewVisible
      {
         get { return _previewVisible; }
         set { _previewVisible = value; }
      }

      private void FrmTranscoder_FormClosing(object sender, FormClosingEventArgs e)
      {
         convertCtrl1.StopConvert();
         convertCtrl1.ResetSource();
         convertCtrl1.ResetTarget();
         convertCtrl1.Window = IntPtr.Zero;
      }

      private void FrmTranscoder_Load(object sender, EventArgs e)
      {
         this.Text = _transcodeData.MachineName;
         _transcodeData.TranscodeResult.Status = LTESHelper.Status.Working;

         try
         {
            convertCtrl1.LoadSettingsFromFile(_transcodeData.SettingsFile, ConvertSettings.Compressors);
            convertCtrl1.TargetFormat = TargetFormatType.LTES;
            convertCtrl1.TargetFile = String.Empty;
            UpdateWriter();

            if (_previewVisible)
            {
               convertCtrl1.Preview = true;
               convertCtrl1.Window = _pbPreview.Handle;
            }

            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();
         }
         catch (Exception ex)
         {
            _transcodeData.TranscodeResult.Status = LTESHelper.Status.Error;
            _transcodeData.TranscodeResult.ErrorMessage = ex.Message;
            this.BeginInvoke(new MethodInvoker(Close));
         }
      }

      void convertCtrl1_Progress(object sender, ProgressEventArgs e)
      {
         _pbProgress.Value = e.percent;
         this.Text = String.Format("{0} - {1}%", _transcodeData.MachineName, e.percent);
      }

      void convertCtrl1_ErrorAbort(object sender, ErrorAbortEventArgs e)
      {
         _transcodeData.TranscodeResult.Status = LTESHelper.Status.Error;
         _transcodeData.TranscodeResult.ErrorMessage = e.errorMessage;
         this.BeginInvoke(new MethodInvoker(Close));
      }

      void convertCtrl1_Complete(object sender, EventArgs e)
      {
         _transcodeData.TranscodeResult.Status = LTESHelper.Status.Success;
         this.BeginInvoke(new MethodInvoker(Close));
      }

      void UpdateWriter()
      {
         //Update the split count in the LTESWriter filter
         LTESWriter ltesWriter = null;
         try
         {
            ltesWriter = convertCtrl1.GetSubObject(ConvertObject.TargetFilter) as LTESWriter;
            if (ltesWriter == null)
               throw new Exception("Unable to obtain LTESWriter from graph");

            ltesWriter.VideoClipMethod = eLTESWriter_ClipMethod.eLTESWriter_ClipMethod_None;
            ltesWriter.TargetFormat = _transcodeData.TargetFormat;
         }
         finally
         {
            if (ltesWriter != null)
            {
               Marshal.ReleaseComObject(ltesWriter);
               ltesWriter = null;
            }
         }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Help desk / Support LEAD Technologies, Inc.
United States United States
Since 1990, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact sales@leadtools.com or support@leadtools.com.
This is a Organisation (No members)


Comments and Discussions