<kbd id="9plqc"><label id="9plqc"></label></kbd>

        <th id="9plqc"></th>
        1. <center id="9plqc"><video id="9plqc"></video></center>
          <sub id="9plqc"><form id="9plqc"><pre id="9plqc"></pre></form></sub>
          <nav id="9plqc"><form id="9plqc"><legend id="9plqc"></legend></form></nav>
          轉(zhuǎn)換媒體文件代碼 您所在的位置:網(wǎng)站首頁(yè) 屬牛的跟屬兔的婚姻配嗎 轉(zhuǎn)換媒體文件代碼

          轉(zhuǎn)換媒體文件代碼

          2023-09-18 16:38| 來(lái)源: 網(wǎng)絡(luò)整理| 查看: 265

          轉(zhuǎn)換媒體文件代碼 項(xiàng)目 07/14/2023

          可以使用 Windows.Media.Transcoding API 將視頻文件代碼從一種格式轉(zhuǎn)換為另一種格式。

          轉(zhuǎn)換代碼是指轉(zhuǎn)換數(shù)字媒體文件,例如將視頻或音頻文件從一種格式轉(zhuǎn)換為另一種格式。 這通常是通過(guò)解碼文件,然后再重新編碼文件實(shí)現(xiàn)的。 例如,你可以將 Windows Media 文件轉(zhuǎn)換為 MP4 文件,以使此文件可以在支持 MP4 格式的便攜式設(shè)備上播放。 或者,你可以將高清視頻文件轉(zhuǎn)換為較低分辨率的文件。 在此情況下,重新編碼的文件可能使用與原始文件相同的編解碼器,但是其編碼配置文件不同。

          設(shè)置你的項(xiàng)目以進(jìn)行轉(zhuǎn)換代碼

          除了由默認(rèn)項(xiàng)目模板引用的命名空間,你還需要引用這些命名空間,以便使用本文中的代碼轉(zhuǎn)換媒體文件代碼。

          using Windows.Storage; using Windows.Media.MediaProperties; using Windows.Media.Transcoding; 選擇源文件和目標(biāo)文件

          應(yīng)用確定要轉(zhuǎn)換代碼的源文件和目標(biāo)文件的方式取決于實(shí)現(xiàn)。 此示例通過(guò)使用 FileOpenPicker 和 FileSavePicker 讓用戶能夠選取源文件和目標(biāo)文件。

          var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; openPicker.FileTypeFilter.Add(".wmv"); openPicker.FileTypeFilter.Add(".mp4"); StorageFile source = await openPicker.PickSingleFileAsync(); var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; savePicker.DefaultFileExtension = ".mp4"; savePicker.SuggestedFileName = "New Video"; savePicker.FileTypeChoices.Add("MPEG4", new string[] { ".mp4" }); StorageFile destination = await savePicker.PickSaveFileAsync(); 創(chuàng)建媒體編碼配置文件

          編碼配置文件包含確定如何編碼目標(biāo)文件的設(shè)置。 轉(zhuǎn)換文件代碼時(shí),此文件中包含的選項(xiàng)最多。

          MediaEncodingProfile 類提供用于創(chuàng)建預(yù)定義編碼配置文件的靜態(tài)方法:

          用于創(chuàng)建純音頻編碼配置文件的方法 方法 配置文件 CreateAlac Apple 無(wú)損音頻編解碼器 (ALAC) 音頻 CreateFlac 免費(fèi)無(wú)損音頻編解碼器 (FLAC) 音頻。 CreateM4a AAC 音頻 (M4A) CreateMp3 MP3 音頻 CreateWav WAV 音頻 CreateWmv Windows Media 音頻 (WMA) 用于創(chuàng)建音頻/視頻編碼配置文件的方法 方法 配置文件 CreateAvi AVI CreateHevc 高效率視頻編碼 (HEVC) 視頻,也稱為 H.265 視頻 CreateMp4 MP4 視頻(H.264 視頻加 AAC 音頻) CreateWmv Windows Media 視頻 (WMV)

          以下代碼為 MP4 視頻創(chuàng)建配置文件。

          MediaEncodingProfile profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p);

          靜態(tài) CreateMp4 方法創(chuàng)建 MP4 編碼配置文件。 此方法的參數(shù)為視頻指定目標(biāo)分辨率。 在這種情況下,VideoEncodingQuality.hd720p 表示在每秒 30 幀情況下的 1280 x 720 像素。 (“720p”表示每幀 720 個(gè)逐行掃描行。)用于創(chuàng)建預(yù)定義配置文件的其他方法均遵循此模式。

          或者,你可以通過(guò)使用 MediaEncodingProfile.CreateFromFileAsync 方法來(lái)創(chuàng)建與現(xiàn)有媒體文件相匹配的配置文件。 或者,如果你知道所需的確切編碼設(shè)置,則可以創(chuàng)建一個(gè)新的 MediaEncodingProfile 對(duì)象,然后填寫配置文件詳細(xì)信息。

          轉(zhuǎn)換文件代碼

          若要轉(zhuǎn)碼文件,請(qǐng)創(chuàng)建新的 MediaTranscoder 對(duì)象并調(diào)用 MediaTranscoder.PrepareFileTranscodeAsync 方法。 傳入源文件、目標(biāo)文件和編碼配置文件。 然后,調(diào)用從異步轉(zhuǎn)換代碼作中返回的 PrepareTranscodeResult 對(duì)象上的 TranscodeAsync 方法。

          MediaTranscoder transcoder = new MediaTranscoder(); PrepareTranscodeResult prepareOp = await transcoder.PrepareFileTranscodeAsync(source, destination, profile); if (prepareOp.CanTranscode) { var transcodeOp = prepareOp.TranscodeAsync(); transcodeOp.Progress += new AsyncActionProgressHandler(TranscodeProgress); transcodeOp.Completed += new AsyncActionWithProgressCompletedHandler(TranscodeComplete); } else { switch (prepareOp.FailureReason) { case TranscodeFailureReason.CodecNotFound: System.Diagnostics.Debug.WriteLine("Codec not found."); break; case TranscodeFailureReason.InvalidProfile: System.Diagnostics.Debug.WriteLine("Invalid profile."); break; default: System.Diagnostics.Debug.WriteLine("Unknown failure."); break; } } 響應(yīng)代碼轉(zhuǎn)換進(jìn)度

          你可以注冊(cè)要在異步進(jìn)度 TranscodeAsync 發(fā)生更改時(shí)響應(yīng)的事件。 這些事件是通用 Windows 平臺(tái) (UWP) 應(yīng)用的異步編程框架的一部分,且不特定于 API 代碼轉(zhuǎn)換作。

          void TranscodeProgress(IAsyncActionWithProgress asyncInfo, double percent) { // Display or handle progress info. } void TranscodeComplete(IAsyncActionWithProgress asyncInfo, AsyncStatus status) { asyncInfo.GetResults(); if (asyncInfo.Status == AsyncStatus.Completed) { // Display or handle complete info. } else if (asyncInfo.Status == AsyncStatus.Canceled) { // Display or handle cancel info. } else { // Display or handle error info. } }


          【本文地址】

          公司簡(jiǎn)介

          聯(lián)系我們

          今日新聞

          推薦新聞

          專題文章
            CopyRight 2018-2019 實(shí)驗(yàn)室設(shè)備網(wǎng) 版權(quán)所有
            黄色免费网站在线看,韩国精品在线观看,韩国美女一区二区,99国产热 浮山县| 香河县| 卫辉市| 凤山市| 绥中县| 安宁市| 阳新县| 青川县| 岚皋县| 长武县| 万宁市| 青阳县| 诸暨市| 射阳县| 金川县| 调兵山市| 陇南市| 西乌珠穆沁旗| 桑日县| 新沂市| 博罗县| 扶风县| 改则县| 东平县| 嘉荫县| 阜南县| 定远县| 上犹县| 五莲县| 盐源县| 襄城县| 搜索| 通城县| 仙游县| 龙川县| 长阳| 沾化县| 乾安县| 乃东县| 香格里拉县| 大邑县| http://444 http://444 http://444 http://444 http://444 http://444