Split Video in small clips

ASP.NET Media Handler Pro version 4.0 or later include feature to split and encode video in multiple clips using one step of coding.

Media Handler Pro 5.0 or later has improved script for spliting video in small clips. It can split videos upto 20 times faster than older script. for sample code visit below section.

You can split video in small clips using two approaches.

  • Split video using specified length of video and publish every clip in any other format.
  • Split video using specified length of video and no of clips and encode every clip to any other format.

Sample Code: C#, Media Handler Pro ver 5.0

Sample code that can be used to split video in small clips using Media Handler Pro ver 5.0.

MediaHandler _mhandler = new MediaHandler();

string RootPath = Server.MapPath(Request.ApplicationPath);

// set required parameters

_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\videos";
_mhandler.OutputPath = RootPath + "\\contents\\splitvideos";

// set other parameters
_mhandler.FileName = "FullVideo.avi";
_mhandler.OutputFileName = "split_video"; // required
_mhandler.OutputExtension = ".avi"; // required
_mhandler.Width = 320;
_mhandler.Height = 240;

// set paremters related to output video type. it is different for 3gp video, mp4 video, avi video etc.
_mhandler.TargetFileType = "pal-vcd";

// split video parameters

int length_of_video = 20; // in seconds;
int total_clips = 10;
//VideoInfo info = _mhandler.Split_Video(20);
VideoInfo info = _mhandler.Split_Video(length_of_video,total_clips);
if (info.ErrorCode > 0)
{
Response.Write("Error occured: Error Code: " + info.ErrorCode + "<br />Error Message: " + info.ErrorMessage);
return;
}

// retrive video information from VideoInfo object info. more detail.

 

Sample code: C#

Sample code for splitting video in small clips using c#.

MediaHandler _mhandler = new MediaHandler();

string RootPath = Server.MapPath(Request.ApplicationPath);

// set required parameters

_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\videos";
_mhandler.OutputPath = RootPath + "\\contents\\splitvideos";

// video name to be split in small clips
_mhandler.FileName = "sample.mp4";

// start spliting video in six equal parts.

VideoInfo info = _mhandler.Split_Video(6, 30, true);
// true represent auto_time, which means clip duration automatically setup with duration of total video / no of clips.
if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated");
return;
}

// retrive video information from VideoInfo object info. more detail.

 

©2007 - 2010, MediaSoft Pro Inc  | Site Map |  Privacy Policy