Merge Videos
See original GitHub issueHi
I was following this issue but I am still having issues merging 2 video files My code is as follows `@Test public void test() throws IOException { String introVideoFile=“C:\development\vid\final\tmpIntro_3.mp4”; String videoContentFile=“C:\development\vid\final\tmpContent_3.mp4”;
VideoPropertiesVO videoPropertiesVO = new VideoPropertiesVO();
videoPropertiesVO.setOutputVideoFileLocation("C:\\development\\vid\\final\\output.mp4");
boolean concatResult = concatVideos(videoPropertiesVO, introVideoFile, videoContentFile);
System.out.println("concatResult:" + concatResult);
}
private static boolean concatVideos(VideoPropertiesVO videoPropertiesVO, String introVideoFile, String videoContentFile)
throws IOException {
System.out.println("introVideoFile:" + introVideoFile);
System.out.println("videoContentFile:" + videoContentFile);
FFmpeg ffmpeg = new FFmpeg(Constants.FFMPEG_EXE_PATH);;
FFprobe ffprobe= new FFprobe(Constants.FFPROBE_EXE_PATH);
Path listOfFiles = null;
try {
Path intro = Paths.get(introVideoFile);
Path content = Paths.get(videoContentFile);
Path[] files = new Path[2];
files[0] = intro;
files[1] = content;
String filesStrings = List(files).map(f -> f.toAbsolutePath().toString()).map(p -> "file '" + p + "'")
.mkString(System.getProperty("line.separator"));
listOfFiles = Files.createTempFile(intro.getParent(), "ffmpeg-list-", ".txt");
Files.write(listOfFiles, filesStrings.getBytes());
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(listOfFiles.toAbsolutePath().toString())
.setFormat(FORMAT_CONCAT).addExtraArgs("-safe")
.addOutput(videoPropertiesVO.getOutputVideoFileLocation())
.setAudioCodec(CODEC_COPY)
.setVideoCodec(CODEC_COPY).done();
builder.setVerbosity(Verbosity.DEBUG);
FFmpegExecutor fFmpegExecutor = new FFmpegExecutor(ffmpeg, ffprobe);
fFmpegExecutor.createJob(builder).run();
} catch (IOException e) {
System.out.println("Error during Ffmpeg conversion: Exception:" + e);
} finally {
Path finalListOfFiles = listOfFiles;
if (nonNull(listOfFiles)) {
Try(() -> Files.deleteIfExists(finalListOfFiles));
}
}
return true;
}`
I can verify that all files do exist.
The output I get is as follows
introVideoFile:C:\development\vid\final\tmpIntro_3.mp4 videoContentFile:C:\development\vid\final\tmpContent_3.mp4 ffmpeg version N-89343-g83ecdc9a92 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7.2.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx libavutil 56. 4.100 / 56. 4.100 libavcodec 58. 6.102 / 58. 6.102 libavformat 58. 2.103 / 58. 2.103 libavdevice 58. 0.100 / 58. 0.100 libavfilter 7. 5.100 / 7. 5.100 libswscale 5. 0.101 / 5. 0.101 libswresample 3. 0.101 / 3. 0.101 libpostproc 55. 0.100 / 55. 0.100 Splitting the commandline. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-v' ... matched as option 'v' (set logging level) with argument 'debug'. Reading option '-f' ... matched as option 'f' (force format) with argument 'concat'. Reading option '-safe' ... matched as AVOption 'safe' with argument '-i'. Reading option 'C:\development\vid\final\ffmpeg-list-8634572609066384284.txt' ... matched as output url. Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'. Reading option 'C:\development\vid\final\output.mp4' ... matched as output url. Finished splitting the commandline. Parsing a group of options: global . Applying option y (overwrite output files) with argument 1. Applying option v (set logging level) with argument debug. Successfully parsed a group of options. Parsing a group of options: output url C:\development\vid\final\ffmpeg-list-8634572609066384284.txt. Applying option f (force format) with argument concat. Successfully parsed a group of options. Opening an output file: C:\development\vid\final\ffmpeg-list-8634572609066384284.txt. [NULL @ 000002164fc2ab60] Requested output format 'concat' is not a suitable output format C:\development\vid\final\ffmpeg-list-8634572609066384284.txt: Invalid argument
The main error is [NULL @ 000002164fc2ab60] Requested output format ‘concat’ is not a suitable output format
Could someone please help to validate what may be the issue here?
Thank you Damien
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top GitHub Comments
I got it working! using .addExtraArgs(“-safe”, “0”)
I got it working now: I was using relative paths in the TXT file. Using absolute paths there solved the problem!