Why OpenXml SDK 2.5doesn't support mp4 format?

Home Forums PresentationML Why OpenXml SDK 2.5doesn't support mp4 format?

This topic contains 8 replies, has 2 voices, and was last updated by  Eric White 8 years, 8 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2538

    sliu
    Participant

    Hi Eric,

    I figured out why my copied video is not playable. My video format is .mp4. I found MediaDataPartType doesn’t have mp4. It has avi for audio and video. So I added avi file in my pptx and ran PresentationBuilder01 to copy my slide. My copied avi works, but not copied mp4.

    I see you have OpenXml SDK 2.6. I wonder if it supports mp4 format.

    Thanks for your help!

    #2539

    Eric White
    Keymaster

    Neither the Open-Xml-Sdk nor Open-Xml-PowerTools deal with the specifics of video or sound formats. As far as binary parts are concerned, they are blobs that you stream to a part, or copy from one part to another. The Open-Xml-Sdk and Open-Xml-PowerTools are not aware of the specific contents of any binary part.

    When you insert an MP4 into a presentation, does it play? I wonder if PowerPoint converts the video to avi when inserting. Can you look and see?

    • This reply was modified 8 years, 8 months ago by  Eric White.
    #2541

    sliu
    Participant

    I think both deal with the specifics of video and sound. Please take a look at the code I got from PresentationBuilder::CopyRelatedMedia and the definition of DocumentFormat.OpenXml.Packaging.MediaDataPartType.

    Since MediaDataPartType doesn’t have mp4 in its enumeration, PowerTools GetMediadataPartTypeFromContentType uses the default value – MediaDataPartType.Wmv – as mp4 media type. That is why mp4 file cannot be played correctly.

    I can play my mp4 in my original pptx. I converted my mp4 to .avi file and inserted it in my original pptx. Both .mp4 and .avi can play. After copied version generated, only .avi file can play, but .mp4 gives the error “Codec Unavailable”.

    if (temp.DataPart == null)
    {
    var ct = oldPart.ContentType;
    MediaDataPartType mdpt = GetMediadataPartTypeFromContentType(ct);
    MediaDataPart newPart = newContentPart.OpenXmlPackage.CreateMediaDataPart(mdpt);
    newPart.FeedData(oldPart.GetStream());

    private static MediaDataPartType GetMediadataPartTypeFromContentType(string ct)
    {
    MediaDataPartType mdpt = MediaDataPartType.Wmv;

    if (ct == “audio/aiff”)
    mdpt = MediaDataPartType.Aiff;
    else if (ct == “video/x-ms-asf-plugin”)
    mdpt = MediaDataPartType.Asx;
    else if (ct == “video/avi”)
    mdpt = MediaDataPartType.Avi;
    else if (ct == “audio/midi”)
    mdpt = MediaDataPartType.Midi;
    else if (ct == “audio/mp3”)
    mdpt = MediaDataPartType.Mp3;
    else if (ct == “audio/mpeg”)
    mdpt = MediaDataPartType.MpegAudio;
    else if (ct == “audio/mpegurl”)
    mdpt = MediaDataPartType.MpegUrl;
    else if (ct == “video/mpeg”)
    mdpt = MediaDataPartType.MpegVideo;
    else if (ct == “video/mpg”)
    mdpt = MediaDataPartType.Mpg;
    else if (ct == “audio/ogg”)
    mdpt = MediaDataPartType.OggAudio;
    else if (ct == “video/ogg”)
    mdpt = MediaDataPartType.OggVideo;
    else if (ct == “video/quicktime”)
    mdpt = MediaDataPartType.Quicktime;
    else if (ct == “video/vc1”)
    mdpt = MediaDataPartType.VC1;
    else if (ct == “audio/wav”)
    mdpt = MediaDataPartType.Wav;
    else if (ct == “audio/x-ms-wma”)
    mdpt = MediaDataPartType.Wma;
    else if (ct == “video/x-ms-wmv”)
    mdpt = MediaDataPartType.Wmv;
    else if (ct == “video/x-ms-wmx”)
    mdpt = MediaDataPartType.Wmx;
    else if (ct == “video/x-ms-wvx”)
    mdpt = MediaDataPartType.Wvx;
    else if (ct == “audio/unknown”)
    mdpt = MediaDataPartType.Wav;
    return mdpt;
    }

    namespace DocumentFormat.OpenXml.Packaging
    {
    // Summary:
    // Defines part media types.
    public enum MediaDataPartType
    {
    // Summary:
    // Audio Interchange File Format (.aiff)
    Aiff = 0,
    //
    // Summary:
    // MIDI Audio (.mid)
    Midi = 1,
    //
    // Summary:
    // MP3 (.mp3)
    Mp3 = 2,
    //
    // Summary:
    // MP3 Playlist File (.m3u)
    MpegUrl = 3,
    //
    // Summary:
    // WAV audio (.wav)
    Wav = 4,
    //
    // Summary:
    // Windows Media Audio File (.wma)
    Wma = 5,
    //
    // Summary:
    // Mpeg audio (.mpeg)
    MpegAudio = 6,
    //
    // Summary:
    // Ogg Vorbis (.ogg)
    OggAudio = 7,
    //
    // Summary:
    // Advanced Stream Redirector File (.asx)
    Asx = 8,
    //
    // Summary:
    // Audio Video Interleave File (.avi)
    Avi = 9,
    //
    // Summary:
    // MPEG 1 System Stream (.mpg)
    Mpg = 10,
    //
    // Summary:
    // MPEG 1 System Stream (.mpeg)
    MpegVideo = 11,
    //
    // Summary:
    // Windows Media File (.wmv)
    Wmv = 12,
    //
    // Summary:
    // Windows Media Player A/V Shortcut (.wmx)
    Wmx = 13,
    //
    // Summary:
    // Windows Media Redirector (.wvx)
    Wvx = 14,
    //
    // Summary:
    // QuickTime video (.mov)
    Quicktime = 15,
    //
    // Summary:
    // Ogg Stream (.ogg)
    OggVideo = 16,
    //
    // Summary:
    // VC-1 Stream (.wmv)
    VC1 = 17,
    }
    }

    #2542

    Eric White
    Keymaster

    Yes, you are right.

    BTW, I now work on the SDK on a free basis, so could use a bit of help here.

    Do one experiment – get version 2.6 of the SDK from GitHub, tweak the code, adding an entry into that enum, adding an additional case into GetMediadataPartTypeFromContentType, and see if this fixes the problem.

    • This reply was modified 8 years, 8 months ago by  Eric White.
    #2544

    sliu
    Participant

    Ok, I’ll do it tomorrow and let you know.

    #2551

    sliu
    Participant

    Hi Eric,

    After added Mp4 in MediaDataPartType and modified the corresponding MediaDataPartTypeInfo methods and GetMediadataPartTypeFromContentType in PowerTools, Mp4 works fine.

    Finally, I can use the modified OpenXml SDK 2.6 to make my videos (mp4) working.

    #2557

    Eric White
    Keymaster

    This is awesome. BTW, if you are git savvy, and want to create a pull request for the Open-Xml-Sdk, I would welcome that.

    #2580

    sliu
    Participant

    Sorry, I’m not git savvy. I’ll see what I can do.

    #2582

    Eric White
    Keymaster

    Ok, no worries, I added issues to both Open-Xml-Sdk and Open-Xml-PowerTools on GitHub, so this will ensure that this gets addressed.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.