MP4 Encoding with Fast Start for Streaming using MP4Box

126 views
Skip to first unread message

Mike

unread,
Mar 9, 2011, 5:25:00 PM3/9/11
to mediasoftpro
First to let everyone know: I have the latest Media Handler Pro,
ffmpeg and MP4Box as of 3/9/2011

Using the below code issues are as follows:
Issue 1: when converting an .flv file to .mp4 it fails giving me
Error code 134 incorrect parameters error.

Issue 2: when converting a .mpg file it works, but I have not tested
the fast start yet. Also if I change the preset to ipod640 it fails -
and yes I did copy and paste the preset exactly not typos here.

issue 3: the file will not rename after encoding. It should rename to
meta.mp4, but instead it stays meta_temp.mp4 in the output directory.

issue 4: without the rename function working the last line of code
just deletes the file created so be aware of that.

I did e-mail support and they have been great so far. They have
a .flv file that I e-mailed to them and I am hoping they get it
working.

any help would be much appreciated.

Code below for reference:


protected void Button1_Click(object sender, EventArgs e)
{

//Encode for MP4 Streaming fast start
MediaHandler _mhandler = new MediaHandler();

//App path
string RootPath = Server.MapPath(Request.ApplicationPath);

//input output properties
_mhandler.FFMPEGPath = RootPath + "\\ffmpeg\\ffmpeg.exe";
_mhandler.InputPath = RootPath + "\\contents\\original";
_mhandler.OutputPath = RootPath + "\\contents\\output";

string PresetFilePath = RootPath + "\\ffmpeg\\presets\\libx264-
faster_firstpass.ffpreset";

//Original filename
_mhandler.FileName = "comm_test.mpg";

//Output settings
_mhandler.OutputFileName = "meta_temp"; // generate temp mp4
video in first step
_mhandler.OutputExtension = ".mp4";
_mhandler.Parameters = "-strict experimental -fpre " +
PresetFilePath + " -threads 0";
_mhandler.ACodec = "aac";
_mhandler.Audio_Bitrate = 160;
_mhandler.Width = 300;
_mhandler.Height = 220;
_mhandler.VCodec = "libx264";
_mhandler.Video_Bitrate = 450;
_mhandler.Force = "mp4";

VideoInfo info = _mhandler.Process();// start encoding mp4
video via process method

// Check for errors
if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " +
info.ErrorCode + " generated");
return;
}

// Set Meta Information using mp4box utility program.
_mhandler.MP4BoxPath = RootPath + "\\MP4Box\\MP4Box.exe"; //
set mp4box path

string encoded_mp4 = _mhandler.OutputFileName + ".mp4";
string temp_path = RootPath + "\\contents\\output\\" +
encoded_mp4; // set mp4 video complete path as encoded through step 1;

_mhandler.Parameters = "-isma -hint -add " + temp_path + ""; //
set mp4 box meta information parameters

string temp_filename = encoded_mp4; // optional store for
further processing

_mhandler.InputPath = RootPath + "\\contents\\output\\"; //
set input path where _temp.mp4 video stored.

_mhandler.OutputFileName = encoded_mp4.Replace("_temp.mp4",
".mp4"); // set final mp4 file name by removing _temp after setting
meta information.

// start generating final mp4 video with meta information.
_mhandler.Set_MP4_Buffering();

// delete temp mp4 video after processing
if (System.IO.File.Exists(_mhandler.OutputPath + "\\" +
temp_filename))
System.IO.File.Delete(_mhandler.OutputPath + "\\" +
temp_filename);




}
Reply all
Reply to author
Forward
0 new messages