Embedding video inside PPTX

We are inserting video into pptx slides (Using java Aspose jar), in two ways and facing below issues:
1) After dynamically inserting video though UI (input field) in pptx slides, it’s playing video fine but in first frame it displaying “No Image”. Here we have to default the first video frame instead of “No image”, please find attachment for the same.

Below code we are using for embedding video

private static void replaceVideoTextField(Presentation presentation,
String strToFind, Field field,Map<Long, ImageObject> assetImages) {

System.err.println(“replaceVideoTextField ::::::::::::::::::::::::”);
ITextFrame[] textFrames = SlideUtil.getAllTextFrames(presentation, true);

ISlide sld = presentation.getSlides().get_Item(12);

try {

// ImageObject image;
IVideo vid;
// ImageObject img = new ImageObject();
Iterator<Map.Entry<Long, ImageObject>> entries = assetImages.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<Long, ImageObject> entry = entries.next();
System.out.println("Key = " + entry.getKey() + ", Value = "+ entry.getValue());
byte[] ivi = entry.getValue().getImage();
// image=entry.getValue();


vid = presentation.getVideos().addVideo((ivi));

//Add Video Frame
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, vid);

//Set video to Video Frame
vf.setEmbeddedVideo(vid);

//Set Play Mode and Volume of the Video
vf.setPlayMode(VideoPlayModePreset.Auto);
vf.setVolume(AudioVolumeMode.Loud);

// Write the PPTX file to disk
presentation.save(“c:/VideoFrame.pptx”, SaveFormat.Pptx);
}
}

catch(Exception ex){
System.err.println(“error creating video ::::”+ex.getMessage());
}

}
2) If video file is already embedded inside the pptx file, after pptx file generation video place holder is blank and video is displaying only on mouseover.

3) Instead of using this slide index (12) in below code, is there any way to append the video dynamically to some place holder in pptx slides?
ISlide sld = presentation.getSlides().get_Item(12)

Note: Is there any restriction regarding video format type like .mp4, .wmb etc., for embedding video inside pptx slides.

Hi Laurie,


Thank you for your interest in Aspose.Slides.

I have observed your comments and like to share with you that Video frame could be filled with a picture. You need to extract first frame of a video by using some third party tool and then you can set that image by using the below sample code.

IPPImage img =null;
img = pres.getImages().addImage(new FileInputStream(new File(“C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg”)));
vf.getFillFormat().setFillType(FillType.Picture);
vf.getFillFormat().getPictureFillFormat().getPicture().setImage(img);

where vf is an instance of IVideoFrame.

About your query of slide index, you need to use the slide index because the Video frame is a shape which could be added on a slide. Also, there is no limitation of video formats and any video binary data can be passed for embedding.

I hope this will clarify the concept. Please share if I may help you further in this regard.

Best Regards,

we don’t have to insert the image in video frame, we have to default viewer to the first frame of the video instead of “no image” , as I mentioned in first mail chain and attachment.

Hi Laurie,


I have observed your comments and worked over your requirements. As shared earlier, in this forum thread and live chat, you need to set the image in a video frame but the image is being added to the background of Video frame which is an issue. A ticket with ID SLIDESJAVA-35089 has been logged in our issue tracking system to further investigate and resolve the issue.This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

Hi Laurie,


I would like to request you to please try using following sample code on your end to serve the purpose. This is how image could be set on a video frame and as shared earlier, you have to extract the first frame of video by using some third party tool.

Presentation pres = new Presentation();

//Get the first slide
ISlide sld = pres.getSlides().get_Item(0);

//Add Video Frame
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, “C:\Videos\Wildlife.mp4”);

//Set Play Mode and Volume of the Video
vf.setPlayMode(VideoPlayModePreset.Auto);
vf.setVolume(AudioVolumeMode.Loud);

IPPImage img =null;
img = pres.getImages().addImage(new FileInputStream(new File(“D:\test.png”)));
vf.getPictureFormat().getPicture().setImage(img);


//Write the PPTX file to disk
pres.save(“D:\VideoFrameTest.pptx”, SaveFormat.Pptx);

I hope this will be helpful. Please share if I may help you further in this regard.

Best Regards,

The issues you have found earlier (filed as SLIDESJAVA-35089) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hello, I’m having the same issue using .NET code below. Setting Picture.Image property looks like sets it below the “No Image” place holder (once set you can see a pixel or so of it sticking out at the bottom and on the right). I cannot find out how to get rid of the “No Image” place holder.

	using (Presentation presentation = new Presentation())
{
	// Get the first slide
	ISlide slide = presentation.Slides[0];

	var videoPath = Path.Combine(Util.CurrentQuery.Location, "Wildlife.mp4");
	IVideo vid = slide.Presentation.Videos.AddVideo(new FileStream(videoPath, FileMode.Open), LoadingStreamBehavior.ReadStreamAndRelease);
	IVideoFrame vf = slide.Shapes.AddVideoFrame(10, 10, 300, 200, vid);
	vf.EmbeddedVideo = vid;
	vf.PlayMode = VideoPlayModePreset.OnClick;
	vf.Volume = AudioVolumeMode.Medium;
	
	var imgx = presentation.Images.AddImage((Image)new Bitmap(Path.Combine(Util.CurrentQuery.Location, "pic.jpg")));
	vf.FillFormat.FillType = FillType.Picture;
	vf.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Tile;

	vf.FillFormat.PictureFillFormat.Picture.Image = imgx;

	// Save presentation
	presentation.Save(Path.Combine(Util.CurrentQuery.Location, "out.pptx"), SaveFormat.Pptx);
}

@ivoloshin,

Please try using following sample code to add image for Video Frame.

IPPImage img = null;
img = presentation.Images.AddImage(new FileStream(imgpath + "Tulips.jpg", FileMode.Open));
vf.PictureFormat.Picture.Image = img;

That solved my problem. Thank you!