示例#1
0
 protected virtual void OnMediaFileConvertionComplete(MediaFile mediaFile, MediaConverterMetadata outputMetadata)
 {
     if (this.MediaFileConvertionCompelete != null)
     {
         this.MediaFileConvertionCompelete(this, new MediaFileConversionEventArgs(mediaFile, outputMetadata));
     }
 }
示例#2
0
        protected virtual bool OnMediaFileConversionStarting(MediaFile mediaFile, MediaConverterMetadata outputMetadata)
        {
            if (this.MediaFileConversionStarting != null)
            {
                var args = new MediaFileConversionEventArgs(mediaFile, outputMetadata);
                this.MediaFileConversionStarting(this, args);
                return(!args.Cancel);
            }

            return(true);
        }
 public DownloadConvertRequest(MediaFile mediaFile, string downloadPath, string convertPath, MediaConverterMetadata convertMetadata)
 {
     this.MediaFile       = mediaFile;
     this.DownloadPath    = downloadPath;
     this.ConvertPath     = convertPath;
     this.ConvertMetadata = convertMetadata;
 }
示例#4
0
        public DownloadConvertRequest EnqueueDownloadAndConvertRequest(MediaFile file, string downloadPath, string convertPath, MediaConverterMetadata convertMetadata)
        {
            DownloadConvertRequest request = new DownloadConvertRequest(file, downloadPath, convertPath, convertMetadata);

            this.Queue.Enqueue(request);

            return(request);
        }
示例#5
0
 public DownloadConvertRequest EnqueueDownloadAndConvertRequest(MediaFile file, string outputPath, MediaConverterMetadata convertMetadata)
 {
     return(this.EnqueueDownloadAndConvertRequest(file, outputPath, outputPath, convertMetadata));
 }
示例#6
0
 public MediaFileConversionEventArgs(MediaFile mediaFile, MediaConverterMetadata outputMetadata)
     : base(mediaFile)
 {
     this.OutputMetadata = outputMetadata;
 }
示例#7
0
        public virtual ConvertResult Convert(MediaFile inputFile, string inputFilePath, string outputFolder, MediaConverterMetadata metadata)
        {
            ConvertResult result = new ConvertResult(inputFile);

            if (metadata == MediaConverterMetadata.Default)
            {
                result.IsConverted = false;
                return(result);
            }

            result.IsConverted = true;
            string destinationPath = Path.Combine(outputFolder, metadata.FileName + metadata.Extension);

            result.ConvertedPath = destinationPath;
            if (File.Exists(destinationPath))
            {
                try
                {
                    File.Delete(destinationPath);
                }
                catch (Exception ex)
                {
                    result.IsConverted = false;
                    result.Exceptions.Add(ex);
                    return(result);
                }
            }

            string extension = metadata.Extension.Value;

            if (!this.OnMediaFileConversionStarting(inputFile, metadata))
            {
                result.IsConverted = false;
                return(result);
            }

            string parameters = null;
            SupportedConversionFormats format = SupportedConversionFormats.Parse(extension);

            if (format == SupportedConversionFormats.Mp3)
            {
                parameters = string.Format("-i \"{0}\" -ab {1}k \"{2}\"", inputFilePath, (int)metadata.AudioBitrate, destinationPath);
            }

            Process instance = FfmpegManager.Instance.CreateNewFfmpegInstance(parameters);

            instance.Start();

            this.ProcessOutputStream(instance.StandardError);

            instance.WaitForExit();
            if (!instance.HasExited)
            {
                instance.Kill();
            }

            this.OnMediaFileConvertionComplete(inputFile, metadata);

            return(result);
        }