FFmpeg ActiveX FAQ

How to add task after start ?

Back to Top

You can't add task when it is converting. But you do can add task when the convert is paused.

So, there are 3 steps to add task after start convert:

1, converter.Pause();

2, converter.AddTask(input file name, output file name);

3, converter.Resume();

Note that you must call start(n) n > 0 to pause and resume task(s).

The following codes are the sample with C#:

 mConverter = new CAVConverter();

//The first task

mConverter.OutputOptions.VideoBitrate = 2000000;

 mConverter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                                   "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

mConverter.Start(1);

//The second task

mConverter.Pause();

mConverter.OutputOptions.VideoBitrate = 2000000;

mConverter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                                   "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife2.mpg");

mConverter.Resume();

How to add watermark ?

Back to Top

Use OutputOptions.ExtOptions to add watermark.

 Note that the hook dll must be specified correctly.

 The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

// here we use ExtOptions to define vhook parameters

// outputOptions.ExtOptions usage: extent options for flexibility

// Format: name1=value1name2=value2...nameN=valueN

// name && value correspond to ffmpeg.exe's parameters

// e.g. "pix_fmt=yuv422paspect=16:9"

 // one or more vhooks can be defined in the same time.

// Official Video Hook: please refer to http://ffmpeg.mplayerhq.hu/hooks.html

// NOTICE: if vhook parameters(HookDLL or FileName) have SPACE characters,

 // the delimiter between vhook parameters must be set to '|'.

// this feature is an increment to original FFmpeg's vhook.

// WaterMark Video Hook comes from official ffmpeg

string hookDLL = "";

 string hookImg = "";

string delimiter = "";

 hookDLL = Application.StartupPath + "\\vhook\\watermark.dll";

hookImg = "E:\\Pictures\\test.bmp";

if ((hookDLL.IndexOf(' ') > 0) || (hookImg.IndexOf(' ') > 0))
    delimiter = "|"; //{Do not Localize}    
else
    delimiter = " ";

converter.OutputOptions.ExtOptions = converter.OutputOptions.ExtOptions +
    string.Format("vhook={0}{1}{2}{3}{4}{5}{6}{7}{8:D}\r\n",
        hookDLL, delimiter, "-f", delimiter, hookImg, delimiter, "-m", delimiter, checkBoxWaterMarkMode.Checked ? 1 : 0);

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

 converter.StartAndWait();

How to convert with H.264 ?

Back to Top

Use OutputOptions.VideoCodec and OutputOptions.VideoPreset to convert with H.264.

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

 converter.OutputOptions.VideoCodec = "libx264"; ////{Do not Localize}

converter.OutputOptions.VideoPreset = "libx264-default";

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
"C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mp4"); converter.StartAndWait();

How to crop video ?

Back to Top

Use OutputOptions.CropLeft, OutputOptions.CropTop, OutputOptions.CropRight, OutputOptions.CropBottom to crop video.

 The unit is pixel.

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

// crop size must be a multiple of 2

converter.OutputOptions.CropLeft = 200;

converter.OutputOptions.CropTop = 100;

converter.OutputOptions.CropRight = 200;

converter.OutputOptions.CropBottom = 100;

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to flip video ?

Back to Top

Use OutputOptions.VideoFilters to flip video.

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

 // **********Below code shows Video Filter usage*************

// libavfilter: please refer to http://svn.mplayerhq.hu/soc/libavfilter/README?view=co

// currently only several Video Filters are present.

// NOTICE: What we know about libavfilter is also very limited.

 // so you have to get help of it by yourself.

// vflip: Vertically Flip Video Frame

 if (!string.IsNullOrEmpty(converter.OutputOptions.VideoFilters))
{
    converter.OutputOptions.VideoFilters += ",vflip";
}
else
{
    converter.OutputOptions.VideoFilters = "vflip";
}

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

 converter.StartAndWait();

How to get media property ?

Back to Top

Use converter.AVPrope.FileInfoText to get the media information summary.

 Use converter.FileName to get the file name, converter.FileSize to get the file size and so on...

The following codes are the sample with C#:

