I’d like to be able to use FFmpeg to convert a video file from within my C# program. I know I can just call a shell command, but is there a better way?
The issue with invoking a command via the shell, is I’m not sure you could do things like a progress bar, etc… or could you?
If there isn’t a way, can anyone suggest the best way to layout some framework for executing shell commands. Passing one big long string is very cumbersome atm.
You can easily implement a progress bar if running ffmpeg. The output of ffmpeg while running is something like:
And it is refreshed ~twice per second. You can parse that line and get the data you need to display the progress. When you run in the command line, you only see one line being updated all the time, but what ffmpeg does is to write the line followed by \r. That’s why you don’t see multiple lines. However, when using StreamReader.ReadLine() on the error output of the program, you get one line for every update.
Sample code to read the output follows. You would have to ignore any line that does not begins with ‘frame’, perhaps use BeginErrorReadLine()+ErrorDataReceived if you want reading lines to be asynchronous, etc., but you get the idea (I’ve actually tested it):