Adding Subtitles to a WMV file

Topics: Developer Forum, Project Management Forum, User Forum
Jan 21, 2009 at 6:30 AM
Hi there! I am trying to figure out how to insert subtitles into a WMV movie file. Any ideas on how to  do that with Splicer? Thanks in advance. -Sergio
Coordinator
Jan 21, 2009 at 7:37 PM
You could do this by implementing your own watermark participant (see ImageWatermarkParticipant for an example and it's base class AbstractWatermarkParticipant) - basically you would want to implement your own participant that's loaded with the stack of subtitles and associated points in time when they should be displayed, for how long etc.  The AbstractWatermarkParticipant is passed an Image (so you can use general drawing commands to render on top of it, i.e. text) as well as double value called sampleTime, which gives you the position in seconds that this frame occurs.

It should be fairly easy to implement - though if it's a full length movie you may find it quite slow to process compared to existing native code solutions for implementing Hardcoded subs, because the managed code drawing commands are not the fastest.  There are some basic optimizations that would help (like rendering each subtitles text once, storing that as an image with transparency, then just blitting over the top of the frames image.

Another solution is to just create a specific track in the timeline for subtitles (above the video track) - then render each subtitle as an Image the same size as the source video (with a transparent background), and place the image in the track at the apropriate time, and for the apropriate length.  This will make rendering the clip a lot faster, but prevents you from applying more subtle blending affects for the text because you can't interrogate the pixels beneath the subtitles.  Note that with this approach you need to render the images as transparent gifs, not pngs, as DirectShow doesn't support png transparency correctly - which obviously makes it hard to do things like applying a "semi-transparent" glow around your subtitle text.
Oct 28, 2010 at 7:12 PM

Would you be able to give some additional guidance on this?

I used your slideshow example program (slightly modified for images and duration, and attempted to add a second track, which would display some transparent gifs.

The rendered video showed the gifs but not the original images.

After the duration fo rthe gifs had completed (45 seconds) the final image of the main video displayed.

Here's the code I tried.

IGroup group = timeline.AddVideoGroup(32, 160, 100);

                ITrack videoTrack = group.AddTrack();
                string imagefilename = textBox1.Text;
                IClip clip1 = videoTrack.AddImage("I:\\temp\\image1.jpg", 0, 15); // play first image for a little while
                IClip clip2 = videoTrack.AddImage("I:\\temp\\image2.jpg", 0, 15); // and the next
                IClip clip3 = videoTrack.AddImage("I:\\temp\\image3.jpg", 0, 15); // and finally the last
                IClip clip4 = videoTrack.AddImage("I:\\temp\\image4.jpg", 0, 15); // and finally the last

                ITrack videoTrack2 = group.AddTrack("subtitles",1);
                IClip clip1_2 = videoTrack2.AddImage("I:\\temp\\FastVideo1.gif", 0, 15); // overlay image 
                IClip clip2_2 = videoTrack2.AddImage("I:\\temp\\FastVideo2.gif", 0, 15); // overlay image 
                IClip clip3_2 = videoTrack2.AddImage("I:\\temp\\FastVideo3.gif", 0, 15); // overlay image 

 

Can you give me some help to undertand what I am doing wrong?

 

Thanks.

 

Dec 2, 2010 at 1:58 AM

Can anyone shed any light on what I cold be doing wrong?

Am I doing something stupid with how I am trying to do this?

 

Dec 2, 2010 at 2:01 AM
bittercoder wrote:

Another solution is to just create a specific track in the timeline for subtitles (above the video track) - then render each subtitle as an Image the same size as the source video (with a transparent background), and place the image in the track at the apropriate time, and for the apropriate length.  This will make rendering the clip a lot faster, but prevents you from applying more subtle blending affects for the text because you can't interrogate the pixels beneath the subtitles.  Note that with this approach you need to render the images as transparent gifs, not pngs, as DirectShow doesn't support png transparency correctly - which obviously makes it hard to do things like applying a "semi-transparent" glow around your subtitle text.

 Are you, or anyone else, able to provide any more info about this?

You mention "create a track in the timeline for subtitles" - I've tied to do this as I explained above but my code isn't working how I expected. Any pointers would be greatly appreviated.

 

Dec 2, 2010 at 1:09 PM

Look at the samples page: http://splicer.codeplex.com/wikipage?title=Samples&referringTitle=Home

There's an example showing you how to watermark video. So if you use or render images with a transparent background and then add them to a second track with a transparency effect, you should get what you're looking for.

Dec 2, 2010 at 4:51 PM

Thanks, that's exactly what I need.

 

Dec 3, 2010 at 3:45 PM

Thanks for your previous help. I am now able to included transparent GIFs on a second timeline and show them in from of the images on the other timeline.

I have this working fine with pre-created transparent GIFs, but I really need to be able to create the GIFs on the fly and it apears this isn't an easy thing to do because in c# the MakeTransparent only seems to work for PNG not for GIF.

So I then  thought, I would just create and add transparent PNGs, but it seems that Splicer doesn't support PNG format, because I get errors whenever I try to use PNG files with Splicer.

Anyone got any thoughts or advice?