Last active
March 1, 2020 15:12
-
-
Save Microncode/123fbf720ccfb8990d28463bb6219c0a to your computer and use it in GitHub Desktop.
Here is a snap example of using the CSVideoConverter using C#:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a new instance of the library with the path of the ffmpeg libraries: | |
_CSVideoConverter = new CSVideoConverter.VideoConverter(@"../../../libs/ffmpeg/x86/bin", | |
"UserName", "RegKey"); | |
//Set the source file | |
_CSVideoConverter.FileSource = txtSource.Text; | |
//Set the destination file | |
_CSVideoConverter.FileDestination = txtDestination.Text; | |
//Set the video and the audio properties of the destination media file. | |
//Leave one or more properties empty will make the ffmpeg to use the | |
//default settings of the property. | |
//Set the video codec: | |
_CSVideoConverter.VideoCodec = txtVideoCodec.Text; | |
//Set the bitrate (add K for kilobytes) | |
_CSVideoConverter.VideoBitrate = txtVideoBitrate.Text; | |
//Set the frames per seconds | |
_CSVideoConverter.VideoFPS = txtFPS.Text; | |
//Set the resolution | |
_CSVideoConverter.VideoResolutionX = txtVideoResolutionX.Text; | |
_CSVideoConverter.VideoResolutionY = txtVideoResolutionY.Text; | |
//Set the Audio properties | |
_CSVideoConverter.AudioBitrate = txtAudioBitrate.Text; | |
_CSVideoConverter.AudioSamplerate = txtAudioSampeRate.Text; | |
_CSVideoConverter.AudioChannels = txtAudioChannels.Text; | |
//Set the length to convert. | |
//From TimeSpan value. If 0 the library will convert the media file from the start. | |
TimeSpan from_time = new TimeSpan(timeFrom.Value.Hour, timeFrom.Value.Minute, timeFrom.Value.Second); | |
//Length to convert of TimeSpan value. If 0 the library will convert the media until the end. | |
TimeSpan length_time = new TimeSpan(timeLength.Value.Hour, timeLength.Value.Minute, timeLength.Value.Second); | |
//Set values | |
_CSVideoConverter.FromTime = from_time; | |
_CSVideoConverter.LengthTime = length_time; | |
//Set the ID3 tags | |
//Create an instance of ID3Tags | |
ID3Tags iD3Tags = new ID3Tags(); | |
//Set the ID3 tags values | |
iD3Tags.Title = txtID3Title.Text; | |
iD3Tags.Comment = txtID3Comment.Text; | |
iD3Tags.Album = txtID3Album.Text; | |
iD3Tags.Artist = txtID3Artist.Text; | |
iD3Tags.Date = txtID3Date.Text; | |
//Set the ID3 tags | |
_CSVideoConverter.SetID3Tags(iD3Tags); | |
//Additional | |
//You can add an additional arguments: | |
//_CSVideoConverter.ArgsAdditional = "-vtag xvid -more arg1"; | |
//Or if you want to set your own arguments: | |
//_CSVideoConverter.ArgsDirect = "Your_own_arguments"; | |
//You can get the final arguments after setting the library properties: | |
//string cmd = _CSVideoConverter.GetArgs(); | |
//Debug.WriteLine(cmd); | |
//Events | |
//On start event | |
_CSVideoConverter.OperationStart += (o) => | |
{ | |
Debug.WriteLine("Start"); | |
}; | |
//On output | |
_CSVideoConverter.OperationOutput += (o, s) => | |
{ | |
Debug.WriteLine(s); | |
}; | |
//On progress event | |
_CSVideoConverter.OperationProgress += (o, Precents, ConvertingProperties) => | |
{ | |
this.Invoke(new Action(() => | |
{ | |
try | |
{ | |
//Display the converting operation parameters | |
lblStatus.Text = "Frame:" + ConvertingProperties.Frame | |
+ " Size:" + ConvertingProperties.Size | |
+ " FPS:" + ConvertingProperties.Fps | |
+ " Time:" + ConvertingProperties.Time | |
+ " Bitrate:" + ConvertingProperties.Bitrate | |
+ " Speed:" + ConvertingProperties.Speed; | |
//Display the percents of the converting operation | |
progressBar1.Value = Precents; | |
} | |
catch { } | |
})); | |
}; | |
//Done | |
_CSVideoConverter.OperationDone += (o, Aborted) => | |
{ | |
//Aborted = true if the user was aborted the operation | |
if (Aborted) | |
{ | |
Debug.WriteLine("Done (Aborted)."); | |
} | |
else | |
{ | |
Debug.WriteLine("Done"); | |
} | |
}; | |
//Closed | |
_CSVideoConverter.OperationClosed += (o) => | |
{ | |
Debug.WriteLine("Closed"); | |
}; | |
//Start the converting operation | |
_CSVideoConverter.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment