2013-03-22 199 views
2

我正在尋找一種方法來分割或剪切用h264編碼的mp4視頻文件,而無需重新編碼。到目前爲止編輯mp4 h264編碼的文件我使用了Microsoft Expression Encoder 4 Pro。問題是,我總是必須重新編碼文件,這需要時間,如果我只想剪切或拆分視頻文件,則會花費不必要的時間。任何幫助或指向正確的方向表示讚賞。切割mp4 h264視頻文件無需重新編碼

+0

取決於視頻的編碼方式。除非您在關鍵幀邊界上進行分割,否則通常需要對其至少一部分進行重新編碼。 – 2013-03-22 21:51:52

+0

分裂在關鍵幀的邊界對我來說會很好,但我沒有找到任何庫,我可以用這個「簡單」的任務在c# – Kevkong 2013-03-23 02:38:41

回答

0

libmp4v2爲您提供了構建自己做某些事情的原語。我沒有意識到現成的解決方案可以做到這一點,但只要您切割I幀邊界,實現起來相對容易。

+0

感謝迄今,但我正在尋找c#相關的東西。 – Kevkong 2013-03-23 02:37:29

+0

@Kevkong我不相信它存在。如果對c#中的媒體進行任何低級別的操作,你很可能不得不對p/invoke進行很多操作。 – Yaur 2013-03-25 00:01:57

+0

如果想要對MP4文件進行殘酷的任意裁剪,並修改頭文件,我真的希望他不需要超級優化的低級C代碼。我會做的是檢查格式規格,然後做一些測試,看看解碼器如何消化破碎的序列。在像WP和WinRT這樣的新平臺上,越少越好。 – 2013-06-11 01:08:19

3

我不知道如何分割而無需重新編碼(轉碼)視頻,但在Windows 8轉碼的視頻已經內置:

要修剪的文件,調用aysnc方法PrepareFileTranscodeAsync然後調用PrepareTranscodeResult對象上的TranscodeAsync方法。

例如:

async void TrimFile(StorageFile srcFile, StorageFile destFile) 
{ 
    MediaEncodingProfile profile = 
     MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p); 

    MediaTranscoder transcoder = new MediaTranscoder(); 

    // Set the start of the trim. 
    transcoder.TrimStartTime = new TimeSpan(0, 0, 1); 

    // Set the end of the trim. 
    transcoder.TrimStopTime = new TimeSpan(0, 0, 9); 

    PrepareTranscodeResult prepareOp = await 
     transcoder.PrepareFileTranscodeAsync(srcFile, destFile, profile); 

    if (prepareOp.CanTranscode) 
    { 
     var transcodeOp = prepareOp.TranscodeAsync(); 
     transcodeOp.Progress += 
      new AsyncActionProgressHandler<double>(TranscodeProgress); 
     transcodeOp.Completed += 
      new AsyncActionWithProgressCompletedHandler<double>(TranscodeComplete); 
    } 
    else 
    { 
     switch (prepareOp.FailureReason) 
     { 
      case TranscodeFailureReason.CodecNotFound: 
       OutputText("Codec not found."); 
       break; 
      case TranscodeFailureReason.InvalidProfile: 
       OutputText("Invalid profile."); 
       break; 
      default: 
       OutputText("Unknown failure."); 
       break; 
     } 
    } 
} 

How to trim a video file (Windows Store apps using C#/VB/C++ and XAML)

也可以到Splicer(使用DirectShow.Net)用於Windows的早期。

希望它可以幫助別人。

+0

嗨,感謝您的提示。該項目發生了變化,但只要我不得不再次處理這個問題,我就會看看你的解決方案/示例。 – Kevkong 2014-01-24 17:03:04