Created
June 28, 2014 10:05
-
-
Save a-chernykh/587251494b80718a3235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mp4ParserAudioMuxer implements AudioMuxer { | |
@Override | |
public boolean mux(String videoFile, String audioFile, String outputFile) { | |
Movie video; | |
try { | |
video = new MovieCreator().build(videoFile); | |
} catch (RuntimeException e) { | |
e.printStackTrace(); | |
return false; | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
Movie audio; | |
try { | |
audio = new MovieCreator().build(audioFile); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return false; | |
} catch (NullPointerException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
Track audioTrack = audio.getTracks().get(0); | |
video.addTrack(audioTrack); | |
Container out = new DefaultMp4Builder().build(video); | |
FileOutputStream fos; | |
try { | |
fos = new FileOutputStream(outputFile); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
BufferedWritableFileByteChannel byteBufferByteChannel = | |
new BufferedWritableFileByteChannel(fos); | |
try { | |
out.writeContainer(byteBufferByteChannel); | |
byteBufferByteChannel.close(); | |
fos.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment