Beispiel #1
0
        public static void CreateSplits(TASK MotherTask, VideoFile VideoFile)
        {
            int         Splits        = GetNumberOfSplits(MotherTask);
            TimeSpan    timeSpan      = new TimeSpan(VideoFile.Duration.Ticks / Splits);
            TimeSpan    begin         = new TimeSpan(0);
            long        durationTotal = VideoFile.Duration.Ticks;
            PARAM_SPLIT paramSplit    = new PARAM_SPLIT();

            while (Splits != 0)
            {
                if (Splits == GetNumberOfSplits(MotherTask))
                {
                    long stopSpan = new TimeSpan(begin.Ticks + timeSpan.Ticks).Ticks;
                    paramSplit = new PARAM_SPLIT()
                    {
                        BEGIN_PARAM_SPLIT = begin.Ticks.ToString(), END_PARAM_SPLIT = stopSpan.ToString()
                    };
                }
                else
                {
                    long stopSpan = new TimeSpan(timeSpan.Ticks + (durationTotal - timeSpan.Ticks)).Ticks;
                    paramSplit = new PARAM_SPLIT()
                    {
                        BEGIN_PARAM_SPLIT = timeSpan.Ticks.ToString(), END_PARAM_SPLIT = stopSpan.ToString()
                    };
                }

                new PARAM_SPLIT_Service().AddOrUpdateParamSplit(paramSplit);

                CreateSubTask(MotherTask, paramSplit);

                Splits--;
            }
        }
Beispiel #2
0
        public static void CreateSubTask(TASK MotherTask, PARAM_SPLIT paramSplit)
        {
            TASK subTask_1 = new TASK();

            subTask_1.FK_ID_PARENT_TASK       = MotherTask.PK_ID_TASK;
            subTask_1.FK_ID_USER              = MotherTask.FK_ID_USER;
            subTask_1.FK_ID_FORMAT_TO_CONVERT = MotherTask.FK_ID_FORMAT_TO_CONVERT;
            subTask_1.FK_ID_PARAM_SPLIT       = paramSplit.PK_ID_PARAM_SPLIT;

            subTask_1.FILE_URL = MotherTask.FILE_URL_TEMP;
            new TASK_Service().AddOrUpdateTask(subTask_1);
            CreateSplit(subTask_1, paramSplit);
        }
 public bool AddOrUpdateParamSplit(PARAM_SPLIT paramSplit)
 {
     if (paramSplit.PK_ID_PARAM_SPLIT != 0)
     {
         UoW.PARAM_SPLIT_Repository.Update(paramSplit);
         UoW.Save();
         return(true);
     }
     else
     {
         UoW.PARAM_SPLIT_Repository.Insert(paramSplit);
         UoW.Save();
         return(true);
     }
 }
