示例#1
0
        public void Convert(VideoType type, ArgumentContainer container)
        {
            var output = Input.OutputLocation(type);

            try
            {
                var input = VideoInfo.FromFileInfo(Input);

                var arguments = new ArgumentContainer {
                    new InputArgument(input)
                };
                foreach (var arg in container)
                {
                    arguments.Add(arg.Value);
                }
                arguments.Add(new OutputArgument(output));

                var scaling = container.Find <ScaleArgument>();

                Encoder.Convert(arguments);

                var outputVideo = new VideoInfo(output.FullName);

                Assert.IsTrue(File.Exists(output.FullName));
                Assert.AreEqual(outputVideo.Duration, input.Duration);

                if (scaling == null)
                {
                    Assert.AreEqual(outputVideo.Width, input.Width);
                    Assert.AreEqual(outputVideo.Height, input.Height);
                }
                else
                {
                    if (scaling.Value.Width != -1)
                    {
                        Assert.AreEqual(outputVideo.Width, scaling.Value.Width);
                    }

                    if (scaling.Value.Height != -1)
                    {
                        Assert.AreEqual(outputVideo.Height, scaling.Value.Height);
                    }

                    Assert.AreNotEqual(outputVideo.Width, input.Width);
                    Assert.AreNotEqual(outputVideo.Height, input.Height);
                }
            }
            finally
            {
                if (File.Exists(output.FullName))
                {
                    File.Delete(output.FullName);
                }
            }
        }
示例#2
0
        private bool RunProcess(ArgumentContainer container, FileInfo output)
        {
            var successState = true;

            CreateProcess(this.ArgumentBuilder.BuildArguments(container), _ffmpegPath, true, rStandardError: true);


            try
            {
                InputArgument inputArgument = container.Find <InputArgument>();
                VideoInfo     infoOrigen    = new VideoInfo(new FileInfo(inputArgument.Value[0]));
                _totalTime = infoOrigen.Duration;
                Process.Start();
                Process.ErrorDataReceived += OutputData;
                Process.BeginErrorReadLine();
                Process.WaitForExit();
            }
            catch (Exception)
            {
                successState = false;
            }
            finally
            {
                Process.Close();

                if (File.Exists(output.FullName))
                {
                    using (var file = File.Open(output.FullName, FileMode.Open))
                    {
                        if (file.Length == 0)
                        {
                            throw new FFMpegException(FFMpegExceptionType.Process, _errorOutput);
                        }
                    }
                }
                else
                {
                    throw new FFMpegException(FFMpegExceptionType.Process, _errorOutput);
                }
            }
            return(successState);
        }