Android: ffmpeg with filenames containing spaces

烂漫一生 提交于 2019-12-31 05:30:13

问题


I want to execute ffmpeg from an Android app, very much as described here: Using FFmpeg with Android-NDK.

Executing the following commands work fine:

Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/ffmpeg -i infile.mp4 outfile.mp4");

or

Process p = Runtime.getRuntime().exec(new String[]{"/data/data/yourpackagename/ffmpeg", "-i", "infile.mp4", "outfile.mp4");

But when the input or output filenames contain spaces ffmpeg fails with a "File not found" error:

Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/ffmpeg -i \"in space file.mp4\" outfile.mp4"); // fails
Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/ffmpeg -i 'in space file.mp4' outfile.mp4"); // fails
Process p = Runtime.getRuntime().exec(new String[]{"/data/data/yourpackagename/ffmpeg", "-i", "\"in space file.mp4\"", "outfile.mp4"); //fails

FFMPEG also fails for files without spaces but quoted:

Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/ffmpeg -i \"infile.mp4\" outfile.mp4"); // fails

How can I correctly pass a filename containing spaces to the ffmpeg command?

Regards,


回答1:


Wild guess , but you may want the java process to pass "\ " read "backslash space" to the underlying OS when you want ffmpeg to open a file with a name containing a space.

Its not what the java does with the string fileName. Its what the underlying OS and ffmpeg process receives that it will use as 'filename'. There you want "foo bar.input" to be

"foo\ bar.input"

So, the underlying expression "ffmpeg -i foo\ bar.input" should work.

you just need to figure out how to construct your java strings so that the process feeds the above expression to the NDK / process layer running the "ffmpeg" command.

more here




回答2:


I finally got it. I forgot one possibility, and exactly this one is working:

Process p = Runtime.getRuntime().exec(new String[]{"/data/data/yourpackagename/ffmpeg", "-i", "in space file.mp4", "outfile.mp4"); //OK


来源:https://stackoverflow.com/questions/23697398/android-ffmpeg-with-filenames-containing-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!