FFMPEG command fails for file path with white spaces

后端 未结 2 1139
面向向阳花
面向向阳花 2021-01-22 20:43

I am executing the below ffmpeg command for trimming videos.The issue I am having is that if filepath contains spaces then the command fails.I tried many ways to ha

相关标签:
2条回答
  • 2021-01-22 21:29
    //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 + "\"";
        }
    
    0 讨论(0)
  • 2021-01-22 21:40

    You must switch to string-array variant of Runtime.exec(), as described in ffmpeg-android-java.

    For the adventurous, there is a hidden trick in ffmpeg, but IMHO working with String[] is both easier and more robust.

    0 讨论(0)
提交回复
热议问题