Home > Developer Section > Videos & Audio > Video Encoder > Multi Level and Multi Format Video Publishing, Grab Thumbs and Cloud Storage

Sample Code (Multi Level and Multi Format Video Publishing, Grab Thumbs and Cloud Storage)

Below example will publish multiple videos from source videos in youtube style and grab 15 thumbs from source video. Multi level and format video including

  • 240p FLV Encoding (itag: 0)
  • 360p FLV Encoding (itag: 1)
  • 480p FLV Encoding (itag: 2)
  • 360p MP4 Encoding (itag: 5)
  • 480p MP4 Encoding (itag: 6)
  • 720 MP4 HD Encoding (itag: 7)
  • 360p WebM Encoding (itag: 10)
  • 480p WebM Encoding (itag: 11)
  • MP3 Audio Encoding (itag: 14)

And store all published videos, audio files and thumbs on cloud storage. Note: You must provide cloud storage setting information (access key, secrete key, bucket info etc) in order to successfully store contents on cloud storage.

We recommend not to publish multi level or format videos if necessary. Try to publish videos in format which you need.

MHPEncoder encoder = new MHPEncoder();
string RootPath = Server.MapPath(Request.ApplicationPath);
encoder.FfmpegPath = RootPath + "\\ffmpeg\\ffmpeg.exe"; // path of ffmpeg
encoder.FlvToolPath = RootPath + "\\flvtool\\flvtool2.exe"; // path of flvtool, use in case of setting meta information to flv videos
encoder.Mp4BoxPath =  RootPath + "\\mp4box\\MP4Box.exe"; // path of mp4box, to be used for setting meta information to mp4 video
encoder.SourcePath = RootPath + "\\contents\\default"; // path of source video directory
encoder.SourceFileName = filename; // source video filename
encoder.PublishedPath = RootPath + "\\contents\\videos"; // directory path of published videos
encoder.EnableCloudStorage = true; // disable cloud storage
ArrayList itags= new ArrayList();
itags.Add("0"); // publish 240p flv video (more detail at encoder settings section
itags.Add("1"); // publish 360p flv video (more detail at encoder settings section
itags.Add("2"); // publish 480p flv video (more detail at encoder settings section
itags.Add("5"); // publish 360p mp4 video (more detail at encoder settings section
itags.Add("6"); // publish 480 mp4 video (more detail at encoder settings section
itags.Add("7"); // publish 720p mp4 video (more detail at encoder settings section
itags.Add("10"); // publish 360p webm video (more detail at encoder settings section
itags.Add("11"); // publish 480p webm video (more detail at encoder settings section
itags.Add("14"); // publish mp3 audio file (more detail at encoder settings section
encoder.ThumbsDirectory = RootPath + "\\contents\\thumbs"; // directory path of published video thumbs
encoder.TotalThumbs = 15;// grab fifteen thumbs from start to end of video
encoder.GrabThumbs = true; // disable grabbing thumbs from video
encoder.DeleteSource = true; // delete original video after completion
Video_Information vinfo = encoder.Process(); // start processing
if (vinfo.ErrorCode > 0)
{
    // Encoding Failed
    // Encoding Failure Detail in vinfo.ErrorDescription
}
// Retrive Information
string PublishedVideoName = vinfo.FLVVideoName;
string OriginalVideoName = vinfo.OriginalVideoName;
string ThumbFileName = vinfo.ThumbFileName; //return middle thumb filename
string Duration = vinfo.Duration; // length of video
string Duration_Sec = vinfo.Duration_Sec; //length of video in seconds
string isEnabled = vinfo.isEnabled; // to make sure video published and thumbs grabbed successfully.