cropsly / ffmpeg-android-java

Android java library for FFmpeg binary compiled using https://github.com/writingminds/ffmpeg-android
http://writingminds.github.io/ffmpeg-android-java
GNU General Public License v3.0
3.32k stars 831 forks source link

concat videos #167

Open AnswerZhao opened 7 years ago

AnswerZhao commented 7 years ago

with "ffmpeg -f concat -i mylist.txt -c copy output" to concat 2 videos, it can't work.The error is following: Non-monotonous DTS in output stream 0:0; previous: 1396402, current: 181462; changing to 1396403. This may result in incorrect timestamps in the output file.

fxhereng commented 7 years ago

Encountered the same issue, it happens if you have different bitrate in your videos, it takes the config of the first one. It's preferable using a filter_complex, something like:

 String[] ffmpegCommand2 = {"-i", videoFile1.getAbsolutePath(), "-i", videoFile2.getAbsolutePath(), "-filter_complex", "[0:v:0] [1:v:0] concat=n=2:v=1 [v]", "-map", "[v]", "-c:v", "libx264", "-strict", "experimental", "-preset", "ultrafast", "-threads", "16", outputResultPath};
ffmpeg.execute(ffmpegCommand2, [...]);

Note that this command is only for videos, I haven't tried yet with the audio. Change the video codec -c:v if needed.

Preset and threads are not mandatory, read the ffmpeg doc if you need more details: https://trac.ffmpeg.org/wiki/Concatenate (concat filter section)