using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace H264Convert
{
class Ffmpeg
{
// Where FFMPEG should be
// This is also in Form1.cs
public string ffmpegLocation = @"C:\program files\ffmpeg\ffmpeg.exe";
// Create a new process
System.Diagnostics.Process proc
= new System.Diagnostics.Process();
// Function to actually envoke FFMPEG
public void runFFMPEG(string inputFile, string outputFile, string aspectRatio,
string dimensions, string bitRate, string passes, string videoTypeArg,
string audioFrequency, string audioBitRate, string deinterlace, string otherArgs, string audioCodec)
{
// See if the video to be output already exists
if (File.Exists(outputFile))
{
// and stop FFMPEG from starting
return;
}
// Create arguements from passed variables
string arguement = " -i \"" + inputFile + "\"" +
" -aspect " + aspectRatio +
" -pass " + passes +
" " + videoTypeArg +
" -b " + bitRate +
" -ar " + audioFrequency +
" -ab " + audioBitRate +
" -acodec " + audioCodec +
" -s " + dimensions +
" " + deinterlace +
" " + otherArgs +
" " + "-y" + // Overwrite
" \"" + outputFile + "\"";
// Stop proc raising events
proc.EnableRaisingEvents = false;
// Location of file to start (FFMPEG)
proc.StartInfo.FileName = ffmpegLocation;
// Arguements to pass to file
proc.StartInfo.Arguments = arguement;
// Use shell execute
proc.StartInfo.UseShellExecute = false;
// Don't show FFMPEG
proc.StartInfo.CreateNoWindow = false;
// Do not steal information from the FFMPEG window
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.RedirectStandardInput = false;
proc.StartInfo.RedirectStandardError = false;
// Start FFMPEG
proc.Start();
// Change processor priority from 'Normal' to 'Below Normal'
proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
// Don't do anything else until it is done
proc.WaitForExit();
// Once FFMPEG is finished it will close. Just be sure that it is
proc.Close();
// Exit out of function
return;
}
}
}