if (comboBoxProperties.SelectedIndex == 0)//"File Information Summary",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileInfoText;
}
else if (comboBoxProperties.SelectedIndex == 1)//"File Name",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileName;
}
else if (comboBoxProperties.SelectedIndex == 2)//"Format Name"
{
    richTextBoxProperty.Text = mConverter.AVPrope.FormatName;
}
else if (comboBoxProperties.SelectedIndex == 3)//"Format Long Name"
{
    richTextBoxProperty.Text = mConverter.AVPrope.FormatLongName;
}
else if (comboBoxProperties.SelectedIndex == 4)//"File Size",
{
    richTextBoxProperty.Text = GetFileSizeFromBytes(mConverter.AVPrope.FileSize);
}
else if (comboBoxProperties.SelectedIndex == 5)//"Album",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Album;
}
else if (comboBoxProperties.SelectedIndex == 6)//"Author",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Author;
}
else if (comboBoxProperties.SelectedIndex == 7)//"Bitrate",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Bitrate.ToString() + "b/s";
}
else if (comboBoxProperties.SelectedIndex == 8)//"Comment",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Comment;
}
else if (comboBoxProperties.SelectedIndex == 9)//"Copyright",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Copyright;
}
else if (comboBoxProperties.SelectedIndex == 10)//"Duration",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Duration.ToString() + "us";
}
else if (comboBoxProperties.SelectedIndex == 11)//"Title",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Title;
}
else if (comboBoxProperties.SelectedIndex == 12)//"Track",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Track.ToString();
}
else if (comboBoxProperties.SelectedIndex == 13)//"Year",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FileStreamInfo.Year.ToString();
}
else if (comboBoxProperties.SelectedIndex == 14)//"Aspect Ratio",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.AspectRatio.ToString();
}
else if (comboBoxProperties.SelectedIndex == 15)//"Video Bitrate",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.Bitrate.ToString() + "b/s";
}
else if (comboBoxProperties.SelectedIndex == 16)//"Video Codec Name",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.CodecName;
}
else if (comboBoxProperties.SelectedIndex == 17)//"Frame Rate",
{
    richTextBoxProperty.Text = ((float)mConverter.AVPrope.FirstVideoStreamInfo.FrameRate.num /
                     mConverter.AVPrope.FirstVideoStreamInfo.FrameRate.den).ToString() +
                    "(" + mConverter.AVPrope.FirstVideoStreamInfo.FrameRate.num.ToString() + "/"
                    + mConverter.AVPrope.FirstVideoStreamInfo.FrameRate.den.ToString() + ")";
}
else if (comboBoxProperties.SelectedIndex == 18)//"Height",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.Height.ToString();
}
else if (comboBoxProperties.SelectedIndex == 19)//"Video Language",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.Language;
}
else if (comboBoxProperties.SelectedIndex == 20)//"Width",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstVideoStreamInfo.Width.ToString();
}
else if (comboBoxProperties.SelectedIndex == 21)//"Audio Bitrate",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstAudioStreamInfo.Bitrate.ToString() + "b/s";
}
else if (comboBoxProperties.SelectedIndex == 22)//"Channels",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstAudioStreamInfo.Channels.ToString();
}
else if (comboBoxProperties.SelectedIndex == 23)//"Audio Codec Name",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstAudioStreamInfo.CodecName;
}
else if (comboBoxProperties.SelectedIndex == 24)//"Audio Language",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstAudioStreamInfo.Language;
}
else if (comboBoxProperties.SelectedIndex == 25)//"Sample Rate",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstAudioStreamInfo.SampleRate.ToString() + "hz";
}
else if (comboBoxProperties.SelectedIndex == 26)//"Subtitle Codec Name",
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstSubtitleStreamInfo.CodecName;
}
else if (comboBoxProperties.SelectedIndex == 27)//"Subtitle Language"
{
    richTextBoxProperty.Text = mConverter.AVPrope.FirstSubtitleStreamInfo.Language;
}

How to get progress information ?

Back to Top

