-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ffmpeg version included in 2.7.3 is a vry old one, which might cause the issue. #166
Comments
Hello @a-schild . i must reopen #160 . sorry. when i use jave-all-deps:3.2.0-SNAPSHOT.i cannot concat mp4 correctly again. my story is : when i do concat mp4 in 2.7.3 ,i can't concat mp4 together directly. so i google lots of pages ,finnally a method told me
it works.:) but now in 3.2.0-snapshot . neither directly concat mp4 nor transcode ts then concat is ok. :( i test it on my mac. my codes below: String tmpdir = System.getProperty("java.io.tmpdir");
public List<String> formatVideo(List<String> videoPathList, String targetFormat)
throws IllegalArgumentException,EncoderException {
AudioAttributes audio = new AudioAttributes();
audio.setCodec(DIRECT_STREAM_COPY);
VideoAttributes video = new VideoAttributes();
video.setCodec(DIRECT_STREAM_COPY);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
attrs.setEncodingThreads(2);
for (String o: videoPathList) {
String[] keySplit = o.split("/");
String fileName = keySplit[keySplit.length - 1];
String targetName = fileName.substring(0,fileName.lastIndexOf(".") + 1) + targetFormat;
File target = new File(targetPath, targetName);
if (target.exists()) {
target.delete();
}
Encoder encoder = new Encoder();
try {
encoder.encode(new MultimediaObject( new File(o)), target, attrs);
}catch (Exception e){
throw e;
}
formattedList.add(targetPath + targetName);
}
return formattedList;
}
public String concatVideo(List<String> filePathList, String concatName) throws IllegalArgumentException, InputFormatException,
EncoderException {
File target = new File(tmpdir, concatName);
if (target.exists()) {
target.delete();
}
AudioAttributes audio = new AudioAttributes();
audio.setCodec(DIRECT_STREAM_COPY);
audio.setBitRate(96000);
audio.setSamplingRate(16000);
audio.setChannels(1);
VideoAttributes video = new VideoAttributes();
video.setCodec(DIRECT_STREAM_COPY);
video.setBitRate(2045000);
video.setFrameRate(24);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat(concatName.substring(concatName.lastIndexOf(".") + 1));
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
attrs.setEncodingThreads(2);
Encoder encoder = new Encoder();
List<MultimediaObject> src = new ArrayList<>();
for (String o : filePathList) {
File sourceTmp = new File(o);
src.add(new MultimediaObject(sourceTmp));
}
encoder.encode(src, target, attrs);
Assert.isTrue(target.exists(), "Output file missing");
return target.getAbsoluteFile().getAbsolutePath();
}
//for instance: if you have 2 mp4 file , names are /data/a.mp4 (10M) and /data/b.mp4(5M).two mp4 filies are the same . video is h264 1280*720 .audio is aac 1ch 16khz
List<String> filePathList;
filePathList.add(' /data/a.mp4 ');
filePathList.add(' /data/b.mp4 ');
concatVideo(filePathList,'result.mp4');
//or
List<String> formattedPath = formatVideo(filePathList, "ts");
concatVideo(formattedPath,'result.mp4');
the result is only System.getProperty("java.io.tmpdir")/result.mp4 produced. only 10M~ could u test mp4 concat in 3.2.0-snapshot thank you. |
After deepdiving into the code, I'm wondering if the concat did ever work properly...
|
Can you please try the new 3.2.1-SNAPSHOT release?
|
i have updated to 3.2.1-snapshot and i change my code below: public String concatVideo(List<String> filePathList, String concatName) throws IllegalArgumentException, InputFormatException,
EncoderException {
File target = new File(tmpdir, concatName);
if (target.exists()) {
target.delete();
}
AudioAttributes audio = new AudioAttributes();
audio.setCodec(DIRECT_STREAM_COPY);
audio.setBitRate(96000);
audio.setSamplingRate(16000);
audio.setChannels(1);
VideoAttributes video = new VideoAttributes();
video.setCodec(DIRECT_STREAM_COPY);
video.setBitRate(2045000);
video.setFrameRate(24);
//a Filter to encoding codes added
FilterGraph complexFiltergraph= new FilterGraph();
FilterChain fc= new FilterChain();
fc.addFilter(new MediaConcatFilter(filePathList.size()));
complexFiltergraph.addChain(fc);
video.setComplexFiltergraph(complexFiltergraph);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat(concatName.substring(concatName.lastIndexOf(".") + 1));
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
attrs.setEncodingThreads(2);
Encoder encoder = new Encoder();
List<MultimediaObject> src = new ArrayList<>();
for (String o : filePathList) {
File sourceTmp = new File(o);
src.add(new MultimediaObject(sourceTmp));
}
encoder.encode(src, target, attrs);
Assert.isTrue(target.exists(), "Output file missing");
return target.getAbsoluteFile().getAbsolutePath();
}
1.concat mp4 directly: 2.first transcode to .ts and then concat and transcodde to .mp4 finally, i think add Filter is not a better method . because it take time longger , file bigger , resuoce taken more. and it seem not stop by itself. could u try concat your mp4 for test and show ur test result and process detail? |
It's been 9 hours since MY last reply. i closed the jave thread and close my mac screen and dealing with my home stuff,now i return , i found my mac power very low (11%) and its fans run fast make a big noise. i open "Activity monitor" see 3 ffmpeg process are still running. so do you think it is a bug? |
In the testConcatVideo2() unit test, the concat of two mp4 files work as expected |
i wil check later. thx your work |
HI @a-schild.
video.setFrameRate(30);
video.setSize(new VideoSize(320, 240));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat("mp4");
attrs.setVideoAttributes(video);
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
List<MultimediaObject> src = new ArrayList<>();
src.add(new MultimediaObject(source1));
src.add(new MultimediaObject(source2));
//why these code below attrs.setVideoAttributes(video);?
FilterGraph complexFiltergraph= new FilterGraph();
FilterChain fc= new FilterChain();
fc.addFilter(new MediaConcatFilter(src.size()));
complexFiltergraph.addChain(fc);
video.setComplexFiltergraph(complexFiltergraph); 2.i have two mp4 videos. the first one 18M and ffprobe information is:
the scond one 21M and ffprobe information is:
now , the concat work is still running . the concated mp4 video is 104M and is still growing.my mac's fan is making big noise. i use the jave version is 3.2.1-snapshot implementation 'ws.schild:jave-all-deps:3.2.1-SNAPSHOT' and my code below here: public String concatVideo(Long taskId, List<String> filePathList, DirType targetDir, String concatName) throws IllegalArgumentException, InputFormatException,
EncoderException {
String targetDirPath = fileInfra.makeDirPath(taskId, targetDir);
File target = new File(targetDirPath, concatName);
if (target.exists()) {
target.delete();
}
AudioAttributes audio = new AudioAttributes();
FilterGraph complexFiltergraph= new FilterGraph();
FilterChain fc= new FilterChain();
fc.addFilter(new MediaConcatFilter(filePathList.size()));
complexFiltergraph.addChain(fc);
video.setComplexFiltergraph(complexFiltergraph);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat(concatName.substring(concatName.lastIndexOf(".") + 1));
attrs.setOutputFormat("mp4");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
attrs.setEncodingThreads(2);
Encoder encoder = new Encoder();
List<MultimediaObject> src = new ArrayList<>();
for (String o : filePathList) {
File sourceTmp = new File(o);
src.add(new MultimediaObject(sourceTmp));
}
encoder.encode(src, target, attrs);
Assert.isTrue(target.exists(), "Output file missing");
return target.getAbsoluteFile().getAbsolutePath();
} |
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
Originally posted by @a-schild in #160 (comment)
The text was updated successfully, but these errors were encountered: