dotnet / Open-XML-SDK

Open XML SDK by Microsoft
https://www.nuget.org/packages/DocumentFormat.OpenXml/
MIT License
4.03k stars 547 forks source link

Open XML SDK does not properly process MP4 files #84

Closed EricWhiteDev closed 7 years ago

EricWhiteDev commented 8 years ago

From a forum post:

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".

From Eric White: This needs a member added to MediaDataPartType.

        if (temp.DataPart == null)
        {
            var ct = oldPart.ContentType;
            <strong>MediaDataPartType </strong>mdpt = <strong>GetMediadataPartTypeFromContentType</strong>(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, } }

Josh-Curry commented 7 years ago

Closing issue. Fix contained in PR #140.

kimsey0 commented 7 years ago

@tomjebo: Will you make sure to get this into vNext again now that v2.7 is out? How is the timeline for getting this in a release? It was more than a year between v2.6 and v2.7, after all, and we need this quite a bit.

tomjebo commented 7 years ago

@kimsey0 Sorry for the delay in responding. Yes, we did add this and then revert. Now that 2.7.1 is done, we will add this fix back in. A PR will likely be submitted next week. Thanks for asking.

kimsey0 commented 7 years ago

@tomjebo: Great. Thanks.

cjscholten commented 3 years ago

Does anyone know what happened with this? I still can't find any reference to MP4 in the MediaDataPartType or MediaDataPartTypeInfo classes. Am I looking in the wrong place?