PDA

View Full Version : problems with AddMediaObject2 in PowerPoint, importing videos sometimes fails



candphys
03-30-2015, 08:40 AM
Hi all,

I was wondering, if there is a maximum number of videos in ppt that one can import via "AddMediaObject2" in VBA?
I get a strange error, if I try to import several videos with the following macro (which is a dummy version just to show the problem) :



Sub loadVideos()
Const path As String = "D:\video.avi"
For folder = 1 To 20
Debug.Print "folder: " & folder
Set sld = ActivePresentation.Slides.Add(ActivePresentation.Slides.count + 1, ppLayoutTitleOnly)
sld.Select
sld.Shapes.Title.TextFrame.TextRange.text = "CFD-Results: " & folder

For i = 1 To 8
Dim oShp As Shape
Set oShp = sld.Shapes.AddMediaObject2(FileName:=(path), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=-1, _
Height:=-1)

Next i
Next folder
End Sub


It works as expected with smaller video files (so code should be alright!?) but I get the error

"Runtime error -214....
Shapes.AddMediaObject2 : Invalid request + some complaint about video codecs
"

if I use it with larger videos or alternatively increase the number of videos on each slide or the number of slides containing videos.
So I suppose there may be some internal stack or cache memory problem in ppt. Is there any restriction to the number or size of media files that can be loaded in ppt?

I would be very grateful, if someone could tell me that it's either some bug in ppt or may point to some sort of solution. Maybe I can configure ppt to accept more/bigger videos?

Many thanks.

John Wilson
03-30-2015, 09:59 PM
Are you sure the videos will insert manually (ie the codec is OK)

I inserted 8 times 0.5 Gb videos no problem with similar code is that the sort of size you are working with.

My code


Sub loadVideos()
Dim osld As Slide
Dim i As Integer

Const vidpath As String = "C:\Users\John\Desktop\kilimanjaro2.avi"
For i = 1 To 8
Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutTitleOnly)
osld.Shapes.Title.TextFrame.TextRange = "Video " & CStr(i)
Dim oShp As Shape
Set oShp = osld.Shapes.AddMediaObject2(FileName:=(vidpath), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0)
oShp.Left = ActivePresentation.PageSetup.SlideWidth / 2 - oShp.Width / 2
oShp.Top = ActivePresentation.PageSetup.SlideHeight / 2 - oShp.Height / 2
Next i
End Sub

candphys
03-31-2015, 10:30 AM
Hi John,

thanks for your answer.
Yes, I have checked that the videos can be inserted manually and do work in ppt. Actually the first 75 videos (in my special case I guess) inserted by the vba-macro also work, but then the macro quits with the above error. The error code points out to video codecs, you're right, but why do they work if I insert them manually and why do the first few videos also work then?
My videos are each smaller than 0.5 Gb, but there are more of them than 8 and distributed on different slides. I have no idea, if this plays a role. Maybe it is just an error special to my system or vba-script. I will try out more and keep you updated.

candphys
04-02-2015, 05:06 AM
Hi there,

I tried out John's version of the code for inserting several videos in ppt and it works as well for me, if I leave it as is. BUT: If I increase the number of videos to be inserted, the same error I already experienced comes up. As I want to include several videos on each slide I tested the following version (slightly adapted based on John's; only inserted a second loop!):


Sub loadVideos()
Dim osld As Slide
Dim i As Integer

Const vidpath As String = "D:\ani.avi"
For i = 1 To 30
Set osld = ActivePresentation.Slides.Add(ActivePresentation.Slides.count + 1, ppLayoutTitleOnly)
osld.Shapes.Title.TextFrame.TextRange = "Video " & CStr(i)
For j = 1 To 6
Dim oShp As Shape
Set oShp = osld.Shapes.AddMediaObject2(FileName:=(vidpath), _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0)
oShp.Left = j * 50 + ActivePresentation.PageSetup.SlideWidth / 2 - oShp.Width / 2
oShp.Top = ActivePresentation.PageSetup.SlideHeight / 2 - oShp.Height / 2
Next j
Next i
End Sub

' 20x8 gives error
' 10x4 works
' 20x2 works
' 40x2 works
' 20x3 works
' 20x4 works
' 30x4 works
' 40x4 gives error
' 170x1 gives error
' 30x6 gives error



in which I also tried out several combinations of the two loops (results as can be seen above: lower numbers of videos work, greater numbers >160 in my special case do not). The video file that I used for testing is 15.6Mb in size. I also tried John's original version with just a greater number of videos in the single loop and it gives the error as well as I increase the number of videos. I also had a look on ppt's memory usage while the videos get inserted: The RAM is NOT completely filled, but the error may occur, if ppt-memory approaches the 1Gb mark.

Does that help to pinpoint the error? Maybe it's still with my code or my system...

Thank you.