Use converter.ProgressInfo (or converter.get_ProgressInfo() in c#) to get the progress information.

Use converter.TerminateInfo (or converter.get_TerminateInfo() in C#) to get the terminate information.

The terminate information shows whether convert successfully or failed.

Please start a timer to call converter.ProgressInfo and converter.TerminateInfo periodically. (Interval 500ms is recommended)

If you are using the AVEditOcx control, just use the event callback.

The following codes are the sample with C#:

mConverter = new CAVConverter();

mConverter.OutputOptions.VideoBitrate = 2000000;

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

 mConverter.Start(1);

//Now start the timer

//In the timer call back function, do the following thing:

CTProgressInfo progressInfo = mConverter.get_ProgressInfo(0);

 if (progressInfo.TotalDuration > 0)
{
    //Show the progress informatino in the UI
}
CTTerminateInfo terminateInfo = mConverter.get_TerminateInfo(0);
if (terminateInfo.Finished != 0 && terminateInfo.Exception == 0)
{
    //Convert successfully.
}

How to get thumbnail?

Back to Top

Use converter.AVPrope.Decode(-1) to decode the next frame and converter.AVPrope.CurrentPicture to get the thumbnail picture.

Use converter.AVPrope.SaveCurrentFrame(fileName) to save current frame to the file fileName.

The following codes are the sample with C#:

//Load the file

converter.AVPrope.LoadFile(fileName, "");

//Decode the frame converter.AVPrope.Decode(-1);

//Get the thumbnail picture. It is a IPictureDisp object, do something as you need.

 thumbnail = converter.AVPrope.CurrentPicture

//Save current frame to file fileName

converter.AVPrope.SaveCurrentFrame(fileName);

How to mix the video with image?

Back to Top

Use OutputOptions.ExtOptions to mix the video with image.

Note that the path of the hook dll must be specified correctly.

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

 // here we use ExtOptions to define vhook parameters

// outputOptions.ExtOptions usage: extent options for flexibility

 // Format: name1=value1name2=value2...nameN=valueN

 // name && value correspond to ffmpeg.exe's parameters

 // e.g. "pix_fmt=yuv422paspect=16:9"

 // one or more vhooks can be defined in the same time.

// Official Video Hook: please refer to http://ffmpeg.mplayerhq.hu/hooks.html

// NOTICE: if vhook parameters(HookDLL or FileName) have SPACE characters,

 // the delimiter between vhook parameters must be set to '|'.

// this feature is an increment to original FFmpeg's vhook.

// Imlib2 Video Hook comes from official ffmpegs

// Imlib2 Hook (Image usage) string hookDLL = Application.StartupPath + "\\vhook\\imlib2.dll";

//Important: the hook path must be set correctly.

string hookImg = "E:\\Pictures\\test.gif";

 string delimiter = "";

 string x = "";

string y = "";

if ((hookDLL.IndexOf(' ') > 0) || (hookImg.IndexOf(' ') > 0))
    delimiter = "|"; ////{Do not Localize
}
else
    delimiter = " ";

if (checkBoxDancing.Checked) //The image is dancing
{
    x = "(W-w)*(0.5+0.5*sin(N/47*PI))";
    y = "(H-h)*(0.5+0.5*cos(N/97*PI))";
}
else
{
    x = "W-w";
    y = "H-h";
}

converter.OutputOptions.ExtOptions = converter.OutputOptions.ExtOptions +
string.Format("vhook={0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}\r\n",
    hookDLL, delimiter, "-i", delimiter, hookImg, delimiter, "-x", delimiter, x, delimiter, "-y", delimiter, y);

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to mix video with text?

Back to Top

Use OutputOptions.ExtOptions to mix the video with text.

 Note that the path of the hook dll must be specified correctly.

 The following codes are the sample with C#:

 CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

 // **********Below code shows Video Hook usage*************

// here we use ExtOptions to define vhook parameters

// outputOptions.ExtOptions usage: extent options for flexibility

// Format: name1=value1name2=value2...nameN=valueN

// name && value correspond to ffmpeg.exe's parameters

// e.g. "pix_fmt=yuv422paspect=16:9"

// one or more vhooks can be defined in the same time.

// Official Video Hook: please refer to http://ffmpeg.mplayerhq.hu/hooks.html

 // NOTICE: if vhook parameters(HookDLL or FileName) have SPACE characters,

// the delimiter between vhook parameters must be set to '|'.

// this feature is an increment to original FFmpeg's vhook.

// Imlib2 Hook (Text usage)

string hookDLL = "";

string delimiter = "";

string hookText = "CAVEditLib";

string x = "";

 string y = "";

 hookDLL = Application.StartupPath + "\\vhook\\imlib2.dll";

if (hookDLL.IndexOf(' ') > 0)
delimiter = "|"; ////{Do not Localize}
else
delimiter = " ";

if (checkBoxScrolling.Checked) //The text is scrolling
{
    x = "10";
    // Y = 'abs(H-25-1.0*N)';
    y = "(H-25)*(0.5+0.50*sin(N/97*PI))";
}
else
{
    x = "10"; y = "10";
}

converter.OutputOptions.ExtOptions = converter.OutputOptions.ExtOptions +
string.Format("vhook={0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}{19}{20}{21}{22}{23}    {24}{25}{26}{27}{28}\r\n",
    hookDLL, delimiter, "-R", delimiter, "255", delimiter, "-G", delimiter, "255",
    delimiter, "-B", delimiter, "255", delimiter, "-F", delimiter, "Tahoma.ttf/16",
    delimiter, //{Imlib2 Hook need fontfile to draw text} "-t", delimiter, hookText,
    delimiter, "-x", delimiter, x, delimiter, "-y", delimiter, y);

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to pad video?

Back to Top

Use OutputOptions.PadLeft, OutputOptions.PadTop, OutputOptions.PadRight, OutputOptions.PadBottom to pad the video.

The following codes are the sample code with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

converter.OutputOptions.PadLeft = 160;

converter.OutputOptions.PadTop = 90;

 converter.OutputOptions.PadRight = 160;

converter.OutputOptions.PadBottom = 90;

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to rotate video?

Back to Top

Use OutputOptions.VideoFilters to rotate video. The format is like "rotate=45". The 45 is the rotate degree.

The following codes are the sample with C#:

 CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

if (!string.IsNullOrEmpty(converter.OutputOptions.VideoFilters))
    converter.OutputOptions.VideoFilters = converter.OutputOptions.VideoFilters + ",rotate=45"; //{Do not Localize}
else
    converter.OutputOptions.VideoFilters = "rotate=45"; //{Do not Localize}

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to scale video?

Back to Top

Use OutputOptions.VideoFilters to scale video. The format is like "scale=640:480".

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

if (!string.IsNullOrEmpty(converter.OutputOptions.VideoFilters))
    converter.OutputOptions.VideoFilters = converter.OutputOptions.VideoFilters + ",scale=640:480"; //{Do not Localize}
else
    converter.OutputOptions.VideoFilters = "scale=640:480"; //{Do not Localize}

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to set aspect ratio?

Back to Top

OutputOptions.FrameAspectRatio is used to set aspect ratio, which is like "16:9" "4:3" and so on.

 The following codes are sample with C#:

 CAVConverter converter = new CAVConverter();

 converter.OutputOptions.VideoBitrate = 2000000;

 converter.OutputOptions.FrameAspectRatio = "16:9"; //Set output Aspect Ratio ("4:3" "16:9" ...)

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to set PTS?

Back to Top

Use OutputOptions.VideoFilters to set PTS.

The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.OutputOptions.VideoBitrate = 2000000;

/* # A few usage examples follow, usable too as test scenarios.

# Start counting PTS from zero ffmpeg -i input.avi -vfilters setpts=PTS-STARTPTS output.avi

# Fast motion ffmpeg -i input.avi -vfilters setpts=0.5*PTS output.avi

 # Fixed rate 25 fps ffmpeg -i input.avi -vfilters setpts=N*AVTB/25 output.avi

 # Fixed rate 25 fps with some jitter ffmpeg -i input.avi -vfilters 'setpts=AVTB/25*(N+0.05*sin(N*2*PI/25))' output.avi */

// setpts: Set PTS of Video Frame

 if (!string.IsNullOrEmpty(converter.OutputOptions.VideoFilters))
    converter.OutputOptions.VideoFilters = converter.OutputOptions.VideoFilters + ",setpts=0.5*PTS"; //{Do not Localize}
else
    converter.OutputOptions.VideoFilters = "setpts=0.5*PTS"; //{Do not Localize}

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to split video?

Back to Top

Use InputOptions.TimeStart and OutputOptions.TimeLength to split video.

 The following codes are the sample with C#:

CAVConverter converter = new CAVConverter();

converter.InputOptions.TimeStart = 15000000; //Start time to trim, unit is um(micro second)

converter.OutputOptions.TimeLength = 3000000; //Time length to trim, unit is um(micro second)

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();

How to use ExtOptions?

Back to Top

The format of ExtOptions is as follows:

Format: name1=value1name2=value2...nameN=valueN name && value correspond to ffmpeg.exe's parameters

e.g. "pix_fmt=yuv422paspect=16:9"

The following codes are the sample with C#:

 CAVConverter converter = new CAVConverter();

// outputOptions.ExtOptions usage: extent options for flexibility

// Format: name1=value1name2=value2...nameN=valueN // name && value correspond to ffmpeg.exe's parameters

 // e.g. "pix_fmt=yuv422paspect=16:9"

 converter.OutputOptions.ExtOptions = "b=2000000\r\naspect=16:9";

converter.AddTask("C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv",
                              "C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.mpg");

converter.StartAndWait();