PptxGenJS icon indicating copy to clipboard operation
PptxGenJS copied to clipboard

Issue with adding Video files

Open adrienco88 opened this issue 9 years ago • 13 comments

Hi,

I am trying to add a video file to the presentation, but there seems to be something wrong with the relations used for the video element, because after I export the ppt and try to open, PowerPoint is asking me to repair the ppt. After PowerPoint repairs the file, I can see that the relations for the video tag are changed in the slide file: (r:embed="rId1") <p14:media xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" r:embed="rId1"/> and also in the _rels file, the tags are the same, the only change is the relationship ID that is re-assigned after PowerPoint file repair.

When I generate the PPT, I take the video from the server and encode it in base64 and then I pass it to the data attribute of addMedia() function. I use js and not Node and for the encoding part I use XMLHttpRequest() and FileReader.readAsDataURL()

The video is successfully encoded since I can add it as the source for the HTML video tag and it's still playing, and also in the generated PPT, in the media folder I can see the video and I can play it with any video player.

Here are some parts of my code that will better define the flow that I use: Encoding the videos:

jQuery('.elementVideo').each(function (ind, el) {
      var videoPath = jQuery(el).find('source').attr('src');
      var videoData = '';
      var request = new XMLHttpRequest();
      request.open('GET', videoPath, true);
      request.responseType = 'blob';
      request.onload = function () {
        var reader = new FileReader();
        reader.readAsDataURL(request.response);
        reader.onloadend = function (e) {
          videoData = e.target.result;
          var elId = jQuery(el).attr('id');
         // add the encoded video string to mediaArray variable for later use
          mediaArray[elId] = videoData;
          if (mediaDone == jQuery('.elementVideo').length) {
            continueExport();
          } else {
            mediaDone++;
          }
        };
      };
      request.send();
    });

And inside the continueExport() function I have the following for adding the video:

var elId = jQuery(el).attr('id'); // the video HTML element
        var extraOptions = {
          rotate: getRotationDegrees(jQuery(el))
        };
        var options = {
          type: 'video',
          data: mediaArray[elId], // the encoded video
          x: pixel2inches(jQuery(el).position().left),
          y: pixel2inches(jQuery(el).position().top),
          w: pixel2inches(jQuery(el).width()),
          h: pixel2inches(jQuery(el).height()),
//          opts: extraOptions
        };
        slide.addMedia(options);

Also attached there are the 2 files, the generated one and the one repaired by PowerPoint: Test Forms - Repaired.pptx Test Forms.pptx

Any ideas would be helpful.

Thanks, Adrian

adrienco88 avatar Nov 22 '17 10:11 adrienco88

Hi @adrienco88,

Does your video get added successfully when using Node? What type of video is it (MP4 etc.)?

[brent@Air 17:30:33] ~/Documents/GitHub/PptxGenJS/examples 
=> node nodejs-demo.js Media

-------------
STARTING DEMO
-------------
 * pptxgenjs version: 1.11.0-beta.20171120

--------------
DEMO COMPLETE!
--------------
 * Files saved to...: GitHub/PptxGenJS/examples

saveCallback: Good News Everyone! File created: Node_Demo_Callback_201711221730.pptx

screen shot 2017-11-22 at 17 31 58

gitbrent avatar Nov 22 '17 23:11 gitbrent

Hi @gitbrent , I'm not using Node, and the video is mp4. even with the video from samples I got the same issue. As for now, I didn't saw any demo in using a local video implemented in javascript. As I stated before, the video file seems to be encoded correctly and I can see the video after I unzip the ppt and I can play it with all video players.

I'm not sure what exactly PowerPoint doesn't like and ask me to repair the file, but as far as I saw, the relations are good and everything should work. I use PowerPoint 365 Business Version 1710. I saw in the log files of the repair that there are 2 files modified: the slide.xlm and slide.xml.rel and the only changes are re-ordering the relations ID's, that doesn't make any sense. You can see in the 2 ppt files that I attached to the issue.

I can assure you that the video is successfully added and it's fully working without PowerPoint asking to repair the file because I hardcoded the relations in your library just for testing purposes and it worked.

Are there any rules of priority for those relations? I'm thinking at the relation ID and the order that the relations are written in the rels file?

Or what can be the issue since the video is successfully converted and added to the ppt, but for some reason the relations are not the ones that PowerPoint expect?

Any idea is appreciated.

Thanks and best Regards, Adrian

adrienco88 avatar Nov 23 '17 00:11 adrienco88

Also, have you tried to open the Test Forms.pptx ? do you get the same error that is asking you to repair the file?

adrienco88 avatar Nov 23 '17 00:11 adrienco88

Yes, it does.

What is the code you're using (just the PptxgenJS part)?

gitbrent avatar Nov 23 '17 01:11 gitbrent

For PPT it's just PptxGenJs library. Slightly improved by adding other options for shapes, tables, text and images (like rotation, flat/round borders, border type, image/border transparency, etc), but nothing it's changed in the code that generates the video.

Also, all my changes/improvements to the the library will be delivered to you once I have some time to merge them in the repo.

adrienco88 avatar Nov 23 '17 02:11 adrienco88

Hi, is there a solution for this problem yet? Is there maybe a working example for mp4 Videos? Thanks!

MichiSpandl avatar Feb 13 '18 15:02 MichiSpandl

Hi @MichiSpandl,

@adrienco88 had issues with the node demo files, which produce correctly for me and open in desktop and PowerPoint online.

What's a test case for your situation? How are you creating the ppt? What is the result of the node demo video sample?

gitbrent avatar Feb 14 '18 02:02 gitbrent

@gitbrent I don't use node. But I guess the main problem in my case is, that the base64 string for the mp4 movie is about 4.975.140 signs long... Has anyone got a working result without node?

MichiSpandl avatar Feb 15 '18 14:02 MichiSpandl

@gitbrent I have tried also with audio (mp3 file as base64) but it is also not working. Only with images I was able to output them as data instead of path. Don't have a clue at the moment what is wrong... (still without node.js, unfortunately I can't use node.js on this webserver...)

MichiSpandl avatar Feb 15 '18 16:02 MichiSpandl

Same problem here, video is not working

jobnte avatar Mar 03 '18 07:03 jobnte

@jorgelub12

Unless you're using Node, video is probably not an option as browsers cannot encode video into base64 for inclusion in the PPTX file.

Otherwise, the node demo under examples produces videos in many formats.

gitbrent avatar Mar 05 '18 04:03 gitbrent

FYI: I've updated the Adding Media section of the README with much more information about what can be encoded and why, etc.

Adding Media

gitbrent avatar Mar 05 '18 04:03 gitbrent

@MichiSpandl

I've updated the image/media encoding methods to accept URL's as a path, so you can add mp3 and other files now.

slide.addMedia({
  type:'video', 
  path:'https://raw.githubusercontent.com/gitbrent/PptxGenJS/2.1.0/examples/media/sample.mov', 
  x:1.0, y:1.0, w:3.0, h:2.0
});

Ref: Issue #318 and Issue #325

gitbrent avatar Apr 25 '18 04:04 gitbrent