0

So, I'm facing a really strange issue. When I run "ffmpeg" through C# process, it doesn't work for multiple commands (concatenated with &). However, it works for simple/single command and even produces output. I checked the logs through "Standard Error" and it appears that it fails in "concat" command.

This line specifically indicates the error in the ffmpeg created log: concat:CoverImage_Video_Landscape_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts|Downloaded_Video_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts: No such file or directory

Now, the code snippet is as follows:

string arguments = $"-loop 1 -i \"{physicalPath}bin\\CoverImage_Video_Landscape_{guid}.png\" -f lavfi -i anullsrc -t 3 -c:v libx264 -c:a aac -b:a 160k -t 3 -pix_fmt yuv420p -vf scale={videoWidth}:{videoHeight} -y \"{physicalPath}bin\\CoverImage_Video_Landscape_{guid}.ts\"" 
+ $" & -i \"{physicalPath}bin\\{objectNameWithoutExtension}.mp4\" -c:v libx264 -c:a aac -b:a 160k -f mpegts \"{physicalPath}bin\\{objectNameWithoutExtension}.ts\"" 
+ $" & -i \"concat:CoverImage_Video_Landscape_{guid}.ts|{objectNameWithoutExtension}.ts\" -c copy \"{fileAssetRootPath}\\Video\\Output\\{outputVideoName}.mp4\"";

            process = new Process();
            process.StartInfo.FileName = ffmpegPath;
            process.StartInfo.Arguments = arguments;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;

            process.EnableRaisingEvents = true;
            process.Exited += new EventHandler(process_Exited);
            process.Start();
            string stResult = process.StandardOutput.ReadToEnd();
            string erResult = process.StandardError.ReadToEnd();
            process.WaitForExit();

"Physical Path" -> Application directory (bin) folder "File Asset Path" -> The directory in which I'm storing uploaded resources

Now, the strange part. During debugging, if I just copy the "arguments" variable value and execute it in CMD directly in "bin" folder, I get perfect results. Everything works. Here's the actual query generated:

ffmpeg -loop 1 -i "E:\Projects\Freelance\UP - Inspire3 (Karl)\AWS S3 Bucket Editing Routine\Code\AWSAPI\AWSAPI\bin\CoverImage_Video_Landscape_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.png" -f lavfi -i anullsrc -t 3 -c:v libx264 -c:a aac -b:a 160k -t 3 -pix_fmt yuv420p -vf scale=1920:964 -y "E:\Projects\Freelance\UP - Inspire3 (Karl)\AWS S3 Bucket Editing Routine\Code\AWSAPI\AWSAPI\bin\CoverImage_Video_Landscape_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts" & ffmpeg -i "E:\Projects\Freelance\UP - Inspire3 (Karl)\AWS S3 Bucket Editing Routine\Code\AWSAPI\AWSAPI\bin\Downloaded_Video_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.mp4" -c:v libx264 -c:a aac -b:a 160k -f mpegts "E:\Projects\Freelance\UP - Inspire3 (Karl)\AWS S3 Bucket Editing Routine\Code\AWSAPI\AWSAPI\bin\Downloaded_Video_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts" & ffmpeg -i "concat:CoverImage_Video_Landscape_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts|Downloaded_Video_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.ts" -c copy "E:\Projects\Freelance\UP - Inspire3 (Karl)\AWS S3 Bucket Editing Routine\Code\AWSAPI\AWSAPI\FileAssets\Video\Output\Downloaded_Video_fd8dbbb5-63c0-4ff0-b0c6-e6c3c8f590aa.mp4"

I have added "ffmpeg" keyword before every actual query otherwise I can't run it in CMD. Rest of the query is exactly the same

This query doesn't produce anything when running through C# process and throws the "concat" error I just mentioned above.

FYI, all files needed for conversion are present in the "bin" directory (temp files) and output file is supposed to be placed in another directory. I did that, because concat command apparently has issues with paths, so I just placed ffmpeg.exe along with all files needed directly in "bin" folder.

Also, the code explanation is that it's a 3-step process. It's supposed to convert a png image to ts, then another video to ts, and then combine the 2 and produce output.

Any help would be highly appreciated, thanks!!

Solat Ali
  • 39
  • 1
  • 6
  • This looks like you are avoiding the reason of the error: «I have added "ffmpeg" keyword before every actual query otherwise I can't run it in CMD». Look at [this answer](https://stackoverflow.com/a/15973631/2738151). Basically, it suggests to use cmd and pass the commands to execute. – Hernán Alarcón Aug 20 '20 at 22:36
  • Thanks for replying. I'm saying that when I run the "ffmpeg" process through C#, I'm directly invoking "ffmpeg.exe" file and that's why I don't have to write "ffmpeg" keyword. However, when I run it through CMD directly on my computer, then I have to write "ffmpeg" just to invoke it through CMD. Hope you get my point! – Solat Ali Aug 21 '20 at 03:23
  • The point is that you cannot use `&` and expect that `ffmpeg` understands it. `cmd` can understand it. Look at the answer I linked. – Hernán Alarcón Aug 21 '20 at 13:45

0 Answers0