I am developing win forms application to split,join,Add watermark(both text and image) to a split video file.i have completed all the above said operations.the problem is when i try to join watermarked videos which i have watermarked with my developed application i get an exception "An invalid Media type was specified" if i try to join the split video without watermark its getting joined without errors.
I am using "DirectShow" for Joining videos
here is the code to join video files:
private void FrmVideoJoinStatus_Load(object sender, EventArgs e)
{
LoadList();
try
{
if (ds == null)
{
MyCallback pVideo = new MyCallback(tbVideo, tbTime, tbElapsed, progressBar1);
MyCallback pAudio = new MyCallback(tbAudio);
ds = new DESCombine(30, 24, 1024, 768);
foreach (Chunk c in listBox1.Items)
{
if (c.sVideoFile == c.sAudioFile)
{
ds.AddAVFile(c.sVideoFile, c.lStart, c.lEnd);
}
else
{
if (c.sVideoFile != null)
{
ds.AddVideoFile(c.sVideoFile, c.lStart, c.lEnd);
}
if (c.sAudioFile != null)
{
ds.AddAudioFile(c.sAudioFile, c.lStart, c.lEnd);
}
}
}
IBaseFilter ibfVideoCompressor = GetVideoCompressor(tbCompressor.Text);
ds.RenderToAVI(ClassTransport.FilePath, ibfVideoCompressor, null, pVideo, pAudio);
ds.Completed += new EventHandler(Completed);
ds.FileCompleted += new EventHandler(FileCompleted);
ds.StartRendering();
progressBar1.Maximum = (int)(ds.MediaLength / (DESCombine.UNITS / 10));
progressBar1.Step = progressBar1.Maximum / 20;
progressBar1.Value = 0;
tbStatus.Text = "Running";
}
else
{
ds.Cancel();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
ds.Dispose();
ds = null;
}
}
#region load Videos To list From Table
private void LoadList()
{
DataTable dt = ClassTransport.Table;
foreach (DataRow row in dt.Rows)
{
Chunk c = new Chunk(
row["File"].ToString(),
row["File"].ToString(),
"0",
"-1");
int i = listBox1.Items.Add(c);
listBox1.SelectedIndex = i;
}
}
#endregion
Code for water mark Video
#region WaterMark
[STAThreadAttribute]
private void AddWaterMark(object row)
{
DataRow Drow = (DataRow)(row);
DirectoryInfo info = new DirectoryInfo(Convert.ToString(Drow["FilePath"]));
string[] filename = info.Name.Split('.');
string outputFile = ClassTransport.ClipSavePath + "\\" + filename[0] + "WaterMarked" + info.Extension;
using (ITimeline timeline = new DefaultTimeline(15))
{
timeline.AddAudioGroup().AddTrack();
IGroup videoGroup = timeline.AddVideoGroup(32, 720, 480);
ITrack videoTrack = videoGroup.AddTrack();
ITrack watermarkTrack = videoGroup.AddTrack();
timeline.AddVideoWithAudio(Drow["FilePath"].ToString());
Bitmap image, BImage,TextImage;
image = new Bitmap(int.Parse(ConfigurationSettings.AppSettings["VideoWidth"].ToString()), int.Parse(ConfigurationSettings.AppSettings["VideoHeight"].ToString()));
BImage = new Bitmap(int.Parse(ConfigurationSettings.AppSettings["VideoWidth"].ToString()), int.Parse(ConfigurationSettings.AppSettings["VideoHeight"].ToString()));
TextImage = new Bitmap(int.Parse(ConfigurationSettings.AppSettings["VideoWidth"].ToString()), int.Parse(ConfigurationSettings.AppSettings["VideoHeight"].ToString()));
TextImage = CreateBitmapImage(Drow);
image = CloneImage(TextImage);
if (Drow["Logo"] != null)
{
BImage = ((Bitmap)Image.FromFile(Drow["Logo"].ToString()));
image = CloneLogoWithImage(BImage, image, Drow);
}
IClip watermarkClip = watermarkTrack.AddImage(image, 0, videoTrack.Duration);
watermarkClip.AddEffect(0, watermarkClip.Duration, StandardEffects.CreateAlphaSetterRamp(((double)Drow["Opacity"])));
watermarkTrack.AddTransition(0, videoTrack.Duration,
StandardTransitions.CreateKey(KeyTransitionType.Alpha, null, null, null, null, null),
false);
IRenderer renderer = new WindowsMediaRenderer(timeline, outputFile, WindowsMediaProfiles.HighQualityVideo);
using ((System.IDisposable)renderer)
{
renderer.Render();
}
}
Drow["filePath"] = outputFile;
}
#endregion
Please help me if any possible suggestions..thank you :rolleyes: