示例#1
0
 public void ChangeNumberOfAudioChannels_CreatesFile()
 {
     using (var file = TempFile.FromResource(Resources._2Channel, ".wav"))
     {
         var outputPath = file.Path.Replace(".wav", "1ch.wav");
         FFmpegRunner.ChangeNumberOfAudioChannels(file.Path, outputPath, 1, new NullProgress());
         Assert.IsTrue(File.Exists(outputPath));
     }
 }
示例#2
0
 public void ExtractOggAudio_CreatesFile()
 {
     using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
     {
         var outputPath = file.Path.Replace("wmv", "ogg");
         FFmpegRunner.ExtractOggAudio(file.Path, outputPath, 1, new NullProgress());
         Assert.IsTrue(File.Exists(outputPath));
     }
 }
示例#3
0
        public void MakeLowQualitySmallVideo_CreatesFile()
        {
            using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
            {
                var outputPath = file.Path.Replace("wmv", "low.wmv");
                FFmpegRunner.MakeLowQualitySmallVideo(file.Path, outputPath, 0, new ConsoleProgress());
                Assert.IsTrue(File.Exists(outputPath));
#if !MONO
                System.Diagnostics.Process.Start(outputPath);
#endif
            }
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// It's up to the caller to close and dispose of the stream.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static WaveStream GetOneChannelStreamFromAudio(string audioFilePath,
                                                              out Exception error, IProgress progress)
        {
            error = null;

            try
            {
                var stream = new WaveFileReader(audioFilePath);
                if (stream.WaveFormat.Channels == 1 || !FFmpegRunner.HaveNecessaryComponents)
                {
                    return(stream);
                }
            }
            catch (Exception e)
            {
                error = e;
                return(null);
            }

            var tmpFile = Path.Combine(Path.GetTempPath(), Path.GetFileName(audioFilePath));

            if (File.Exists(tmpFile))
            {
                File.Delete(tmpFile);
            }

            try
            {
                FFmpegRunner.ChangeNumberOfAudioChannels(audioFilePath, tmpFile, 1, progress);

                // WaveFileReader does not read the entire file into a buffer right away. Therefore,
                // the file will remain open but we want to delete it right away. So read it
                // into our own stream and pass that to WaveFileReader so the file is no longer
                // needed and can be deleted.
                return(new WaveFileReader(new MemoryStream(File.ReadAllBytes(tmpFile))));
            }
            catch (Exception e)
            {
                error = e;
                return(null);
            }
            finally
            {
                if (File.Exists(tmpFile))
                {
                    try { File.Delete(tmpFile); }
                    catch { }
                }
            }
        }
示例#5
0
        public void MakeLowQualityCompressedAudio_CreatesFile()
        {
            using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
            {
                var originalAudioPath = file.Path.Replace("wmv", "mp3");
                FFmpegRunner.ExtractMp3Audio(file.Path, originalAudioPath, 1, new NullProgress());

                var outputPath = originalAudioPath.Replace("mp3", "low.mp3");
                FFmpegRunner.MakeLowQualityCompressedAudio(originalAudioPath, outputPath, new ConsoleProgress());
                Assert.IsTrue(File.Exists(outputPath));
#if !MONO
                System.Diagnostics.Process.Start(outputPath);
#endif
            }
        }
示例#6
0
        private string ShrinkPicture(string original, string newPathRoot)
        {
            Debug.WriteLine("ShrinkPicture " + original);
            var newPath = newPathRoot + ".jpg";

            if (File.Exists(newPath))
            {
                File.Delete(newPath);
            }
            var result = FFmpegRunner.MakeLowQualitySmallPicture(original, newPath,
                                                                 _progress);

            CheckForError(result);
            return(newPath);
        }
示例#7
0
        private string ShrinkAudio(string original, string newPathRoot)
        {
            Debug.WriteLine("ShrinkAudio " + original);

            var newPath = newPathRoot + ".mp3";

            if (File.Exists(newPath))
            {
                File.Delete(newPath);
            }

            var result = FFmpegRunner.MakeLowQualityCompressedAudio(original, newPath, _progress);

            CheckForError(result);
            return(newPath);
        }
示例#8
0
        static void StartFfmpeg()
        {
            var ffmpegRunner = new FFmpegRunner(
                /*@"D:\Dev\GitHub\AviSynthFakeFFmpegInjector\AviSynthFFmpegInjector\Build\VS\x64\Debug\ffmpeg.exe"*/
                @"L:\temp\ffmpeg-4.0.2-win64-static\bin\ffmpeg.exe");

            ffmpegRunner.Start();
            //var startInfo = new ProcessStartInfo();
            //startInfo.FileName =
            //    @"D:\Dev\GitHub\AviSynthFakeFFmpegInjector\AviSynthFFmpegInjector\Build\VS\x64\Debug\ffmpeg.exe";
            //startInfo.Arguments =
            //    //@" -v info -i SCRIPT.avs -aspect 16:9 -c:v h264_nvenc -rc constqp -preset hq OUT.mp4";
            //    @" -v info -i SCRIPT.avs -aspect 16:9 -c:v h264_qsv -rc constqp -preset medium OUT.mp4";
            //// for intel, possible presets: veryfast, faster, fast, medium, slow, slower, veryslow  (https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/cloud-computing-quicksync-video-ffmpeg-white-paper.pdf)
            //startInfo.WorkingDirectory =
            //    @"D:\Dev\GitHub\AviSynthFakeFFmpegInjector\AviSynthFFmpegInjector\Build\VS\x64\Debug\";
            //var env = startInfo.EnvironmentVariables;
            //startInfo.CreateNoWindow = false;

            //Process.Start(startInfo);
        }