public bool ProcessSynchronously(bool throwOnError = true, FFOptions?ffMpegOptions = null)
        {
            using var instance = PrepareInstance(ffMpegOptions ?? GlobalFFOptions.Current, out var cancellationTokenSource);
            var errorCode = -1;

            void OnCancelEvent(object sender, int timeout)
            {
                instance.SendInput("q");

                if (!cancellationTokenSource.Token.WaitHandle.WaitOne(timeout, true))
                {
                    cancellationTokenSource.Cancel();
                    instance.Started = false;
                }
            }

            CancelEvent     += OnCancelEvent;
            instance.Exited += delegate { cancellationTokenSource.Cancel(); };

            try
            {
                _ffMpegArguments.Pre();
                Task.WaitAll(instance.FinishedRunning().ContinueWith(t =>
                {
                    errorCode = t.Result;
                    cancellationTokenSource.Cancel();
                    _ffMpegArguments.Post();
                }), _ffMpegArguments.During(cancellationTokenSource.Token));
            }
            catch (Exception e)
            {
                if (!HandleException(throwOnError, e, instance.ErrorData))
                {
                    return(false);
                }
            }
            finally
            {
                CancelEvent -= OnCancelEvent;
            }

            return(HandleCompletion(throwOnError, errorCode, instance.ErrorData));
        }
Beispiel #2
0
        public static async Task <IMediaAnalysis> AnalyseAsync(Stream stream, int outputCapacity = int.MaxValue, FFOptions?ffOptions = null)
        {
            var streamPipeSource = new StreamPipeSource(stream);
            var pipeArgument     = new InputPipeArgument(streamPipeSource);

            using var instance = PrepareInstance(pipeArgument.PipePath, outputCapacity, ffOptions ?? GlobalFFOptions.Current);
            pipeArgument.Pre();

            var task = instance.FinishedRunning();

            try
            {
                await pipeArgument.During().ConfigureAwait(false);
            }
            catch (IOException)
            {
            }
            finally
            {
                pipeArgument.Post();
            }
            var exitCode = await task.ConfigureAwait(false);

            if (exitCode != 0)
            {
                throw new FFProbeProcessException($"ffprobe exited with non-zero exit-code ({exitCode} - {string.Join("\n", instance.ErrorData)})", instance.ErrorData);
            }

            pipeArgument.Post();
            return(ParseOutput(instance));
        }
 public static string GetFFProbeBinaryPath(FFOptions?ffOptions = null) => GetFFBinaryPath("FFProbe", ffOptions ?? Current);
Beispiel #4
0
        public static async Task <IMediaAnalysis> AnalyseAsync(Uri uri, int outputCapacity = int.MaxValue, FFOptions?ffOptions = null)
        {
            using var instance = PrepareInstance(uri.AbsoluteUri, outputCapacity, ffOptions ?? GlobalFFOptions.Current);
            await instance.FinishedRunning().ConfigureAwait(false);

            return(ParseOutput(instance));
        }
Beispiel #5
0
        public static async Task <IMediaAnalysis> AnalyseAsync(string filePath, int outputCapacity = int.MaxValue, FFOptions?ffOptions = null)
        {
            if (!File.Exists(filePath))
            {
                throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'");
            }

            using var instance = PrepareInstance(filePath, outputCapacity, ffOptions ?? GlobalFFOptions.Current);
            await instance.FinishedRunning().ConfigureAwait(false);

            return(ParseOutput(instance));
        }
Beispiel #6
0
        public static IMediaAnalysis Analyse(Uri uri, int outputCapacity = int.MaxValue, FFOptions?ffOptions = null)
        {
            using var instance = PrepareInstance(uri.AbsoluteUri, outputCapacity, ffOptions ?? GlobalFFOptions.Current);
            var exitCode = instance.BlockUntilFinished();

            if (exitCode != 0)
            {
                throw new FFMpegException(FFMpegExceptionType.Process, $"ffprobe exited with non-zero exit-code ({exitCode} - {string.Join("\n", instance.ErrorData)})", null, string.Join("\n", instance.ErrorData));
            }

            return(ParseOutput(instance));
        }
Beispiel #7
0
        public static IMediaAnalysis Analyse(string filePath, int outputCapacity = int.MaxValue, FFOptions?ffOptions = null)
        {
            if (!File.Exists(filePath))
            {
                throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'");
            }

            using var instance = PrepareInstance(filePath, outputCapacity, ffOptions ?? GlobalFFOptions.Current);
            var exitCode = instance.BlockUntilFinished();

            if (exitCode != 0)
            {
                throw new FFMpegException(FFMpegExceptionType.Process, $"ffprobe exited with non-zero exit-code ({exitCode} - {string.Join("\n", instance.ErrorData)})", null, string.Join("\n", instance.ErrorData));
            }

            return(ParseOutput(instance));
        }
Beispiel #8
0
 public static void Configure(FFOptions ffOptions)
 {
     _current = ffOptions ?? throw new ArgumentNullException(nameof(ffOptions));
 }