A long time ago I had to find a reliable library for converting audio/video. There were some good options but I thought it best to just use FFmpeg. Of course, using the libraries themselves with bindings for C# would be even better (as the file size would decrease significantly), but that’s not what is done here.
I compressed FFmpeg and embedded it as a resource and when a new instance of the FFmpegEngine class is created, it’s extracted and decompressed in a temporary folder. All the contents are deleted when that object is disposed.
I remember there was another library that did the same thing but I remember not liking the complexity of the library. This library is FAR from complex, there are only two functions.
Here is example usage.
using FFmpeg.NET;
using System.IO;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
// Some arbitrary directory with files in it
string dir = @"C:\Users\Matthew\Desktop\Temp";
// Using statements take care of garbage collection, otherwise make sure you call Dispose()
using (var engine = new FFmpegEngine())
{
foreach (var file in Directory.GetFiles(dir))
{
if (!file.EndsWith(".mp3"))
continue;
string input = file;
string output = file.Replace(".mp3", "_new.mp3");
string parameters = "-ab 192k";
// This just downgrades MP3 files to 192 kbps
engine.Convert(input, output, parameters);
}
}
}
}
}
It’s quite simple, although it’s as powerful as is your knowledge of different FFmpeg commands.