Beispiel #1
0
        public ProcessedVideo ProcessVideo(VideoProcessingInformation videoInformation, SystemConfiguration systemConfiguration, UserInfo userInfo, bool isFileUpload = false)
        {
            if (!isFileUpload)
            {
                // Check if input is an http url
                #region Preparation
                ProcessedVideo   videoInfo = new ProcessedVideo();
                ProcessStartInfo startInfo = new ProcessStartInfo(systemConfiguration.VideoProcessorLocation);
                FFProbe          fFProbe   = new FFProbe();
                bool             isHttp    = Validator.IsHttp(videoInformation.VideoLocations.VideoLocation);
                string           ID        = userInfo.SessionID;

                #region Working directories
                string temporaryWorkingDirectory      = string.Empty;
                string temporaryVideoDirectory        = systemConfiguration.TemporaryVideoSaveLocation;
                string processedVideoSaveLocation     = systemConfiguration.ProcessedVideoSaveLocation;
                string networkProcessedVideoDirectory = string.Empty;
                #endregion Working directories

                #endregion Preparation

                #region Working directory setup

                #region Temporary directory
                // Setting up working directory
                if (temporaryVideoDirectory.EndsWith("\\"))
                {
                    temporaryWorkingDirectory = temporaryVideoDirectory + ID;
                }
                else
                {
                    temporaryWorkingDirectory = temporaryVideoDirectory + "\\" + ID;
                }

                // Check for directory
                if (!Directory.Exists(temporaryWorkingDirectory))
                {
                    Directory.CreateDirectory(temporaryWorkingDirectory);
                }
                #endregion Temporary directory

                #region Processed directory
                string processedVideoDirectory = string.Empty;
                if (videoInformation.VideoLocations.videoSaveLocation == "default")
                {
                    throw new NotImplementedException("Custom path is not yet supported.");
                    if (videoInformation.VideoLocations.videoSaveLocation.EndsWith("\\"))
                    {
                        processedVideoDirectory = videoInformation.VideoLocations.videoSaveLocation + ID;
                    }
                    else
                    {
                        processedVideoDirectory = videoInformation.VideoLocations.videoSaveLocation + "\\" + ID;
                    }
                    //Check for directory
                    if (!Directory.Exists(processedVideoDirectory))
                    {
                        Directory.CreateDirectory(processedVideoDirectory);
                    }
                }
                else
                {
                    if (processedVideoSaveLocation.EndsWith("\\"))
                    {
                        processedVideoDirectory = processedVideoSaveLocation + ID;
                    }
                    else
                    {
                        processedVideoDirectory = processedVideoSaveLocation + "\\" + ID;
                    }

                    //Check for directory
                    if (!Directory.Exists(processedVideoDirectory))
                    {
                        Directory.CreateDirectory(processedVideoDirectory);
                    }
                }

                #endregion Processed directory

                #region Network processed directory

                if (!Directory.Exists(processedVideoDirectory))
                {
                    throw new Exception("Cannot create network folder if local folder isn't available.");
                }
                if (videoInformation.VideoLocations.videoNetworkSaveLocation.EndsWith("/"))
                {
                    networkProcessedVideoDirectory = videoInformation.VideoLocations.videoNetworkSaveLocation + ID + "/";
                }
                else
                {
                    networkProcessedVideoDirectory = videoInformation.VideoLocations.videoNetworkSaveLocation + "/" + ID + "/";
                }
                #endregion Network processed directory

                #endregion Working directory setup

                // Check video configurations
                #region  Video settings
                int videoHeight;
                if (videoInformation.VideoSetting.processedVideoResolution == Resolution.Other)
                {
                    videoHeight = videoInformation.VideoSetting.height;
                }
                else if (videoInformation.VideoSetting.processedVideoResolution == Resolution.Original)
                {
                    videoHeight = -1;
                }
                else
                {
                    videoHeight = (int)videoInformation.VideoSetting.processedVideoResolution;
                }
                //int videoWidth = configurations.VideoWidth;
                //bool scale = configurations.scale;

                #endregion Video settings

                if (isHttp)
                {
                    #region File name processing

                    #region Get filename from URL
                    string[] URLParts     = videoInformation.VideoLocations.VideoLocation.Split('?');
                    string   resultURL    = string.Empty;
                    string   tempFileName = string.Empty;
                    string   tempFileNameWithoutExtension = string.Empty;
                    foreach (var text in URLParts)
                    {
                        if (text.Contains("http://") || text.Contains("https://"))
                        {
                            if (text.Contains("?"))
                            {
                                resultURL = text.Trim('?');
                            }
                            else
                            {
                                resultURL = text;
                            }
                            break;
                        }
                    }
                    tempFileName = Path.GetFileName(resultURL).Replace("%20", " ");
                    tempFileNameWithoutExtension = Path.GetFileNameWithoutExtension(resultURL).Replace("%20", " ");

                    #endregion Get filename from URL

                    #region Get file extension
                    string fileNameExtension = Path.GetExtension(tempFileName);
                    #endregion Get file extension

                    #region Filename without extension to Base64 string

                    /*
                     * The file name will be converted to base64 string to remove space
                     * and to be able to recover the original file name later
                     */
                    byte[] tempFileNameInBytes = Encoding.UTF8.GetBytes(tempFileName);
                    byte[] tempFileNameWithoutExtensionInBytes = Encoding.UTF8.GetBytes(tempFileNameWithoutExtension);

                    string localFileName = Convert.ToBase64String(tempFileNameInBytes) + fileNameExtension;
                    string localFileNameWithoutExtension = Convert.ToBase64String(tempFileNameWithoutExtensionInBytes) + fileNameExtension;
                    #endregion Filename without extension to Base64 string

                    #endregion File name processing

                    #region Working directory setup (second phase)

                    #region Temporary download location setup

                    string temporaryDownloadLocation = string.Empty;
                    if (temporaryWorkingDirectory.EndsWith("\\"))
                    {
                        temporaryDownloadLocation = temporaryWorkingDirectory + localFileName;
                    }
                    else
                    {
                        temporaryDownloadLocation = temporaryWorkingDirectory + "\\" + localFileName;
                    }
                    #endregion Temporary download location setup

                    #region Local processed directory (second phase)
                    if (processedVideoDirectory.EndsWith("\\"))
                    {
                        processedVideoDirectory += localFileNameWithoutExtension;
                    }
                    else
                    {
                        processedVideoDirectory += "\\" + localFileNameWithoutExtension;
                    }

                    if (!Directory.Exists(processedVideoDirectory))
                    {
                        Directory.CreateDirectory(processedVideoDirectory);
                    }
                    #endregion Local processed directory (second phase)

                    #region Network processed directory (second phase)
                    if (networkProcessedVideoDirectory.EndsWith("/"))
                    {
                        networkProcessedVideoDirectory += localFileNameWithoutExtension;
                    }
                    else
                    {
                        networkProcessedVideoDirectory += "/" + localFileNameWithoutExtension;
                    }
                    #endregion Network processed directory (second phase)

                    #endregion Working directory download location (Second phase)

                    #region File download
                    try
                    {
                        using (var client = new WebClient())
                        {
                            client.DownloadFile(videoInformation.VideoLocations.VideoLocation, temporaryDownloadLocation);
                        }
                    }
                    catch (Exception err)
                    {
                        videoInfo.result = Result.Fail;
                        return(videoInfo);
                    }

                    #endregion File download

                    #region VideoProcessing.exe argument configurations
                    string arguments = "GetFrames ";

                    #region Temporary location (Source file)
                    if (temporaryDownloadLocation.Contains("\""))
                    {
                        arguments += temporaryDownloadLocation + " ";
                    }
                    else
                    {
                        arguments += "\"" + temporaryDownloadLocation + "\" ";
                    }
                    #endregion Temporary location (Source file)

                    #region Target directory
                    if (processedVideoDirectory.Contains("\""))
                    {
                        arguments += processedVideoDirectory + " ";
                    }
                    else
                    {
                        arguments += "\"" + processedVideoDirectory + "\"";
                    }
                    #endregion Target directory

                    #region Scaling
                    if (videoHeight > 0)
                    {
                        if (videoHeight > 0)
                        {
                            arguments += " height=" + videoHeight;
                        }
                        else
                        {
                            arguments += " height=-1";
                        }
                    }
                    #endregion Scaling

                    #region Request delete original
                    //if (deleteTemporaryVideoWhenFinished)
                    //{
                    //    // += " request_delete=true";
                    //}
                    #endregion Request delete original

                    #region FPS overriding
                    if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                    {
                        arguments += " FPS=" + videoInformation.VideoSetting.FPS;
                    }
                    else if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                    {
                    }
                    else
                    {
                        arguments += " FPS=" + (int)videoInformation.VideoSetting.frameRate;
                    }
                    #endregion FPS overriding

                    #region Audio processing
                    arguments += " with_audio=true";
                    #endregion Audio processing

                    #region Requester
                    arguments += " requester=mediaplayer";
                    arguments += " sessionid=" + userInfo.SessionID;
                    arguments += " printinfo=true";
                    #endregion Requester
                    #endregion VideoProcessing.exe argument configurations

                    #region Video info extraction
                    VideoProcessor.ApplicationSettings applicationSettings = new VideoProcessor.ApplicationSettings();
                    applicationSettings.useCustomApplication = true;
                    applicationSettings.FFmpegPath           = systemConfiguration.FFmpegLocation;
                    applicationSettings.FFProbePath          = systemConfiguration.FFProbeLocation;
                    VideoProcessor.VideoProcessor processor = new VideoProcessor.VideoProcessor(applicationSettings);
                    #endregion Video info extraction

                    #region Generate info

                    #region File location informations
                    videoInfo.videoSource           = videoInformation.VideoLocations.VideoLocation;
                    videoInfo.networkAccessLocation = networkProcessedVideoDirectory;
                    videoInfo.localAccessLocation   = processedVideoDirectory;
                    #endregion File location informations

                    #region Video name
                    //videoInfo.videoName = tempFileNameWithoutExtension;
                    videoInfo.videoName          = tempFileName;
                    videoInfo.processedVideoName = localFileNameWithoutExtension;
                    #endregion Video name

                    #region Video frame rate
                    if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                    {
                        videoInfo.frameRate = videoInformation.VideoSetting.FPS;
                    }
                    else if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                    {
                        videoInfo.frameRate = processor.GetFrameRate(temporaryDownloadLocation);
                        //videoInfo.frameRate = -1;
                    }
                    else
                    {
                        videoInfo.frameRate = (double)videoInformation.VideoSetting.frameRate;
                    }
                    #endregion Video frame rate

                    #region Local video save location
                    //if (processedVideoDirectory.EndsWith("\\"))
                    //{
                    //    videoInfo.localAccessLocation = processedVideoDirectory + localFileName;
                    //}
                    //else
                    //{
                    //    videoInfo.localAccessLocation = processedVideoDirectory + "\\" + localFileName;
                    //}
                    #endregion Local video save location

                    #region Network video save location
                    videoInfo.networkAccessLocation = networkProcessedVideoDirectory;
                    #endregion Network video save location

                    #region Video duration
                    videoInfo.videoDuration = processor.GetTotalDuration(temporaryDownloadLocation).TotalSeconds;
                    #endregion Video duration

                    #region Video info

                    #region Video frame informations
                    videoInfo.startFrame = 1;

                    if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                    {
                        videoInfo.endFrame = processor.GetTotalFrames(temporaryDownloadLocation);
                    }
                    else if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                    {
                        videoInfo.endFrame = Convert.ToInt32(videoInfo.videoDuration * videoInformation.VideoSetting.FPS);
                    }
                    else
                    {
                        videoInfo.endFrame = Convert.ToInt32(videoInfo.videoDuration * (double)videoInformation.VideoSetting.frameRate);
                    }
                    #endregion Video frame informations

                    videoInfo.videoHeight = videoHeight;
                    #endregion Video info

                    #endregion Generate info

                    #region Video information registration
                    //Re-read user settings
                    VideoPlayerSettings settings = HelperClass.ReadPlayerSettings(userInfo.SessionID, "MediaPlayerDatabase", "UserSettings", systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString);

                    // Add process to database
                    HelperClass.SetVideoInfo(settings, userInfo, videoInfo);

                    // Get process ID
                    int processID = SQLClassPeralatan.Peralatan.NilaiTertinggi("MediaPlayerDatabase", "ProcessedVideoInfo", "ProcessID", "UserID", userInfo.UserID.ToString(), systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString);
                    videoInfo.processID = processID;
                    #endregion Video information registration

                    #region VideoProcessing.exe additional argument
                    //arguments += " processid=" + processID;
                    #endregion VideoProcessing.exe additional argument

                    #region Program execution
                    startInfo.Arguments = arguments;
                    if (ConfigurationManager.AppSettings["VideoProcessingWindowType"] == "Normal")
                    {
                        startInfo.WindowStyle = ProcessWindowStyle.Normal;
                    }
                    else
                    {
                        startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    }
                    startInfo.UseShellExecute = true;
                    Process.Start(startInfo);
                    #endregion Program execution

                    //TODO Cleanup file
                    #region Cleanup

                    /*
                     * For now, the clean up of temporary downloaded file will be
                     * hanlded by external application.
                     * The reason is because there's an external application and
                     * to prevent the external application from getting error.
                     */

                    videoInfo.result = Result.Success;
                    #endregion Cleanup

                    return(videoInfo);
                }
                else
                {
                    videoInfo.result  = Result.Fail;
                    videoInfo.message = "Video playing with protocol other than http is not supported";
                    return(videoInfo);
                }
            }
            else
            {
                #region Preparation
                ProcessStartInfo startInfo      = new ProcessStartInfo(systemConfiguration.VideoProcessorLocation);
                FFProbe          fFProbe        = new FFProbe();
                ProcessedVideo   processedVideo = new ProcessedVideo();

                #region Working directories
                string processedVideoSaveLocation     = systemConfiguration.ProcessedVideoSaveLocation;
                string networkProcessedVideoDirectory = string.Empty;
                string processedVideoDirectory        = string.Empty;
                #endregion Working directories

                #endregion Preparation

                #region Video information
                string localVideoName = string.Empty;
                string localVideoNameWithoutExtension = string.Empty;
                string videoExtension = string.Empty;

                string localVideoNameInBase64 = string.Empty;
                #region File name processing

                #region Video file name
                localVideoName = Path.GetFileName(videoInformation.VideoLocations.VideoLocation);
                localVideoNameWithoutExtension = Path.GetFileNameWithoutExtension(localVideoName);
                videoExtension = Path.GetExtension(localVideoName);
                #endregion Video file name

                #region Video file name in Base64 format
                localVideoNameInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(localVideoName));
                #endregion Video file name in Base64 format
                #endregion File name processing

                #region Video settings
                int videoHeight;
                if (videoInformation.VideoSetting.processedVideoResolution == Resolution.Other)
                {
                    videoHeight = videoInformation.VideoSetting.height;
                }
                else if (videoInformation.VideoSetting.processedVideoResolution == Resolution.Original)
                {
                    videoHeight = -1;
                }
                else
                {
                    videoHeight = (int)videoInformation.VideoSetting.processedVideoResolution;
                }
                #endregion Video settings

                #endregion Video information

                #region Directory setup

                #region Processed video directory
                if (videoInformation.VideoLocations.videoSaveLocation == "default")
                {
                    throw new NotImplementedException("Custom path is not yet supported.");
                    //if (videoInformation.VideoLocations.videoSaveLocation.EndsWith("\\"))
                    //{
                    //    processedVideoDirectory = videoInformation.VideoLocations.videoSaveLocation + ID;
                    //}
                    //else
                    //{
                    //    processedVideoDirectory = videoInformation.VideoLocations.videoSaveLocation + "\\" + ID;
                    //}
                    ////Check for directory
                    //if (!Directory.Exists(processedVideoDirectory))
                    //{
                    //    Directory.CreateDirectory(processedVideoDirectory);
                    //}
                }
                else
                {
                    if (processedVideoSaveLocation.EndsWith("\\"))
                    {
                        processedVideoDirectory = processedVideoSaveLocation + userInfo.SessionID;
                    }
                    else
                    {
                        processedVideoDirectory = processedVideoSaveLocation + "\\" + userInfo.SessionID;
                    }

                    //Check for directory
                    if (!Directory.Exists(processedVideoDirectory))
                    {
                        Directory.CreateDirectory(processedVideoDirectory);
                    }
                }

                if (processedVideoDirectory.EndsWith("\\"))
                {
                    processedVideoDirectory += localVideoNameInBase64;
                }
                else
                {
                    processedVideoDirectory += "\\" + localVideoNameInBase64;
                }

                if (!Directory.Exists(processedVideoDirectory))
                {
                    Directory.CreateDirectory(processedVideoDirectory);
                }
                #endregion Processed video directory

                #region Network processed video directory
                if (!Directory.Exists(processedVideoDirectory))
                {
                    throw new Exception("Cannot create network folder if local folder isn't available.");
                }
                if (videoInformation.VideoLocations.videoNetworkSaveLocation.EndsWith("/"))
                {
                    networkProcessedVideoDirectory = videoInformation.VideoLocations.videoNetworkSaveLocation + userInfo.SessionID + "/";
                }
                else
                {
                    networkProcessedVideoDirectory = videoInformation.VideoLocations.videoNetworkSaveLocation + "/" + userInfo.SessionID + "/";
                }

                if (networkProcessedVideoDirectory.EndsWith("/"))
                {
                    networkProcessedVideoDirectory += localVideoNameInBase64;
                }
                else
                {
                    networkProcessedVideoDirectory += "/" + localVideoNameInBase64;
                }
                #endregion Network processed video directory

                #endregion Directory setup

                #region VideoProcessing.exe argument configurations
                string arguments = "GetFrames ";

                #region Source file
                if (videoInformation.VideoLocations.VideoLocation.Contains("\""))
                {
                    arguments += videoInformation.VideoLocations.VideoLocation + " ";
                }
                else
                {
                    arguments += "\"" + videoInformation.VideoLocations.VideoLocation + "\" ";
                }
                #endregion Source file

                #region Target directory
                if (processedVideoDirectory.Contains("\""))
                {
                    arguments += processedVideoDirectory + " ";
                }
                else
                {
                    arguments += "\"" + processedVideoDirectory + "\"";
                }
                #endregion Target directory

                #region Scaling
                if (videoHeight > 0)
                {
                    if (videoHeight > 0)
                    {
                        arguments += " height=" + videoHeight;
                    }
                }
                #endregion Scaling

                #region Request delete original
                //if (deleteTemporaryVideoWhenFinished)
                //{
                //    // += " request_delete=true";
                //}
                #endregion Request delete original

                #region FPS overriding
                if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                {
                    arguments += " FPS=" + videoInformation.VideoSetting.FPS;
                }
                else if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                {
                }
                else
                {
                    arguments += " FPS=" + (int)videoInformation.VideoSetting.frameRate;
                }
                #endregion FPS overriding

                #region Audio processing
                arguments += " with_audio=true";
                #endregion Audio processing

                #region Requester
                arguments += " requester=mediaplayer";
                arguments += " sessionid=" + userInfo.SessionID;
                arguments += " printinfo=true";
                #endregion Requester
                #endregion VideoProcessing.exe argument configurations

                #region Video info extraction
                VideoProcessor.ApplicationSettings applicationSettings = new VideoProcessor.ApplicationSettings();
                applicationSettings.useCustomApplication = true;
                applicationSettings.FFmpegPath           = systemConfiguration.FFmpegLocation;
                applicationSettings.FFProbePath          = systemConfiguration.FFProbeLocation;
                VideoProcessor.VideoProcessor processor = new VideoProcessor.VideoProcessor(applicationSettings);
                #endregion Video info extraction

                #region Processed video information

                #region File location informations
                processedVideo.videoSource           = videoInformation.VideoLocations.VideoLocation;
                processedVideo.networkAccessLocation = networkProcessedVideoDirectory;
                processedVideo.localAccessLocation   = processedVideoDirectory;
                #endregion File location informations

                #region Video name
                //processedVideo.videoName = tempFileNameWithoutExtension;
                processedVideo.processedVideoName = localVideoNameInBase64;
                #endregion Video name

                #region Video frame rate
                if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                {
                    processedVideo.frameRate = videoInformation.VideoSetting.FPS;
                }
                else if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                {
                    processedVideo.frameRate = processor.GetFrameRate(videoInformation.VideoLocations.VideoLocation);
                }
                else
                {
                    processedVideo.frameRate = (double)videoInformation.VideoSetting.frameRate;
                }
                #endregion Video frame rate

                #region Local video save location
                //processedVideo.localAccessLocation = videoInformation.VideoLocations.VideoLocation;
                #endregion Local video save location

                #region Network video save location
                processedVideo.networkAccessLocation = networkProcessedVideoDirectory;
                #endregion Network video save location

                #region Video duration
                processedVideo.videoDuration = processor.GetTotalDuration(videoInformation.VideoLocations.VideoLocation).TotalSeconds;
                #endregion Video duration

                #region Video frame information

                #region Video frame informations
                processedVideo.startFrame = 1;

                if (videoInformation.VideoSetting.frameRate == FrameRate.Default)
                {
                    processedVideo.endFrame = processor.GetTotalFrames(videoInformation.VideoLocations.VideoLocation);
                }
                else if (videoInformation.VideoSetting.frameRate == FrameRate.Other)
                {
                    processedVideo.endFrame = Convert.ToInt32(processedVideo.videoDuration * videoInformation.VideoSetting.FPS);
                }
                else
                {
                    processedVideo.endFrame = Convert.ToInt32(processedVideo.videoDuration * (double)videoInformation.VideoSetting.frameRate);
                }
                #endregion Video frame informations

                processedVideo.videoHeight = videoHeight;
                #endregion Video frame information

                #endregion Processed video information

                #region Video information registration
                //Re-read user settings
                VideoPlayerSettings settings = HelperClass.ReadPlayerSettings(userInfo.SessionID, "MediaPlayerDatabase", "UserSettings", systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString);

                // Add process to database
                HelperClass.SetVideoInfo(settings, userInfo, processedVideo);

                // Get process ID
                int processID = SQLClassPeralatan.Peralatan.NilaiTertinggi("MediaPlayerDatabase", "ProcessedVideoInfo", "ProcessID", "UserID", userInfo.UserID.ToString(), systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString);
                processedVideo.processID = processID;
                #endregion Video information registration

                #region VideoProcessing.exe additional argument
                //arguments += " processid=" + processID;
                #endregion VideoProcessing.exe additional argument

                #region Program execution
                startInfo.Arguments = arguments;
                if (ConfigurationManager.AppSettings["VideoProcessingWindowType"] == "Normal")
                {
                    startInfo.WindowStyle = ProcessWindowStyle.Normal;
                }
                else
                {
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                }
                startInfo.UseShellExecute = true;
                Process.Start(startInfo);
                #endregion Program execution

                #region Cleanup

                /*
                 * For now, the clean up of temporary downloaded file will be
                 * hanlded by external application.
                 * The reason is because there's an external application and
                 * to prevent the external application from getting error.
                 */

                processedVideo.result = Result.Success;
                #endregion Cleanup
                return(processedVideo);
            }
        }
