FFMPEG command fails for file path with white spaces

后端 未结 2 1140
面向向阳花
面向向阳花 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 + "\"";
        }
    

提交回复
热议问题