mp4parser
mp4parser copied to clipboard
How to replace and add audio at the specified time?
I have a mp4 video (duration 1 minute) and an audio file (40 seconds). I can merge them. But I want the audio starts at the 20th second (not from the beginning of video). How to do that?
hello, do you resolve this problem yet?
Hi, it's easily doable if you only have one audio track.
- identify Audio Track Object.
- Add an edit: audioTrack.getEdits().add(new Edit(20000, 1000, 1, 30))
The edit means that the audio shall start after 20000/1000 seconds with a playback speed of 1 for exactly 30 seconds. Be aware: Most but not all players support that
A different possibility is to have prerecorded silence and you prepend the recorded silence until the actual sound is at the correct position.
Best Regards, Sebastian
2016-01-06 13:32 GMT+01:00 spring [email protected]:
hello, have you already resolve this problem yet?
— Reply to this email directly or view it on GitHub https://github.com/sannies/mp4parser/issues/146#issuecomment-169313828.
Hi Sannies, Thanks for the library, its really helpful, can you please help me to sort out this issue
Movie m = null;
try {
m = MovieCreator.build(baseDir+"/VID-20160609-WA0000.mp4");
} catch (IOException e) {
e.printStackTrace();
}
List<Track> nuTracks = new ArrayList<>();
for (Track t : m.getTracks())
{ // Re-use all tracks besides the audio track
if (!"soun".equals(t.getHandler()))
nuTracks.add(t);
}
Track nuAudio = null;
try {
nuAudio = new AACTrackImpl(new FileDataSourceImpl(baseDir+"/laugh.aac"));
nuAudio.getEdits().add(new Edit(5000, 1000, 1, 5));
} catch (IOException e) {
e.printStackTrace();
}
nuTracks.add(nuAudio); // add the new audio track
m.setTracks(nuTracks);
Container c = new DefaultMp4Builder().build(m);
try {
c.writeContainer(new FileOutputStream(baseDir+"/result4.mp4").getChannel());
} catch (IOException e) {
e.printStackTrace();
}
I have a video of 13 seconds and audio of 8 seconds I want to replace the audio for specific time, and use the original audio for the rest, but the above code mutes the original audio, and replaces the audio for the first 8 seconds, rest 5 seconds is mute.
Hi,
sorry for the late amswer. I'm currently booked full-time so there is not much time left to answer emails.
you cannot playback more than one track at the same time. You cannot switch between tracks. You will need to create a new track from the two source tracks. Basically that means: Decoding, mixing, encoding.
You can either use ffmpeg on the desktop or MediaCodec API on Android.
Beste Grüße, Sebastian
Stewie [email protected] schrieb am Do., 23. Juni 2016 um 08:09 Uhr:
Hi Sannies, Thanks for the library, its really helpful, can you please help me to sort out this issue
Movie m = null; try { m = MovieCreator.build(baseDir+"/VID-20160609-WA0000.mp4"); } catch (IOException e) { e.printStackTrace(); } List<Track> nuTracks = new ArrayList<>(); for (Track t : m.getTracks()) { // Re-use all tracks besides the audio track if (!"soun".equals(t.getHandler())) nuTracks.add(t);
} Track nuAudio = null; try { nuAudio = new AACTrackImpl(new FileDataSourceImpl(baseDir+"/laugh.aac")); nuAudio.getEdits().add(new Edit(5000, 1000, 1, 5)); } catch (IOException e) { e.printStackTrace(); } nuTracks.add(nuAudio); // add the new audio track m.setTracks(nuTracks); Container c = new DefaultMp4Builder().build(m); try { c.writeContainer(new FileOutputStream(baseDir+"/result4.mp4").getChannel()); } catch (IOException e) { e.printStackTrace(); }
I have a video of 13 seconds and audio of 8 seconds I want to replace the audio for specific time, and use the original audio for the rest, but the above code mutes the original audio, and replaces the audio for the first 8 seconds, rest 5 seconds is mute.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sannies/mp4parser/issues/146#issuecomment-227958701, or mute the thread https://github.com/notifications/unsubscribe/AAKUD6ewz0Gkg8WDTyo186EPOG6tkHFDks5qOiL9gaJpZM4GsH2d .
Does anyone have a solution for it?