Beispiel #2
0
        protected void btnUploadVideo_Click(object sender, EventArgs e)
        {
            #region Preparation

            #region Initialization

            #region Database configuration
            string databaseName  = "MediaPlayerDatabase";
            string userTableName = "SessionInfo";
            string settingsTable = "UserSettings";
            #endregion Database configuration

            #region Processor initialization
            Processor mainProcessor = new Processor();
            #endregion Processor initialization

            #region User information
            UserInfo userInfo = new UserInfo();
            #endregion User information

            #region Video processing information
            string                     videoName = string.Empty;
            string                     videoNameWithoutExtension  = string.Empty;
            ProcessedVideo             processedVideo             = new ProcessedVideo();
            VideoProcessingInformation videoProcessingInformation = new VideoProcessingInformation();
            #endregion Video processing information

            #endregion Initialization

            #region System configuration loader
            SystemConfiguration systemConfiguration = HelperClass.SystemConfigurationLoader();
            #endregion System configuration loader

            #region User information loader
            // Check for user information in database
            if (HelperClass.CheckUser(databaseName, userTableName, Session.SessionID, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
            {
                userInfo.SessionID = Session.SessionID;
                try
                {
                    userInfo.UserID = HelperClass.ReadUserInfo(Session.SessionID).UserID;
                }
                catch (Exception err)
                {
                    Response.Redirect("Error.aspx?id=22&message=" + err.Message);
                }
            }
            else
            {
                userInfo.SessionID = Session.SessionID;
                if (!HelperClass.AddUser(databaseName, userTableName, userInfo.SessionID, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                {
                    Response.Redirect("Error.aspx?id=23");
                }

                try
                {
                    userInfo.UserID = HelperClass.ReadUserInfo(Session.SessionID).UserID;
                }
                catch (Exception err)
                {
                    Response.Redirect("Error.aspx?id=22&message=" + err.Message);
                }
            }
            #endregion User information loader

            #region Player settings loader
            VideoPlayerSettings settings = new VideoPlayerSettings();

            if (HelperClass.CheckSettings(databaseName, userInfo, settingsTable, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
            {
                settings = HelperClass.ReadPlayerSettings(Session.SessionID, database, settingsTable, connectionString);
            }
            else
            {
                if (HelperClass.CreateNewSettings(databaseName, settingsTable, userInfo, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                {
                    settings = HelperClass.ReadPlayerSettings(Session.SessionID, database, settingsTable, connectionString);
                }
            }
            #endregion Player settings loader

            #region Video information preparation
            //processedVideo.videoName =  HttpUtility.UrlEncode(HelperClass.StringEncoderDecoder(Path.GetFileNameWithoutExtension(uplVideo.FileName), StringConversionMode.Encode));
            processedVideo.videoName = HttpUtility.UrlEncode(HelperClass.StringEncoderDecoder(Path.GetFileName(uplVideo.FileName), StringConversionMode.Encode));
            //processedVideo.processedVideoName = Convert.ToBase64String(Encoding.UTF8.GetBytes(processedVideo.videoName));
            #endregion Video information preparation

            #endregion Preparation

            #region File saving configuration

            //string saveLocation = string.Empty;

            bool requestDeleteFileAfterComplete = false;

            #region Temporary download location
            if (videoSaveLocation.EndsWith("\\"))
            {
                processedVideo.localAccessLocation = videoSaveLocation + Session.SessionID;
            }
            else
            {
                processedVideo.localAccessLocation = videoSaveLocation + "\\" + Session.SessionID;
            }

            // Path checking
            if (!Directory.Exists(processedVideo.localAccessLocation))
            {
                Directory.CreateDirectory(processedVideo.localAccessLocation);
            }

            if (processedVideo.localAccessLocation.EndsWith("\\"))
            {
                //processedVideo.localAccessLocation += processedVideo.processedVideoName + Path.GetExtension(uplVideo.FileName);
                processedVideo.localAccessLocation += Convert.ToBase64String(Encoding.UTF8.GetBytes(processedVideo.videoName)) + Path.GetExtension(uplVideo.FileName);
            }
            else
            {
                processedVideo.localAccessLocation += "\\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(processedVideo.videoName)) + Path.GetExtension(uplVideo.FileName);;
            }
            #endregion Temporary download location


            #endregion File saving configuration

            #region Received info configuration
            string networkAccessLocation = string.Empty;
            //string videoName = string.Empty;
            string videoDuration = string.Empty;
            string frameRate     = string.Empty;
            string startFrame    = string.Empty;
            string endFrame      = string.Empty;
            string videoWidth    = string.Empty;
            string videoHeight   = string.Empty;

            #endregion Received info configuration

            #region Video saving
            uplVideo.SaveAs(processedVideo.localAccessLocation);

            //try
            //{
            //}
            //catch (Exception err)
            //{
            //    Response.Redirect("Error.aspx?id=202&message=" + err.Message);
            //    return;
            //}
            #endregion Video saving

            #region Information generation
            videoProcessingInformation.VideoLocations.VideoLocation            = processedVideo.localAccessLocation;
            videoProcessingInformation.VideoLocations.videoSaveLocation        = systemConfiguration.ProcessedVideoSaveLocation;
            videoProcessingInformation.VideoLocations.videoNetworkSaveLocation = systemConfiguration.NetworkProcessedVideoSaveLocation;
            videoProcessingInformation.VideoSetting.processedVideoResolution   = settings.resolution;
            videoProcessingInformation.VideoSetting.frameRate       = settings.frameRate;
            videoProcessingInformation.VideoSetting.audioProcessing = AudioProcessing.ProcessAudio;

            #endregion Information generation

            #region Video processing

            ProcessedVideo processedVideo2 = mainProcessor.ProcessVideo(videoProcessingInformation, systemConfiguration, userInfo, true);

            //VideoProcessingService.Service1Client client = new VideoProcessingService.Service1Client();
            //string[] receivedInfo = client.ProcessVideo2(saveLocation, true, Session.SessionID, true, 854, 480, 30);
            #endregion Video processing

            #region Result combination
            string temporaryData = processedVideo.videoName;
            processedVideo           = processedVideo2;
            processedVideo.videoName = temporaryData;
            #endregion Result combination

            #region Query string preparation
            string queryString = string.Empty;

            if (processedVideo.result == Result.Success)
            {
                queryString += "?new=true&";
                queryString += "mode=upload&";
                queryString += "path=" + processedVideo.networkAccessLocation + "&";
                queryString += "name=" + processedVideo.videoName + "&";
                queryString += "duration=" + processedVideo.videoDuration + "&";
                queryString += "framerate=" + processedVideo.frameRate + "&";
                queryString += "startframe=" + processedVideo.startFrame + "&";
                queryString += "endframe=" + processedVideo.endFrame + "&";
                queryString += "videoresolution=" + processedVideo.videoHeight + "&";
                queryString += "pid=" + processedVideo.processID;
                if (Convert.ToInt32(lstPlayingSpeed.SelectedValue) > 0)
                {
                    queryString += "&playspeed=" + lstPlayingSpeed.SelectedValue;
                }
                if (txtCustomPlayTime.Text != string.Empty)
                {
                    queryString += "&timeposition=" + txtCustomPlayTime.Text;
                }


                Response.Redirect("Player.aspx" + queryString);
            }
            else
            {
                Response.Redirect("Error.aspx?id=301");
            }

            #endregion Query string preparation

            // Transfer page
            Response.Redirect("Player.aspx" + queryString);
        }
        /*
         * This class contains the temporary main function of the video processing class.
         * If this success, WCFAIOProcessor will be terminated and continued using this
         * class instead.
         */

        public FunctionResult VideoProcessor(VideoProcessingInformation videoInformation, VideoProcessingSetting videoSetting)
        {
            FunctionResult result = new FunctionResult();

            return(result);
        }
Beispiel #4
0
        protected void btnLoadURLVideo_Click(object sender, EventArgs e)
        {
            if (mode == AccessMode.Web || mode == AccessMode.External)
            {
                #region In line commands
                // Used to check for commands (wihtout additional information)
                if (txtURLSource.Text.ToLower() == "help" || txtURLSource.Text.ToLower() == "bantuan")
                {
                    Response.Redirect("Help.aspx");
                }
                else if (txtURLSource.Text.ToLower() == "error")
                {
                    Response.Redirect("Error.aspx?id=100");
                }
                else if (txtURLSource.Text.ToLower() == "setting" || txtURLSource.Text.ToLower() == "settings")
                {
                    Response.Redirect("Settings.aspx");
                }
                else if (txtURLSource.Text.ToLower() == "player")
                {
                    Response.Redirect("Player.aspx");
                }
                else if (txtURLSource.Text.ToLower() == "sample1" || txtURLSource.Text.ToLower() == "sample2" || txtURLSource.Text.ToLower() == "sample3" || txtURLSource.Text.ToLower() == "sample4" || txtURLSource.Text.ToLower() == "sample5")
                {
                    Response.Redirect("Error.aspx?id=2");
                }
                else if (txtURLSource.Text.ToLower() == "checker")
                {
                    Response.Redirect("Checker.aspx?mode=sample");
                }
                #endregion In line commands

                #region Validation
                if (HelperClass.CheckWebsite(txtURLSource.Text))
                {
                    Uri uri = new Uri(txtURLSource.Text);
                    Response.Redirect("Error.aspx?id=902&message=" + uri.Host);
                }
                #endregion Validation

                #region (Old) Main Processing

                //#region Old main processing
                //#region Service initialization
                //VideoProcessingService.Service1Client videoProcessor = new VideoProcessingService.Service1Client();
                //#endregion Service initialization

                //#region Main process
                //string[] receivedVideoInfo = videoProcessor.ProcessVideo2(txtURLSource.Text, true, Session.SessionID, true, 0, (int)settings.resolution, (float)settings.frameRate);
                //#endregion Main process
                //#endregion Old main processing

                //#region Result processor
                //Stopwatch waitTime = new Stopwatch();
                //waitTime.Start();

                //if (receivedVideoInfo.Length == 0)
                //{
                //    System.Threading.Thread.Sleep(1000);
                //    if (waitTime.ElapsedMilliseconds == 20000)
                //    {
                //        waitTime.Stop();
                //        Response.Redirect("Error.aspx");
                //    }
                //}
                //videoProcessor.Close();
                //if (receivedVideoInfo[0].ToLower().Contains("error"))
                //{
                //    Response.Redirect("Error.aspx?id=10a");
                //}
                //else
                //{
                //    string queryString = string.Empty;
                //    queryString += "?new=true&";
                //    queryString += "path=" + receivedVideoInfo[1] + "&";
                //    queryString += "name=" + receivedVideoInfo[2] + "&";
                //    queryString += "duration=" + receivedVideoInfo[3] + "&";
                //    queryString += "framerate=" + receivedVideoInfo[4] + "&";
                //    queryString += "startframe=" + receivedVideoInfo[5] + "&";
                //    queryString += "endframe=" + receivedVideoInfo[6] + "&";
                //    queryString += "videowidth=" + receivedVideoInfo[7];
                //    Response.Redirect("Player.aspx" + queryString);
                //}
                //#endregion Result processor
                #endregion (Old) Main Processing

                #region  New processing
                #region Preparation
                string databaseName  = "MediaPlayerDatabase";
                string userTableName = "SessionInfo";
                string settingsTable = "UserSettings";

                Processor mainProcessor = new Processor();
                UserInfo  userInfo      = new UserInfo();
                VideoProcessingInformation videoProcessingInformation = new VideoProcessingInformation();

                #region System configuration loader
                SystemConfiguration systemConfiguration = HelperClass.SystemConfigurationLoader();
                #endregion System configuration loader

                #region User information loader
                // Check for user information in database
                if (HelperClass.CheckUser(databaseName, userTableName, Session.SessionID, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                {
                    userInfo.SessionID = Session.SessionID;
                    try
                    {
                        userInfo.UserID = HelperClass.ReadUserInfo(Session.SessionID).UserID;
                    }
                    catch (Exception err)
                    {
                        Response.Redirect("Error.aspx?id=22&message=" + err.Message);
                    }
                }
                else
                {
                    userInfo.SessionID = Session.SessionID;
                    if (!HelperClass.AddUser(databaseName, userTableName, userInfo.SessionID, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                    {
                        Response.Redirect("Error.aspx?id=23");
                    }
                    try
                    {
                        userInfo.UserID = HelperClass.ReadUserInfo(Session.SessionID).UserID;
                    }
                    catch (Exception err)
                    {
                        Response.Redirect("Error.aspx?id=22&message=" + err.Message);
                    }
                }
                #endregion User information loader

                #region Player settings loader
                VideoPlayerSettings settings = new VideoPlayerSettings();
                // Check settings
                if (HelperClass.CheckSettings(databaseName, userInfo, settingsTable, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                {
                    settings = HelperClass.ReadPlayerSettings(Session.SessionID, database, settingsTable, connectionString);
                }
                else
                {
                    if (HelperClass.CreateNewSettings(databaseName, settingsTable, userInfo, systemConfiguration.DatabaseProcessingConfiguration.DatabaseConectionString))
                    {
                        settings = HelperClass.ReadPlayerSettings(Session.SessionID, database, settingsTable, connectionString);
                    }
                }
                #endregion Player settings loader

                #endregion Preparation;

                #region Information generation
                videoProcessingInformation.VideoLocations.VideoLocation            = txtURLSource.Text;
                videoProcessingInformation.VideoLocations.videoSaveLocation        = systemConfiguration.ProcessedVideoSaveLocation;
                videoProcessingInformation.VideoLocations.videoNetworkSaveLocation = systemConfiguration.NetworkProcessedVideoSaveLocation;
                videoProcessingInformation.VideoSetting.processedVideoResolution   = settings.resolution;
                videoProcessingInformation.VideoSetting.frameRate       = settings.frameRate;
                videoProcessingInformation.VideoSetting.audioProcessing = AudioProcessing.ProcessAudio;

                userInfo.SessionID = Session.SessionID;
                #endregion Information generation

                #region Main process
                ProcessedVideo processedVideo = mainProcessor.ProcessVideo(videoProcessingInformation, systemConfiguration, userInfo);
                string         queryString    = string.Empty;
                if (processedVideo.result == Result.Success)
                {
                    queryString += "?new=true&";
                    queryString += "path=" + processedVideo.networkAccessLocation + "&";
                    queryString += "name=" + processedVideo.videoName + "&";
                    queryString += "duration=" + processedVideo.videoDuration + "&";
                    queryString += "framerate=" + processedVideo.frameRate + "&";
                    queryString += "startframe=" + processedVideo.startFrame + "&";
                    queryString += "endframe=" + processedVideo.endFrame + "&";
                    queryString += "videoresolution=" + processedVideo.videoHeight + "&";
                    queryString += "pid=" + processedVideo.processID;
                    if (Convert.ToInt32(lstPlayingSpeed.SelectedValue) > 0)
                    {
                        queryString += "&playspeed=" + lstPlayingSpeed.SelectedValue;
                    }
                    if (txtCustomPlayTime.Text != string.Empty)
                    {
                        queryString += "&timeposition=" + txtCustomPlayTime.Text;
                    }
                    Response.Redirect("Player.aspx" + queryString);
                }
                else
                {
                    Response.Redirect("Error.aspx?id=301&message=" + processedVideo.message);
                }
                #endregion Main process


                #endregion New processing
            }
            else if (mode == AccessMode.Other)
            {
                Server.Transfer("Error.aspx?id=96");
            }
        }