Getting Started

Getting Started

ASP.NET Video Converter is a small utility component that can be used to convert any format videos to another format, and done other processing in real-time within your ASP.NET, .NET, .NET 5, ASP.NET Core, and related application.

It can be used in any application that runs on .NET Framework or .NET 5 or ASP.NET Core Runtimes.

FFMPEG Windows Build

ASP.NET Video Converter  uses FFmpeg open-source utility that you can easily download FFmpeg windows build and perform the following steps

  • Download and unzip Ffmpeg windows build from any reputed source
  • Copy and put your unzip open-source utility within your application e.g /encoder directory
  • Make sure you provide proper execute permission to /encoder directory or specific file to perform video processing smoothly.
  • Create directories for saving uploaded and published media files.
  • Make sure to give proper read/write permission to these directories.
Example Usage Code

e.g sample code will convert video file to audio file


var _mhandler = new MediaHandler();
var RootPath = Server.MapPath(Request.ApplicationPath);
// setup path that points ffmpeg.exe
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
// setup input / uploaded video directory path
_mhandler.InputPath = RootPath + "\\contents\\original";
// setup published video directory path
_mhandler.OutputPath = RootPath + "\\contents\\mp4";
// set uploaded / source video filename
_mhandler.FileName = "input.mp4";
// set out file extension
_mhandler.OutputExtension = ".mp3";
// set published filename without extension
_mhandler.OutputFileName = "output";
// setup ffmpeg parameters
_mhandler.Parameters = " -vn -ar 44100 -ac 2 -ab 320 -f mp3";
var info = _mhandler.Process();

More Examples

I: Change resolution of video files


var _mhandler = new MediaHandler();
var RootPath = Server.MapPath(Request.ApplicationPath);
// setup path that points ffmpeg.exe
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
// setup input / uploaded video directory path
_mhandler.InputPath = RootPath + "\\contents\\original";
// setup published video directory path
_mhandler.OutputPath = RootPath + "\\contents\\mp4";
// set uploaded / source video filename
_mhandler.FileName = "input.mp4";
// set out file extension
_mhandler.OutputExtension = ".mp4";
// set published filename without extension
_mhandler.OutputFileName = "output";
// setup ffmpeg parameters
_mhandler.Parameters = "-filter:v scale=1280:720 -c:a copy";
var info = _mhandler.Process();

ii: Compressing video files


var _mhandler = new MediaHandler();
var RootPath = Server.MapPath(Request.ApplicationPath);
// setup path that points ffmpeg.exe
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
// setup input / uploaded video directory path
_mhandler.InputPath = RootPath + "\\contents\\original";
// setup published video directory path
_mhandler.OutputPath = RootPath + "\\contents\\mp4";
// set uploaded / source video filename
_mhandler.FileName = "input.mp4";
// set out file extension
_mhandler.OutputExtension = ".mp4";
// set published filename without extension
_mhandler.OutputFileName = "output";
// setup ffmpeg parameters
_mhandler.Parameters = "-vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24";
var info = _mhandler.Process();

iii: Removing audio stream from a video file


_mhandler.Parameters = "-an";

iv:  Cropping videos


_mhandler.Parameters = "-filter:v "crop=w:h:x:y"";
Here.

  • w - Width of the rectangle that we want to crop from the source video.
  • h - Height of the rectangle.
  • x - the x coordinate of the rectangle that we want to crop from the source video.
  • y - the y coordinate of the rectangle.

v: Trim a media file using start and stop times


_mhandler.Parameters = "-ss 00:00:50 -codec copy -t 50"";

vi: Split audio/video files into multiple parts


_mhandler.Parameters = " -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy"";