예제 #1
0
 private void TryUpdateMediaInfo(string data)
 {
     if (_mediaInfo == null)
     {
         if (RegexEngine.IsMediaInfo(data, out var newMediaInfo))
         {
             _mediaInfo = newMediaInfo;
         }
     }
 }
예제 #2
0
        private void FFmpegProcessOnErrorDataReceived(DataReceivedEventArgs e, FFmpegParameters parameters, ref Exception exception, List <string> messages)
        {
            var totalMediaDuration = new TimeSpan();

            if (e.Data == null)
            {
                return;
            }

            try
            {
                TryUpdateMediaInfo(e.Data);
                messages.Insert(0, e.Data);
                if (parameters.Input != null)
                {
                    RegexEngine.TestVideo(e.Data, parameters);
                    RegexEngine.TestAudio(e.Data, parameters);

                    var matchDuration = RegexEngine._index[RegexEngine.Find.Duration].Match(e.Data);
                    if (matchDuration.Success)
                    {
                        if (parameters.Input is MediaFile input)
                        {
                            if (input.MetaData == null)
                            {
                                input.MetaData = new MetaData {
                                    FileInfo = input.FileInfo
                                }
                            }
                            ;

                            RegexEngine.TimeSpanLargeTryParse(matchDuration.Groups[1].Value, out totalMediaDuration);
                            input.MetaData.Duration = totalMediaDuration;
                        }
                    }
                }

                if (RegexEngine.IsProgressData(e.Data, out var progressData))
                {
                    if (parameters.Input != null)
                    {
                        progressData.TotalDuration = parameters.Input.MetaData?.Duration ?? totalMediaDuration;
                    }

                    OnProgressChanged(new ConversionProgressEventArgs(progressData, parameters.Input, parameters.Output, _mediaInfo));
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
        }