Example #1
0
        void GenerateGif(string PaletteFile)
        {
            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(_tempFileName);

            argsBuilder.AddInputFile(PaletteFile);

            argsBuilder.AddOutputFile(_args.FileName)
            .AddArg("lavfi", "paletteuse")
            .SetFrameRate(_args.FrameRate);

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), _args.FileName);

            process.WaitForExit();
        }
Example #2
0
        public async Task StartAsync(VideoConverterArgs Args, IProgress <int> Progress)
        {
            if (!FFmpegService.FFmpegExists)
            {
                throw new FFmpegNotFoundException();
            }

            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(Args.InputFile);

            const string filter = "\"[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse\"";

            argsBuilder.AddOutputFile(Args.FileName)
            .AddArg("filter_complex", filter)
            .SetFrameRate(Args.FrameRate);

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), Args.FileName, out var log);

            log.ProgressChanged += Progress.Report;

            await Task.Run(() => process.WaitForExit());

            if (process.ExitCode != 0)
            {
                throw new FFmpegException(process.ExitCode);
            }

            Progress.Report(100);
        }
        /// <inheritdoc />
        public void Dispose()
        {
            _ffMpegWriter.Dispose();

            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(_tempFileName);

            var output = argsBuilder.AddOutputFile(_args.FileName)
                         .AddArg(_args.VideoArgsProvider(_args.VideoQuality))
                         .SetFrameRate(_args.FrameRate);

            if (_args.AudioProvider != null)
            {
                output.AddArg(_args.AudioArgsProvider(_args.AudioQuality));
            }

            output.AddArg(_args.OutputArgs);

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), _args.FileName);

            process.WaitForExit();

            File.Delete(_tempFileName);
        }
Example #4
0
        public async Task StartAsync(VideoConverterArgs Args, IProgress <int> Progress)
        {
            if (!FFmpegService.FFmpegExists)
            {
                throw new FFmpegNotFoundException();
            }

            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(Args.InputFile);

            var output = argsBuilder.AddOutputFile(Args.FileName)
                         .SetFrameRate(Args.FrameRate);

            _videoCodec.Apply(ServiceProvider.Get <FFmpegSettings>(), Args, output);

            //if (Args.AudioProvider != null)
            {
                _videoCodec.AudioArgsProvider(Args.AudioQuality, output);
            }

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), Args.FileName, out var log);

            log.ProgressChanged += Progress.Report;

            await Task.Run(() => process.WaitForExit());

            if (process.ExitCode != 0)
            {
                throw new FFmpegException(process.ExitCode);
            }

            Progress.Report(100);
        }
Example #5
0
        string GeneratePalette()
        {
            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(_tempFileName);

            var tempFile = Path.GetTempFileName();
            var paletteFile = Path.ChangeExtension(tempFile, "png");
            File.Move(tempFile, paletteFile);

            argsBuilder.AddOutputFile(paletteFile)
                .AddArg("-vf palettegen")
                .SetFrameRate(_args.FrameRate)
                .AddArg("-y");

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), paletteFile);

            process.WaitForExit();

            return paletteFile;
        }
Example #6
0
        /// <inheritdoc />
        public void Dispose()
        {
            _ffMpegWriter.Dispose();

            var argsBuilder = new FFmpegArgsBuilder();

            argsBuilder.AddInputFile(_tempFileName);

            var output = argsBuilder.AddOutputFile(_args.FileName)
                         .SetFrameRate(_args.FrameRate);

            _args.VideoCodec.Apply(ServiceProvider.Get <FFmpegSettings>(), _args, output);

            if (_args.AudioProvider != null)
            {
                _args.VideoCodec.AudioArgsProvider(_args.AudioQuality, output);
            }

            var process = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), _args.FileName, out _);

            process.WaitForExit();

            File.Delete(_tempFileName);
        }