Beispiel #1
0
 /// <summary>
 /// Returns whether a given file name is an image or a video (based on its extension)
 /// </summary>
 /// <param name="filename">Filename of the file to check.</param>
 /// <returns>A boolean which is true if it is an acceptable video file and false otherwise.</returns>
 private static bool IsVideoFile(string filename)
 {
     return(MediaProcessor.GetAllAllowedVideoExtensions().Contains(Path.GetExtension(filename).ToLower()));
 }
Beispiel #2
0
 public void AddFiles(string[] files)
 {
     AddNewFilesToList(files, MediaProcessor.GetAllAllowedExtensions(), this.fileList);
 }
Beispiel #3
0
        public bool HasAllowedVideoExt(string file)
        {
            string thisExt = Path.GetExtension(file).ToLower();

            return(MediaProcessor.GetAllAllowedVideoExtensions().Contains(thisExt));
        }
Beispiel #4
0
        /// <summary>
        /// Runs the processing on this instance of the MediaProcessor
        /// </summary>
        public void Run(CancellationToken token, ProgressCallback onProgress = null)
        {
            if (this.options == null)
            {
                throw new Exception("Media processor options must be set before MediaProcessor can be run.");
            }
            this.onProgress = onProgress;
            this.OnProcessingStart();

            this.cancelToken = token;

            this.failedList = new List <string>();

            List <string> outFileList = this.GetOutputFileList();

            for (int ii = 0; ii < this.fileList.Count; ii++)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                try
                {
                    if (!IsVideoFile(this.fileList[ii]))
                    {
                        DoOnProgress(this, new ProgressEventArgs(0, ii, this.GetNumFiles(), this.fileList[ii]));
                        MediaProcessor.ProcessImageFile(this.fileList[ii], outFileList[ii],
                                                        this.options.imageResizeValue, this.options.imageResizeType,
                                                        this.options.imageOutType,
                                                        this.cropBoundaries,
                                                        this.options.defaultCropRatio,
                                                        this.options.jpegQuality);
                    }
                    else
                    {
                        Tuple <double, double> trimRange = null;
                        int idx = this.trimFiles.FindIndex(a => a == this.fileList[ii]);
                        if (idx >= 0)
                        {
                            trimRange = this.trimRanges[idx];
                        }
                        DoOnProgress(this, new ProgressEventArgs(0, ii, this.GetNumFiles(), this.fileList[ii]));
                        MediaProcessor.ProcessVideoFile(this.fileList[ii], outFileList[ii],
                                                        this.options.videoResizeValue, this.options.videoResizeType,
                                                        this.options.videoOutType, this.options.videoQuality, trimRange, OnVideoEncodeProgress);
                    }
                    DoOnProgress(this, new ProgressEventArgs(0, (ii + 1), this.GetNumFiles(), this.fileList[ii]));
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }
                catch (Exception exp)
                {
                    Console.WriteLine(String.Format("{0} - {1}", exp.Message, exp.StackTrace));
                    failedList.Add(this.fileList[ii]);
                    lastProcessingError = exp;
                }
            }
            if (token.IsCancellationRequested)
            {
                this.OnProcessingCancelled();
            }
            else
            {
                this.OnProcessingComplete();
            }
        }