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

Question: How to merge audio&video files (mux) so that the audio will loop if needed? #11

Open
AndroidDeveloperLB opened this issue Feb 24, 2019 · 2 comments

Comments

@AndroidDeveloperLB
Copy link

Using this library (or others), is it possible to merge audio&video together, so that the output video will be of the same duration as the input video, and have the audio loop if it's shorter than the video?

I've asked about it here too:
https://stackoverflow.com/q/54769976/878126

@AndroidDeveloperLB
Copy link
Author

AndroidDeveloperLB commented Feb 24, 2019

I tried to use this:
https://superuser.com/a/1319950/152400

by writing this in AudioVideoMerger class:

val cmd = arrayOf("-i", video!!.path, "-filter_complex", "amovie=${audio!!.path}:loop=0,asetpts=N/SR/TB[aud];[0:a][aud]amix[a]", "-map", "0:v", "-map", "[a]", "-c:v", "copy", "-c:a", "aac", "-b:a", "256k", "-shortest", outputLocation.path)

It worked, but the audio of the video file remained, so both are playing.
Also, it's quite slow in making the output file... :(

@AndroidDeveloperLB
Copy link
Author

AndroidDeveloperLB commented Feb 25, 2019

Never mind, got it:

    val cmd = arrayOf("-i", video!!.absolutePath, "-stream_loop", "-1", "-i", audio!!.absolutePath, "-c:v", "copy","-c:a","copy", "-map", "0:v:0", "-map", "1:a:0", "-shortest", outputLocation.absolutePath)

It sometimes work really well, but for some reason the sample project can't play the output file. In some other cases, the output video gets to be as short as the audio...

How come?

I tried this too, but it didn't help:

    val cmd = arrayOf("-i", video!!.absolutePath, "-stream_loop", "-1", "-i", audio!!.absolutePath, "-c:v", "copy", "-c:a", "copy", "-map", "0:v:0", "-map", "1:a:0", "-vprofile", "baseline",
            "-movflags", "faststart", "-shortest", outputLocation.absolutePath)

If I remove the "-c:a","copy" , it will succeed playing, but also will take a long time to make the file...

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

1 participant