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

Cannot add audio (.wav) to a video file (.mp4) #204

Open
dr-slurp opened this issue Apr 24, 2022 · 4 comments
Open

Cannot add audio (.wav) to a video file (.mp4) #204

dr-slurp opened this issue Apr 24, 2022 · 4 comments

Comments

@dr-slurp
Copy link

Hey! Overall I love jave, had tons of luck with splitting .mp4s. Now I need to add audio to my video files.

`attributes = new EncodingAttributes();
attributes.setOutputFormat("mp4");
attributes.setVideoAttributes(video);
attributes.setAudioAttributes(audio);

	MultimediaObject originalVideo = new MultimediaObject(new File(pathToVideo));
	MultimediaObject originalAudio = new MultimediaObject(new File(pathToAudio));
	ArrayList<MultimediaObject> sources = new ArrayList<MultimediaObject>();
	sources.add(originalVideo);
	sources.add(originalAudio);
	
	File target = new File(pathToCombined);

	
	encoder.encode(sources, target, attributes);`

and I'm getting a
Exception in thread "main" ws.schild.jave.EncoderException: Exit code of ffmpeg encoding run is 1 at ws.schild.jave.Encoder.encode(Encoder.java:638) at ws.schild.jave.Encoder.encode(Encoder.java:481) at ws.schild.jave.Encoder.encode(Encoder.java:324) at dr_slurp.MyceliumFidelity.Video.VideoSplitter.addAudioToVideo(VideoSplitter.java:92) at dr_slurp.MyceliumFidelity.MyFiTester.audioAdder(MyFiTester.java:34) at dr_slurp.MyceliumFidelity.MyFiTester.main(MyFiTester.java:26)

Is there a way to put audio on a video file that has no audio already?

Thanks,

@dr-slurp
Copy link
Author

dr-slurp commented Apr 24, 2022

FYI, I am able to add audio to the video if I use this command in the CLI:
ffmpeg -i v.mp4 -i a.wav -c:v copy -map 0:v:0 -map 1:a:0 new.mp4
Is there a way to run arbitrary ffmpeg commands from jave2, or a way to run a similar command programatically?

THANKS!

@DoreamonWdy
Copy link

I also wanna to implement it, but i don't find any method.
so sad..

@dr-slurp
Copy link
Author

@wxyleo
This is how i'm doing it without jave2, good luck

`

	Runtime rt = Runtime.getRuntime();
	Process pr = rt.exec("/opt/homebrew/bin/ffmpeg -i "+pathToVideo+" -i "+pathToAudio+" -c:v copy -map 0:v:0 -map 1:a:0 "+pathToCombined);

	BufferedReader stdInput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
	BufferedReader stdError = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
	
	String s = null;
	while ((s = stdInput.readLine()) != null) 
	{
	    System.out.println(s);
	}

	// Read any errors from the attempted command
	System.out.println("Here is the standard error of the command (if any):\n");
	while ((s = stdError.readLine()) != null) {
	    System.out.println(s);
	}

// Process pr = rt.exec("/opt/homebrew/bin/ffmpeg");
System.out.println(pr.getOutputStream().toString());
int result = pr.waitFor();
if(result == 0)
{
System.out.println("success");
}`

@DoreamonWdy
Copy link

tks

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

2 participants