简体   繁体   English

FFmpeg使用Java运行时在Mac上以目录名称中的空格从PNG制作视频

[英]FFmpeg Using Java Runtime to Make Video From PNG on Mac with Spaces in Directory Names

I have run into a problem on Mac OSX where I'm trying to make video from PNG's such as: 我在Mac OSX上遇到问题,我试图从PNG制作视频,例如:

String command = "ffmpeg -r 30 -i " + outputFileName + fileName + "_%d.png -i "+
    outputFileName + fileName + ".wav -r 30 -pix_fmt yuv420p " +
    outputFileName + videoName;

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);

Unfortunately, I don't have any control over these filenames and they come to me with spaces in them. 不幸的是,我对这些文件名没有任何控制,它们以空格出现在我面前。 On Windows, I simply surround the command with quotes and all works as expected. 在Windows上,我只用双引号将命令引起来,并且所有工作都按预期进行。 However, on Mac, I tried that and many other things to no avail. 但是,在Mac上,我尝试了此操作以及许多其他操作,但均无济于事。 Once a space is encountered in the filename, FFmpeg reports that the file cannot be found and truncates the string up to the point of the first space. 在文件名中遇到空格后,FFmpeg报告找不到文件,并将字符串截断到第一个空格为止。 When I surround the filename with quotes, FFmpeg tells me it can't find the file and shows me the quotes around the file. 当我用引号将文件名引起来时,FFmpeg告诉我找不到文件,并显示文件周围的引号。 Such as: 如:

String command = "ffmpeg -r 30 -i \" + outputFileName...\"

Assume the filename is: 假设文件名是:

/Users/me/Application Folder/... /用户/我/应用程序文件夹/ ...

FFmpeg will report: "/Users/me/Application: No such file or directory. FFmpeg将报告:“ / Users / me / Application:没有这样的文件或目录。

Without the quotes, it will error with: /Users/me/Application: No such file or directory. 没有引号,它将出现以下错误:/ Users / me / Application:没有这样的文件或目录。

I have tried every escape sequence I can think of. 我已经尝试了所有可以想到的转义序列。 I've also tried putting the escape characters only in the file name where the spaces occur such as: 我还尝试过将转义符仅放在出现空格的文件名中,例如:

outputFileName = outputFileName.replace(" ", "\" \"");

In that instance, FFmpeg says: /Users/me/Application": No such file or directory. 在这种情况下,FFmpeg说:/ Users / me / Application“:没有这样的文件或目录。

Along with escaping with quotes, I tried: 除了用引号转义,我还尝试了:

outputFileName = outputFileName.replace(" ", "\\");

I also tried: 我也尝试过:

outputFileName = outputFileName.replace(" ", "\\ ")

In those cases, I get: /Users/me/Application: No such file or directory. 在那种情况下,我得到:/ Users / me / Application:没有这样的文件或目录。

[Edit: in the preview I see the backslash at the end of application but in the final post it's not there... there's a backslash you should see such as '/.../Application\\'] [编辑:在预览中,我在应用程序的末尾看到反斜杠,但在最后一篇文章中不存在反斜杠...您应该看到一个反斜杠,例如'/.../ Application \\']

Can someone tell me how to get FFmpeg to run my command when the directory name has spaces in it? 有人可以告诉我如何在目录名称中包含空格的情况下使FFmpeg运行我的命令吗? I have no control over the directory names when they come to me. 当目录名称出现时,我无法控制它们。 Java is able to find these directories just fine without any sort of escape characters in the directory name. Java能够很好地找到这些目录,而目录名中没有任何转义字符。 What do I have to do to get FFmpeg to do the same? 我要怎么做才能使FFmpeg做到相同?

Thanks for your help. 谢谢你的帮助。

Use ProcessBuilder instead. 请改用ProcessBuilder Also, don't use one long command string. 另外,请勿使用一个长命令字符串。 Break your command up into individual arguments: 将您的命令分解为各个参数:

ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM