Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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);

// FPS, BPP, Width, Height
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();



// add a video group, 32bpp, 320x240 (32bpp required to allow for an alpha channel)

IGroup videoGroup = timeline.AddVideoGroup(32, 720, 480);



// add our default video track

ITrack videoTrack = videoGroup.AddTrack();



// add another video track, this will be used to contain our watermark image

ITrack watermarkTrack = videoGroup.AddTrack();



// add the video in "transitions.wmv" to the first video track, and the audio in "transitions.wmv"

// to the first audio track.

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);
//TODO:Adding Logo Call in Form 1
if (Drow["Logo"] != null)
{

BImage = ((Bitmap)Image.FromFile(Drow["Logo"].ToString()));
image = CloneLogoWithImage(BImage, image, Drow);

}

// add the watermark image in, and apply it for the duration of the videoContent

// this image will be stretched to fit the video clip, and in this case is a transparent gif.


IClip watermarkClip = watermarkTrack.AddImage(image, 0, videoTrack.Duration);








// add a alpha setter effect to the image, this will adjust the alpha of the image to be 0.5

// of it's previous value - so the watermark is 50% transparent.

watermarkClip.AddEffect(0, watermarkClip.Duration, StandardEffects.CreateAlphaSetterRamp(((double)Drow["Opacity"])));



// add a transition to the watermark track, this allows the video clip to "shine through" the watermark,

// base on the values present in the alpha channel of the watermark track.

watermarkTrack.AddTransition(0, videoTrack.Duration,

StandardTransitions.CreateKey(KeyTransitionType.Alpha, null, null, null, null, null),

false);

//using (

// render it to windows media

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:
Posted
Updated 27-Jul-10 0:41am
v2

1 solution

i too even trying out for video encoding let me know if u got idea
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900