2013-02-19 34 views
5

我只是想知道是否有人知道如何在Android上使用mp4parser將mp4音頻文件覆蓋到mp4視頻文件上。我已經能夠將一個視頻添加到另一個視頻中,現在我只需要覆蓋合併文件中的原始mp4。在Android上使用mp4parser合併Mp4s

任何幫助,將不勝感激!

回答

4

以下代碼複合兩種音頻語言和一種視頻。它應該很容易採用它來滿足您的需求:

public static void main(String[] args) throws IOException { 

    String audioDeutsch = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-deutsch-audio.mp4"; 
    String audioEnglish = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4"; 
    String video = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-video.mp4"; 


    Movie countVideo = MovieCreator.build(new FileInputStream(video).getChannel()); 
    Movie countAudioDeutsch = MovieCreator.build(new FileInputStream(audioDeutsch).getChannel()); 
    Movie countAudioEnglish = MovieCreator.build(new FileInputStream(audioEnglish).getChannel()); 

    Track audioTrackDeutsch = countAudioDeutsch.getTracks().get(0); 
    audioTrackDeutsch.getTrackMetaData().setLanguage("deu"); 
    Track audioTrackEnglish = countAudioEnglish.getTracks().get(0); 
    audioTrackEnglish.getTrackMetaData().setLanguage("eng"); 

    countVideo.addTrack(audioTrackDeutsch); 
    countVideo.addTrack(audioTrackEnglish); 

    Container out = new DefaultMp4Builder().build(countVideo); 
    FileOutputStream fos = new FileOutputStream(new File("output.mp4")); 
    out.writeContainer(fos.getChannel()); 
    fos.close(); 

} 
+0

音頻使用此代碼時將覆蓋..任何幫助? – 2014-05-15 09:11:07

+1

@Sebastian音軌逐一添加。無論如何,我可以添加兩個音軌,他們必須同時運行,顯然是視頻。比方說,我有一個視頻和一個語音音頻,還有一個背景音樂。現在我想讓這兩個音頻與視頻同時並行運行。你能幫助我們如何實現這一目標嗎? – ROCKY 2015-04-25 20:14:12

+0

上面提到的代碼將視頻與添加的第一個音軌混合在一起。我想播放與視頻文件並行的兩個音軌。任何人都可以幫助我的那 – 2016-03-14 11:19:22

相關問題