Skip to content
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

Merge Videos #147

Closed
damogallagher opened this issue Dec 4, 2017 · 11 comments
Closed

Merge Videos #147

damogallagher opened this issue Dec 4, 2017 · 11 comments

Comments

@damogallagher
Copy link

Hi

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

@HadesDX
Copy link

HadesDX commented Sep 3, 2018

Hi, could you solve it? im facing the same issue when adding the .addExtraArgs("-safe")

@HadesDX
Copy link

HadesDX commented Sep 3, 2018

I got it working! using
.addExtraArgs("-safe", "0")

@ghost
Copy link

ghost commented Nov 14, 2018

What is CODEC_COPY in your code?

@willy-wonka-git
Copy link

I got it working! using
.addExtraArgs("-safe", "0")

I'm trying but not working. Windows

    try {
        FFprobe ffprobe = new FFprobe("d:\\Distr\\ffprobe.exe");
        FFmpeg ffmpeg = new FFmpeg("d:\\Distr\\ffmpeg.exe");

        FFmpegProbeResult probeResult = ffprobe.probe("d:\\11111\\lqCfwIbG1EU.mp4");
        FFmpegFormat format = probeResult.getFormat();
        
        FFmpegStream  stream = probeResult.getStreams().get(0);
        
        FFmpegBuilder builder = new FFmpegBuilder()
                .setInput("d:\\11111\\list.txt") 
                .setFormat("concat") 
                .addExtraArgs("-safe", "0")
                .overrideOutputFiles(true) // Override the output if it exists
                .addOutput("d:\\11111\\output.mp4") // Filename for the destination
                //.setTargetSize(250_000) // Aim for a 250KB file
                .disableSubtitle() // No subtiles

                .setAudioChannels(1) // Mono audio
                .setAudioCodec("aac") // using the aac codec
                .setAudioSampleRate(48_000) // at 48KHz
                .setAudioBitRate(32768) // at 32 kbit/s

                .setVideoCodec("libx264") // Video using x264
                .setVideoFrameRate(24, 1) // at 24 frames per second
                .setVideoResolution(1080, 720) // at 640x480 resolution

                .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
                .done();

            builder.setVerbosity(FFmpegBuilder.Verbosity.DEBUG);
        
        FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

        // Run a one-pass encode
        executor.createJob(builder).run();

        // Or run a two-pass encode (which is better quality at the cost of being slower)
        //executor.createTwoPassJob(builder).run();
        
    } catch (Exception e) {
        System.err.println(e);
    }

ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.100 / 57. 64.100
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.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 '0'.
Reading option '-i' ... matched as input file with argument 'd:\11111\list.txt'.
Reading option '-strict' ...Routing option strict to both codec and muxer layer
matched as AVOption 'strict' with argument 'experimental'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libx264'.
Reading option '-s' ... matched as option 's' (set frame size (WxH or abbreviation)) with argument '1080x720'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '24/1'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '1'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '48000'.
Reading option '-b:a' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '32768'.
Reading option '-sn' ... matched as option 'sn' (disable subtitle) with argument '1'.
Reading option 'd:\11111\output.mp4' ... matched as output file.
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: input file d:\11111\list.txt.
Applying option f (force format) with argument concat.
Successfully parsed a group of options.
Opening an input file: d:\11111\list.txt.
[file @ 000000000030ac40] Setting default whitelist 'file,crypto'
[concat @ 000000000030a4e0] Impossible to open 'lqCfwIbG1EU.mp4'
[AVIOContext @ 0000000000312d80] Statistics: 38 bytes read, 0 seeks
d:\11111\list.txt: No such file or directory
java.lang.RuntimeException: java.io.IOException: d:\Distr\ffmpeg.exe returned non-zero exit status. Check stdout.

@bramp
Copy link
Owner

bramp commented Jun 8, 2019

The error seems to be:

Opening an input file: d:\11111\list.txt.
d:\11111\list.txt: No such file or directory

Are you sure that file exists?

@willy-wonka-git
Copy link

The error seems to be:

Opening an input file: d:\11111\list.txt.
d:\11111\list.txt: No such file or directory

Are you sure that file exists?

The fact is that everything is in place. Will think

@pgupt
Copy link

pgupt commented Aug 14, 2019

What is CODEC_COPY in your code?

it is just "copy"

@konclackgilles
Copy link

I also have the same problem I need to input the content of a text file over a video but. I get the error, that you show above. it's maybe impossible to concat a text file witch image?

@clicit
Copy link

clicit commented Nov 25, 2019

Same problem here, anyone got this working? @HadesDX maybe?
When I start ffmpeg manually from the command with exactly the same parameters, there is no problem.

Thanks!

@clicit
Copy link

clicit commented Nov 25, 2019

Same problem here, anyone got this working? @HadesDX maybe?
When I start ffmpeg manually from the command with exactly the same parameters, there is no problem.

Thanks!

I got it working now: I was using relative paths in the TXT file. Using absolute paths there solved the problem!

@Euklios
Copy link
Collaborator

Euklios commented Mar 11, 2024

I'll close this issue, as it seems to be resolved. Feel free to reopen or create a new issue.

@Euklios Euklios closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants