Embedding Video (MP4) in PDF

I need to embed a MP4 (h.264 + aac) video into a PDF file. Used code similar to an example posted in Aspose web site show below. The resulting PDF only has a link to the video and it is not embedded. Also it would be preferable to load the video from a stream rather than a local file.

Page lastPage = orig.Pages[orig.Pages.Count - 1];

Aspose.Pdf.InteractiveFeatures.Annotations.MovieAnnotation mov = new Aspose.Pdf.InteractiveFeatures.Annotations.MovieAnnotation(

lastPage,

new Aspose.Pdf.Rectangle(4f * 72f, 3.5f * 72f, 3f * 72f, 4f * 72f),

tmpfile

);

lastPage.Annotations.Add(mov);



markafox:
I need to embed a MP4 (h.264 + aac) video into a PDF file. Used code similar to an example posted in Aspose web site show below. The resulting PDF only has a link to the video and it is not embedded.
Page lastPage = orig.Pages[orig.Pages.Count - 1];Aspose.Pdf.InteractiveFeatures.Annotations.MovieAnnotation mov = new Aspose.Pdf.InteractiveFeatures.Annotations.MovieAnnotation(lastPage,

new Aspose.Pdf.Rectangle(4f * 72f, 3.5f * 72f, 3f * 72f, 4f * 72f),

tmpfile

);

lastPage.Annotations.Add(mov);

Hi Mark,


Thanks for contacting support.


I have tested the scenario and I am able to notice the same problem. For the sake of correction, I have logged this problem as PDFNEWNET-39606 in our issue tracking system.

markafox:
Also it would be preferable to load the video from a stream rather than a local file.
I have separately logged this feature request in our issue tracking system as PDFNEWNET-39607 under new features list. We will further look into the details of these problems and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNET-39606) have been fixed in Aspose.Pdf for .NET 17.3.0.


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

Can you post a working example? The above code still seems to just create a link and not actually embed the movie file.

Hi Mark,


Thanks for your inquriy. In reference to above resolved issue(PDFNET-39606), We have implemented a new annotation RichMediaAnnotation in Aspose.Pdf for .NET 17.3.0. Please note MovieAnnotation can just play link to the external video file (placed on disk or internet). However RichMediaAnnotation is used to play media stored within PDF document.

In fact RichMediaAnnotation is container for SWF (Flash) script. Due to license restriction we can not include third-party flash scripts in our product, so you should provide your script for playing video or audio. For example you can use VideoPlayer and AudioPlayer shipped with Adobe Acrobat. It is placed in Acrobat folder Acrobat\Multimedia Skins\Players.

Please check following sample code for embedding video/audio files in PDF document using RichMediaAnnotation.

Aspose.Pdf.Document
doc = new Aspose.Pdf.Document();<o:p></o:p>

Page page = doc.Pages.Add();

RichMediaAnnotation rma = new RichMediaAnnotation(page, new Aspose.Pdf.Rectangle(100, 500, 300, 600));

//here we should specify stream containing code of the video player

rma.CustomPlayer =

new FileStream(@"Acrobat\Multimedia Skins\Players\Videoplayer.swf",FileMode.Open, FileAccess.Read);

//give name to video data. This data will be embedded into document with this name and referenced from flash variables by this name.

// videoName should not contain path to the file; this is rather "key" to access data inside of the PDF document

string videoName = "VideoTutorial.mp4";

//also we use skin for video player

string skinName = "SkinOverAllNoFullNoCaption.swf";

//compose flash variables line for player. please note that differnet players may have different format of the flash variabless line. Refer to documentation for your player.

rma.CustomFlashVariables = String.Format("source={0}&skin={1}", "VideoTutorial.mp4", skinName);

//add skin code.

rma.AddCustomData(skinName,

new FileStream(@"Acrobat\Multimedia Skins\SkinOverAllNoFullNoCaption.swf",

FileMode.Open, FileAccess.Read));

//set poster for video

rma.SetPoster(new FileStream(myDir + "Aspose.jpg", FileMode.Open, FileAccess.Read));

Stream fs = new FileStream(myDir + videoName, FileMode.Open, FileAccess.Read);

//set video content

rma.SetContent(videoName, fs);

//set type of the content (video)

rma.Type = RichMediaAnnotation.ContentType.Video;

//active player by click

rma.ActivateOn = RichMediaAnnotation.ActivationEvent.Click;

//update annotation data. This method should be called after all assignments/setup. This method initializes data structure of the annotation and embeds required data.

rma.Update();

//add annotation on the page.

page.Annotations.Add(rma);

doc.Save(myDir + “39606-1.pdf”);


Best Regards,

@wajayme

Thank you for the suggestion but this topic covers how to embed a video in a PDF file programmatically.