Beispiel #4
0
        public static void CreateSplit(TASK SubTask, PARAM_SPLIT ParamSplit)
        {
            VideoFile split    = new VideoFile(SubTask.FILE_URL);
            int       count    = SubTask.FILE_URL.LastIndexOf('.');
            string    leftPart = SubTask.FILE_URL.Substring(0, count);
            string    format   = SubTask.FILE_URL.Substring(count);
            string    fullName = leftPart + "_" + SubTask.PK_ID_TASK.ToString() + format;

            SubTask.FILE_URL      = fullName;
            SubTask.FILE_URL_TEMP = fullName;

            split.ExtractVideoSegment(fullName, Convert.ToInt64(ParamSplit.BEGIN_PARAM_SPLIT), Convert.ToInt64(ParamSplit.END_PARAM_SPLIT), Core.Transcoder.FFmpegWrapper.Videos.VideoFormat.avi);
            SubTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.A_FAIRE;
            new TASK_Service().AddOrUpdateTask(SubTask);
        }
        public static void CreateSubTask(TASK MotherTask, PARAM_SPLIT paramSplit, int nbSplitsTotal)
        {
            TASK subTask = new TASK();

            subTask.FK_ID_PARENT_TASK       = MotherTask.PK_ID_TASK;
            subTask.FK_ID_USER              = MotherTask.FK_ID_USER;
            subTask.IS_PAID                 = MotherTask.IS_PAID;
            subTask.FK_ID_TRANSACTION       = MotherTask.FK_ID_TRANSACTION;
            subTask.FK_ID_FORMAT_BASE       = MotherTask.FK_ID_FORMAT_BASE;
            subTask.FK_ID_FORMAT_TO_CONVERT = MotherTask.FK_ID_FORMAT_TO_CONVERT;
            subTask.FK_ID_PARAM_SPLIT       = paramSplit.PK_ID_PARAM_SPLIT;
            subTask.LENGTH = (int)MotherTask.LENGTH / nbSplitsTotal;

            // On set l'url de la tache mere pour que le service puisse aller créer le split a partir du fichier de base
            subTask.FILE_URL = MotherTask.FILE_URL_TEMP;
            new TASK_Service().AddOrUpdateTask(subTask);
            CreateSplit(subTask, paramSplit);
        }
        public static void CreateSplits(TASK MotherTask, VideoFile VideoFile)
        {
            // On récupère le nombre de split a effectuer
            int Splits      = GetNumberOfSplits(MotherTask);
            int SplitsTotal = Splits;
            // On récupère la longueur de chaque split
            TimeSpan timeSpan = new TimeSpan(VideoFile.Duration.Ticks / Splits);
            // On set le debut du premier split
            TimeSpan begin = new TimeSpan(0);
            // on récupère la durée totale de la video
            long durationTotal = VideoFile.Duration.Ticks;
            // On crée notre param split
            PARAM_SPLIT paramSplit = new PARAM_SPLIT();

            while (Splits != 0)
            {
                if (Splits == SplitsTotal)
                {
                    long stopSpan = new TimeSpan(begin.Ticks + timeSpan.Ticks).Ticks;
                    paramSplit = new PARAM_SPLIT()
                    {
                        BEGIN_PARAM_SPLIT = begin.Ticks.ToString(), END_PARAM_SPLIT = stopSpan.ToString()
                    };
                }
                else
                {
                    long beginSpan = timeSpan.Ticks * (SplitsTotal - Splits);
                    long stopSpan  = (durationTotal / SplitsTotal) + beginSpan;

                    paramSplit = new PARAM_SPLIT()
                    {
                        BEGIN_PARAM_SPLIT = beginSpan.ToString(), END_PARAM_SPLIT = stopSpan.ToString()
                    };
                }

                new PARAM_SPLIT_Service().AddOrUpdateParamSplit(paramSplit);
                // On crée une sous tache associé au paramSplit et la tache mere
                CreateSubTask(MotherTask, paramSplit, SplitsTotal);

                Splits--;
            }
        }
        public static void CreateSplit(TASK SubTask, PARAM_SPLIT ParamSplit)
        {
            try
            {
                VideoFile split    = new VideoFile(SubTask.FILE_URL);
                int       count    = SubTask.FILE_URL.LastIndexOf('.');
                string    leftPart = SubTask.FILE_URL.Substring(0, count);
                string    format   = SubTask.FILE_URL.Substring(count);
                string    fullName = leftPart + "_" + SubTask.PK_ID_TASK.ToString() + format;

                SubTask.FILE_URL      = fullName;
                SubTask.FILE_URL_TEMP = fullName;
                // On met un statut temporaire a 0 pour initialiser la tache
                SubTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.SPLIT_EN_COURS;
                new TASK_Service().UpdateTask(SubTask);
                // on extrait notre split
                split.ExtractVideoSegment(fullName, Convert.ToInt64(ParamSplit.BEGIN_PARAM_SPLIT), Convert.ToInt64(ParamSplit.END_PARAM_SPLIT), Core.Transcoder.FFmpegWrapper.Videos.VideoFormat.avi);
                SubTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.A_FAIRE;
                new TASK_Service().UpdateTask(SubTask);
            }
            catch (Exception e)
            {
                SubTask.STATUS = (int)EnumManager.PARAM_TASK_STATUS.ERREUR;
                new TASK_Service().UpdateTask(SubTask);

                TRACE trace = new TRACE()
                {
                    FK_ID_TASK   = SubTask.PK_ID_TASK,
                    FK_ID_SERVER = 1,
                    METHOD       = "FFMPEG Split",
                    TYPE         = "ERROR",
                    DESCRIPTION  = e.Message + " " + e.InnerException,
                    DATE_TRACE   = DateTime.Now,
                    NOM_SERVER   = System.Environment.MachineName
                };
                new TRACE_Service().AddTrace(trace);
            }
        }