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 two videos files side by side horizontally #2286

Open
kamrapooja opened this issue Sep 25, 2024 · 2 comments
Open

Merge two videos files side by side horizontally #2286

kamrapooja opened this issue Sep 25, 2024 · 2 comments

Comments

@kamrapooja
Copy link

I have two webm files a.webm and b.webm having same dimensions and framerate. Purpose is to merge both videos side by side horizontally and get MP4 as output.
For the same, I took reference code given in #955 post. But that did not work.
I am not able to understand how the below code snippet working:
while ((frame2 = grabber.grab()) != null) {
if (frame2.image != null) {
a++;
}
if (frame2.samples != null) {
b++;
}
filter.push(0, frame2);
filter.push(1, frame2);
Frame frame3;
while ((frame3 = filter.pull()) != null) {
if (frame3.image != null) {
c++;
assertEquals(640, frame3.imageWidth);
assertEquals(200, frame3.imageHeight);
assertEquals(3, frame3.imageChannels);
}
if (frame3.samples != null) {
d++;
assertEquals(2, frame3.audioChannels);
assertEquals(1, frame3.samples.length);
assertTrue(frame3.samples[0] instanceof ByteBuffer);
assertEquals(frame2.samples.length, frame3.samples.length);
assertEquals(frame2.samples[0].limit(), frame3.samples[0].limit());
}
}
}

Please assist for the same.

@saudet
Copy link
Member

saudet commented Sep 25, 2024

We can easily accomplish this with the ffmpeg program:
http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html

@kamrapooja
Copy link
Author

kamrapooja commented Sep 26, 2024

We are able to merge the videos side by side using ffmpeg command. But with javacv we are not able to do it. In the attachment, example is given to use ffmpeg command. Could you pls help how to get the merged video using javacv functions? When we are using :FFmpegFrameFilter filter = new FFmpegFrameFilter(
"[0:v][1:v]hstack=inputs=2[v]",
"[0:a][1:a]amerge[a]",
grabber.getImageWidth(), grabber.getImageHeight(), grabber.getAudioChannels());

It is giving error avfilter_graph_config() with errer -22.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants