7

Some Powerpoint presentation contains embedded movies. How to export movies from presentation (or get path to movie file) using C# (VSTO or Oficce COM Api)?

ird
  • 147
  • 1
  • 5
  • Since the movies are embedded, there IS no path to them. They're part of the PPTX file itself. You can get at the embedded media (movies and sound) in a PPTX by unzipping it. Drill down into the folder structure of the unzipped files and there'll be a media folder. The sounds/vids will be inside that. They won't have the original file names, however. Instead they'll have names like Media1.mov etc. – Steve Rindsberg Dec 16 '12 at 19:29

3 Answers3

6

Here is simple demo to do this:

don't forget to add reference to the PowerPoint COM API (Microsoft PowerPoint 12.0 Object Library).

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

then you can get the movies path like this

    private void button1_Click(object sender, EventArgs e)
    {
        PowerPoint.Application app = new PowerPoint.Application();
        app.Visible = Office.MsoTriState.msoTrue;
        //open powerpoint file in your hard drive
        app.Presentations.Open(@"e:\my tests\hello world.pptx");

        foreach (PowerPoint.Slide slide in app.ActivePresentation.Slides)
        {
            PowerPoint.Shapes slideShapes = slide.Shapes;
            foreach (PowerPoint.Shape shape in slideShapes)
            {
                if (shape.Type == Office.MsoShapeType.msoMedia &&
                    shape.MediaType == PowerPoint.PpMediaType.ppMediaTypeMovie)
                {
                    //LinkFormat.SourceFullName contains the movie path 
                    //get the path like this
                    listBox1.Items.Add(shape.LinkFormat.SourceFullName);
                    //or use System.IO.File.Copy(shape.LinkFormat.SourceFullName, SOME_DESTINATION) to export them
                }
            }
        }
    }

I hope this will help.

[Edit:]

regarding Steve comment if you want just the embedded movies, you need just to unpack the .pptx file like any other zip file (e.g. using DotNetZip) and look for embedded videos in this path ([PowerPoint_fileName]\ppt\media)

Issam Ali
  • 1,703
  • 3
  • 15
  • 35
  • 2
    Unfortunately, it won't. The original question specified that the videos were embedded. This example will provide the path to linked (but not embedded) videos. – Steve Rindsberg Dec 16 '12 at 19:27
  • I thought he meant linked videos in this question because getting embedded videos is even easier and it doesn’t need the office COM api , just unpack the .pptx file like any other zip file (e.g. using DotNetZip) and look for embedded videos in this path ([PowerPointfileName]\ppt\media) – Issam Ali Dec 17 '12 at 18:21
  • Yep; I mentioned the unzip trick in a comment to the original post, but you've done one better and supplied the actual path within the zip. Thanks! – Steve Rindsberg Dec 17 '12 at 19:11
4

It is very easy. Extract the file as Zip file using SharpZipLib library, the files will be at ppt\media folder :)

this question will help you:

Programmatically extract embedded file from PowerPoint presentation

And this is the link of sharp-zip-lib:

http://www.icsharpcode.net/opensource/sharpziplib/

Community
  • 1
  • 1
Saw
  • 6,199
  • 11
  • 53
  • 104
1

Checkout the following links

a useful tip to extract .swf file from PowerPoint file

Automation of PowerPoint 97 and PowerPoint 2000 Viewers

santosh singh
  • 27,666
  • 26
  • 83
  • 129