a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.24k stars 247 forks source link

concat mp4 not working properly. version 2.7.3 #160

Closed naffan2014 closed 3 years ago

naffan2014 commented 3 years ago

i have two videos. every videos duration is 5min. i want to concat these videos to one. i thought it will produce a 10min video. but not . result is only one 5min video produced. below is my code.

i use jave-all-deps:2.7.3

public String concatVideo(Long taskId, List<String> fileList, String concatName) throws Exception{
        String storagePath =  fileInfra.makeDirPath(taskId, DirType.STORAGE);
        String cutPath = fileInfra.makeDirPath(taskId, DirType.CONCAT);
        //构造目标文件名
        File target = new File(cutPath, concatName);
        if (target.exists()) {
            target.delete();
        }
        AudioAttributes audio = new AudioAttributes();
        //音频编码
        audio.setCodec("aac");
        //码率
        audio.setBitRate(96000);
        //取样率
        audio.setSamplingRate(16000);
        //单声道
        audio.setChannels(1);
        VideoAttributes video = new VideoAttributes();
        //视频编码
        video.setCodec("h264");
        video.setBitRate(2045000);
        video.setFrameRate(24);
        video.setSize(new VideoSize(1280, 720));
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp4");
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        File source1 = new File("/var/folders/2y/jqhn24qs34sb1699gcdrdr_h0000gn/T/20210828/STORAGE/1_1630150938&14248_1630150204.mp4");
        File source2 = new File("/var/folders/2y/jqhn24qs34sb1699gcdrdr_h0000gn/T/20210828/STORAGE/1_1630150920&14248_1630150506.mp4");
        List<MultimediaObject> src = new ArrayList<>();
        src.add(new MultimediaObject(source1));
        src.add(new MultimediaObject(source2));
        encoder.encode(src, target, attrs);
        Assert.isTrue(target.exists(), "Output file missing");
        return target.getAbsoluteFile().getAbsolutePath();
    }
a-schild commented 3 years ago

Could you please upgrade to the current 3.1.x version and try again?

In addition: When passing multiple sources, make sure that they are compatible in the way that ffmpeg can concat them. We don't use the complex filter at the moment Perhaps you will need to first transcode/resize them https://trac.ffmpeg.org/wiki/Concatenate @see "Concat protocol"

naffan2014 commented 3 years ago

Could you please upgrade to the current 3.1.x version and try again?

In addition: When passing multiple sources, make sure that they are compatible in the way that ffmpeg can concat them. We don't use the complex filter at the moment Perhaps you will need to first transcode/resize them https://trac.ffmpeg.org/wiki/Concatenate @see "Concat protocol"

becasuse some reason,i can't use 3.1.1. because our maven repository has some bugs so i can only get 2.7.3.

i have tried lots of ways, fianlly i first transcode .mp4 to .ts. then i concat them, at last i transcode .ts back to .mp4.i t works. but it is a low efficiency method.

i am sure of that my mp4 file are compatible in ffmpeg. but why mp4 cannot directly concat in 2.7.3?

a-schild commented 3 years ago

The ffmpeg version included in 2.7.3 is a vry old one, which might cause the issue. You could enable debug logging and see why it fails.

We don't have enough resources to support such old versions