android - 带有空格的文件路径的 FFMPEG 命令失败

标签 android ffmpeg string-formatting

我正在执行以下 ffmpeg用于修剪视频的命令。我遇到的问题是,如果文件路径包含空格,则命令失败。我尝试了多种处理空格的方法,但除了将文件移动到没有空间的路径然后执行命令外,它们都不起作用以新文件路径作为源。
下面是命令-

 execFFmpegBinary("-i " +  filepath   + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath());



private void execFFmpegBinary(final String command) {
        try {
            ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
                @Override
                public void onFailure(String s) {
                    Log.e("Previewragment", "FAILED with output : " + s);
                }

                @Override
                public void onSuccess(String s) {
                    Log.e("Previewragment", "SUCCESS with output : " + s);
                }

                @Override
                public void onProgress(String s) {
                    Log.e("Previewragment", "Started command : ffmpeg " + command);
                    Log.e("Previewragment", "progress : " + s);
                }

                @Override
                public void onStart() {
                    Log.e("Previewragment", "Started command : ffmpeg " + command);

                }

                @Override
                public void onFinish() {



                }
            });
        } catch (FFmpegCommandAlreadyRunningException e) {
            // do nothing for now
        }
    }

我看到了 answer并尝试过
 String addQuotes(String in ) {
        return "\"" + in + "\"";
    }
execFFmpegBinary("-i " +  addQuotes(filepath)   + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath())

;

最佳答案

//Process ffmpeg;
        public string exec(string input, string output, string parametri,string fileName) 
        {
        //Create the output and streamreader to get the output
        string output1 = null; StreamReader srOutput = null;
        input = addQuotes(input);
        Process ffmpeg = new Process();
        try
        {

            ffmpeg.StartInfo.Arguments = " -i " + input + " -ss 00:00:00.100 -vframes 1" + " " + output;
            ffmpeg.StartInfo.FileName = fileName;
            ffmpeg.StartInfo.UseShellExecute = false;
            ffmpeg.StartInfo.RedirectStandardOutput = true;
            ffmpeg.StartInfo.RedirectStandardError = true;
            ffmpeg.StartInfo.CreateNoWindow = true;
            ffmpeg.Start();
            ffmpeg.WaitForExit();
            //get the output
            srOutput = ffmpeg.StandardError;
            //now put it in a string
            output1 = srOutput.ReadToEnd();
            ffmpeg.Close();
        }
        catch
        {
            ffmpeg.Close();
            output = string.Empty;
        }
        finally
        {
            //now, if we succeded, close out the streamreader
            if (srOutput != null)
            {
                srOutput.Close();
                srOutput.Dispose();
            }
        }
        return output;
    }


    public string addQuotes(string s)
    {
        return "\"" + s + "\"";
    }

关于android - 带有空格的文件路径的 FFMPEG 命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33149606/

相关文章:

android - PlayN - Android 上没有声音

python - 使用python创建动态图像幻灯片

python - 以 str.format 切片字符串

导致解析错误的Java日期解析时区

android - onOptionsItemSelected() 在 Fragment 上被调用两次

java - 无法解析符号 'getDefaultAdapter()' ?

android - 渲染错误android studio

正则表达式匹配行是否存在

bash - 如何使用 bash 脚本或简化 ffmpeg 命令以调整水印大小、将其添加到视频中并将 subtitle.ass 添加到视频中?

python - 在Python3中打印涉及英语和日语文本的右对齐表格列