Note all sample codes and examples available here works on Media Handler Pro version 2.5 or older. For sample codes about newer version of Media Handler Pro visit documentation section.
Below are some vb.net sample codes for encoding and publishing videos from one format to another format, especially to Flash FLV format.
You can use Media Handler Pro in your VB.NET applications to encode or publish videos to different formats, grab thumbnails from videos, extract audio from videos, post watermark on videos, split videos in many clips and other processings.
'After uploading video
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Set path of source video directory, path where original video exist //'
Dim InputPath As String = RootPath & "/Contents/Default"
'Set path of destination video directory, path where generated, encoded video will be store
Dim OutputPath As String = RootPath & "/Contents/FLV"
'Set path of image directory, path where generated thumbnail image will be store
Dim ThumbPath As String = RootPath & "/Contents/Thumbs"
' Call Convert_Media function of Media_handler class to convert selected video to flv format
' Note sample available here written according to full version of component, free version slightly have different return string than full version. please view product documentation for more help.
' Method No 1
Dim fullstring As String = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 320, 240, 360, 25, 32, 22050, "0", True)
' this function return flv video name in free version and many outputs in the form of string 'separated by comma in full version. e.g str = "FileName:04db71f6-a.flv,Duration: 00:00:29.8, 'start: 0.000000,size: 176x144,SamplingRate: 44100 Hz"
'Method No 2
Dim fullstring As String = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 360, 25, 32, 22050, "0", True)
' Method No 3
Dim fullstring As String = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 32, 44100, "0", True) Recommended for highest quality flv video
' Method No 4
Dim fullstring As String = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 32, 44100, "0", True) Recommended for highest quality flv video
' Method No 5
Dim fullstring As String = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 360, 32, 22050, "0", True)
'After converting video to flv format or video is already in flv format
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set flvtool path
Dim _flvtoolpath As String = HttpContext.Current.Server.MapPath("~/flvtool/flvtool2.exe")
' Set path of source video directory, path where original video exist //'
Dim Path As String = RootPath & "/Contents/FLV"
' Call Set_Buffering function to set meta-information to flv video
_mediahandler.Set_Buffering(outfile, _flvtoolpath, Path)
'After uploading video and successfully converting to flv format
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Set path of source video directory, path where original video exist //'
Dim InputPath As String = RootPath & "/Contents/Default"
'Set path of destination video directory, path where generated, encoded video will be store
Dim OutputPath As String = RootPath & "/Contents/FLV"
'Set path of image directory, path where generated thumbnail image will be store
Dim ThumbPath As String = RootPath & "/Contents/Thumbs"
' Call Grab_Image function of Media_handler class to capture thumbnail from video
Dim image_name As String = _mediahandler.Grab_Image(outfile, _ffmpegpath, OutputPath, ThumbPath, "00:00:03", "png", 110, 90)
' Where image_name is the name of thumbnail that is captured and stored in thumbpath directory.
' For capturing multiple thumbnails in a sequence use.
Dim multiplethubms As String = _mediahandler.Grab_Multiple_Image(outfile, _ffmpegpath, InputPath, OutputPath, 4, "00:00:02", "jpg", 110, 90)
'where 4 shows number of frames or thumbnails to be capture.
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Set path of source video directory, path where original video exist //'
Dim InputPath As String = RootPath & "/Contents/Default"
'Set path of destination video directory, path where generated, encoded video will be store
Dim OutputPath As String = RootPath & "/Contents/MPEG"
' Call Convert_Media_To_MPEG function of Media_handler class to convert video to mpg format.
Dim mpg_video As String = _mediahandler.Convert_Media_To_MPEG(outfile, _ffmpegpath, InputPath, OutputPath)
'where mpg_video is the name of mpg video that is generated and stored in mpg folder.
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Set path of source video directory, path where original video exist //'
Dim InputPath As String = RootPath & "/Contents/Default"
'Set path of destination video directory, path where generated, encoded video will be store
Dim OutputPath As String = RootPath & "/Contents/AVI"
' Call Convert_Media_To_AVI function of Media_handler class to convert video to avi format.
Dim avi_video As String = _mediahandler.Convert_Media_To_AVI(outfile, _ffmpegpath, InputPath, OutputPath)
'where avi_video is the name of avi video that is generated and stored in avi folder.
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Set path of source video directory, path where original video exist //'
Dim InputPath As String = RootPath & "/Contents/Default"
'Set path of destination video directory, path where generated, encoded video will be store
Dim OutputPath As String = RootPath & "/Contents/3gp"
' Call Convert_Media_To_3gp function of Media_handler class to convert video to avi format.
Dim 3gp_video As String = _mediahandler.Convert_Media_To_3gp(outfile, _ffmpegpath, InputPath, OutputPath)
'where 3gp_video is the name of 3gp video that is generated and stored in 3gpfolder.
'Create object of Media_handler class
Dim _mediahandler As New Media_handler()
' Set root path of web application
Dim RootPath As String = Server.MapPath(Request.ApplicationPath)
' Set ffmpeg.exe path
Dim _ffmpegpath As String = HttpContext.Current.Server.MapPath ("~/ffmpeg/ffmpeg.exe")
' Call Execute_FFMPEG function of Media_handler class to execute custom ffmpeg commands according to your own choice.
_mediahandler.Execute_FFMPEG(_ffmpegpath, InputPath, OutputPath, "-i c:\\test.avi -vcodec mp3 c:\\test.flv")