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

setComplexVideoFilter with unexpected results with filtergraph #81

Open
igracia opened this issue Dec 8, 2016 · 6 comments
Open

setComplexVideoFilter with unexpected results with filtergraph #81

igracia opened this issue Dec 8, 2016 · 6 comments

Comments

@igracia
Copy link
Contributor

igracia commented Dec 8, 2016

I'm using the setComplexVideoFilter to add an adelay/amix filter, to merge audio and video tracks that have different lengths, into a single file. I have ffmpeg 3.2 installed in OS X.

The actual command that works is
ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex "[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1" -c:v copy out.webm. To have the library generating the same command, I had to add escaped quotes to the string, producing the following line outputBuilder.setComplexVideoFilter("\"[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1\"");. This yields the following result.

/usr/local/bin/ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex "[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1" -c:v copy out.webm
Truncating packet of size 21863284 to 2742585
Truncating packet of size 21863284 to 181769
[AVFilterGraph @ 0x7faa89416fe0] No such filter: '"'
Error initializing complex filters.
Invalid argument

Issuing the following line outputBuilder.setComplexVideoFilter("[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1"); produces an expected error, as the complex filter should go between quotes

/usr/local/bin/ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex [1:0]adelay=10000|10000[t1];[t1]amix=inputs=1 -c:v copy out.webm
Truncating packet of size 21863284 to 2742585
Truncating packet of size 21863284 to 181769
Filter amix has an unconnected output

which is expected, as it is the same output that you get when running from command line.

Not sure if there's anything we can do here, and is a problem from the ProcessBuilder itself. Any ideas?

@igracia igracia changed the title setComplexVideoFilter with unexpected results with adelay/amix setComplexVideoFilter with unexpected results with adelay/amix Dec 8, 2016
@igracia
Copy link
Contributor Author

igracia commented Dec 8, 2016

@bramp Could this be related with #76?

@igracia igracia changed the title setComplexVideoFilter with unexpected results with adelay/amix setComplexVideoFilter with unexpected results with filterchains Dec 8, 2016
@igracia igracia changed the title setComplexVideoFilter with unexpected results with filterchains setComplexVideoFilter with unexpected results with filtergraph Dec 8, 2016
@igracia
Copy link
Contributor Author

igracia commented Dec 8, 2016

More failed tests with similar results

  • [1:0]adelay=10000[t1];[t1]amix=inputs=1 (remove the pipe |)
  • [1:0]adelay=10000[t1],[t1]amix=inputs=1 (replace the semicolon ;)

The last filter would allow us to run from the command line as ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex [1:0]adelay=10000[t1],[t1]amix=inputs=1 -c:v copy out.webm, but both produce wrong output when run from a Java program.

@igracia
Copy link
Contributor Author

igracia commented Dec 8, 2016

It seems like it is related to how ProcessBuilder handles those args, and the fact that certain args have to be escaped. I've managed to get it working with this workaround

ffmpeg = new ProcessBuilder(
                    new String[] { "/bin/sh", "-c", "/usr/local/bin/ffmpeg " + argsStr })
                            .redirectErrorStream(true).start();

Not sure the "/bin/sh" , "-c" is something you want to have there. Should I upload a PR?

@igracia
Copy link
Contributor Author

igracia commented Dec 26, 2016

@bramp Would you accept a pull request with this modification?

@bramp
Copy link
Owner

bramp commented Dec 26, 2016

There are a lot of Windows users of this library, so I wouldn't want to put a Linux specific fix in place. I will accept pull requests to fix this in a generic way.

@bramp
Copy link
Owner

bramp commented Dec 26, 2016

I just read more about the failings in how java handles character escaping. http://bugs.java.com/view_bug.do?bug_id=6468220 and http://bugs.java.com/view_bug.do?bug_id=6518827

It might be worth using https://commons.apache.org/proper/commons-exec/index.html instead of the process builder. Happy to accept that pull request.

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