tags:

views:

263

answers:

4

What I'm trying to do is take a 'input' video file (I can make it whatever file type will make this the easiest) and then, through my code, add text to the video file.

So, for example, it would take 'Sample1.mpg' and output 'Sample2.mpg'. It wouldn't show the video (I've found some tutorials that talk about overlaying text as the video plays; but not actually modifying the video file.

Basically, I'd like to be able to say, 'From seconds 1 to 200, draw 'Hi Mom' at position 0,0 with this font' and have that saved in the outputed video. Whenever you run the outputted video, with any player, you'd end up seeing the text; because it'd be part of the video file.

I've heard claims like, 'DirectShow!' but I'd really welcome anything slightly more specific.

A: 

Check out the Adobe Premier API. I'm not sure if there are .NET libraries or if you have to go interop.

JP Alioto
A: 

Take a look at this page on Overlaying Text and Graphics. It offers both a VB and C++ example.

Also, the site discusses Direct Show.

You could also look at the Windows SDK which I recall containing some examples.

NoahD
+1  A: 

You can use an extremely powerful scripting language called avisynth

link: http://avisynth.org/

It works with ANY file you can play, it uses directshow.

Just install it, it's basically installing a VFW codec, but very easy. Open notepad and type

DirectShowSource("C:\dir\filename.extension")
Subtitle("Put Your text here")

Save it as "any name.avs"

And THAT'S IT. Now open it with any avi-capable application (you can even name it avi if you want!) and re-encode the video, or do processing. very easy and automatic. it works for pictures too.

For a full reference of the Subtitle() capabilities go here: http://avisynth.org/mediawiki/Subtitle

of course, avisynth can do wonders if you master it, like printing the system date on every frame of a recording (useful for security cams) or even complex processing like top-line noise reduction, sharpening and many, many other tasks, through external pugins.

External Pugin reference: http://avisynth.org/mediawiki/External_plugins

Easily downloadable plugins: http://avisynth.org/warpenterprises/

It's as simple as it gets. 2 lines of code and you have a openable, seekable, processable, convertable fully-compatible and less than 1 KB AVI (the subtitles are added on-the-fly when you open the AVS on your app)

Camilo Martin
+1  A: 

Hi, I'd suggest reading more into this:

http://stackoverflow.com/questions/378107/options-for-predictable-frame-capture-in-net-application

And then using

Graphics g = Graphics.FromImage(bitmap);

To get the frame into .NET and then look at a using this:

GraphicsPath path = new GraphicsPath();
path.AddString("Yadda", font.FontFamily, (int)font.Style, font.Size, rect, format);

Then use

g.FillPath(..path..)

to add the drawing to the frame.

How to stick it back into the MPG??? I guess you're then back to using the code/project referenced in the link at the top.

It just seems to me to be a case of extract BMP frame, use .NET drawing to add stuff to it, then reinsert. Looking at how CAPTCHAs are made in .NET is probably helpful.

Good luck!!

Luke Puplett