Trim and merge audio and video file using ffmpeg

1.9k views Asked by At

I'm trying to trim an audio file and then merge it with my video file on android.

I can merge them together with the command below

String command[] = {"-i", mOutputFile.getAbsolutePath(), " -i", mOutputAudioFile.getAbsolutePath(), "-c:v", "copy", "-c:a", "aac","-shortest", dest.getAbsolutePath()};

But i need to trim the beginning (half-second for example) of my audio file before (for synchronization issue). So if you can help me with a single command it would be perfect but maybe i can just run two ffmpeg commands successively but i don't know how to do that as well. Thanks!

2

There are 2 answers

0
falary On BEST ANSWER

ok, i solved the problem, it was just about syntax, i had to write

{"-i", mOutputFile.getAbsolutePath(), "-ss", "0.5", "-i", mOutputAudioFile.getAbsolutePath(), "-c:v", "copy", "-c:a", "aac", "-shortest", dest.getAbsolutePath()};

thanks

2
Gyan On

Apply a seek option to the audio:

String command[] = {"-i", mOutputFile.getAbsolutePath(), " -ss 0.5", " -i", mOutputAudioFile.getAbsolutePath(), "-c:v", "copy", "-c:a", "aac","-shortest", dest.getAbsolutePath()};

This will start the audio feed from 0.5 seconds.