public static void Encode()
        {
            // Skips Audio Encoding if the audio file already exist
            if (File.Exists(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv")) == false)
            {
                //Creates Audio Directory in the temp dir
                if (!Directory.Exists(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio")))
                {
                    Directory.CreateDirectory(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio"));
                }
                string audio_command = "";

                int end_index = 0;
                if (MainWindow.trackOne)
                {
                    audio_command += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackOne, 0, end_index, MainWindow.audioCodecTrackOne, MainWindow.audioChannelsTrackOne, MainWindow.trackOneLanguage, MainWindow.trackOneName);
                    end_index     += 1;
                }
                if (MainWindow.trackTwo)
                {
                    audio_command += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackTwo, 1, end_index, MainWindow.audioCodecTrackTwo, MainWindow.audioChannelsTrackTwo, MainWindow.trackTwoLanguage, MainWindow.trackTwoName);
                    end_index     += 1;
                }
                if (MainWindow.trackThree)
                {
                    audio_command += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackThree, 2, end_index, MainWindow.audioCodecTrackThree, MainWindow.audioChannelsTrackThree, MainWindow.trackThreeLanguage, MainWindow.trackThreeName);
                    end_index     += 1;
                }
                if (MainWindow.trackFour)
                {
                    audio_command += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackFour, 3, end_index, MainWindow.audioCodecTrackFour, MainWindow.audioChannelsTrackFour, MainWindow.trackFourLanguage, MainWindow.trackFourName);
                }

                if (MainWindow.audioCodecTrackOne != "Copy Audio" && MainWindow.audioCodecTrackTwo != "Copy Audio" && MainWindow.audioCodecTrackThree != "Copy Audio" && MainWindow.audioCodecTrackFour != "Copy Audio")
                {
                    audio_command += " -af aformat=channel_layouts=" + '\u0022' + "7.1|5.1|stereo|mono" + '\u0022' + " ";
                }

                // ══════════════════════════════════════ Audio Encoding ══════════════════════════════════════
                string ffmpegAudioCommands = "/C ffmpeg.exe -y -i " + '\u0022' + MainWindow.VideoInput + '\u0022' + " " + MainWindow.TrimCommand + " -map_metadata -1 -vn -sn -dn " + audio_command + " " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv") + '\u0022';
                SmallFunctions.Logging("Encoding Audio: " + ffmpegAudioCommands);
                SmallFunctions.ExecuteFfmpegTask(ffmpegAudioCommands);
                // ════════════════════════════════════════════════════════════════════════════════════════════
            }
        }
Пример #2
0
        public static async Task Concat()
        {
            // ══════════════════════════════════════ Chunk Parsing ══════════════════════════════════════
            // Writes all ivf files into chunks.txt for later concat
            var sorted = Directory.GetFiles(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Chunks"), "*.ivf").OrderBy(f => f);

            using (StreamWriter outputFile = new StreamWriter(Path.Combine(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Chunks"), "chunks.txt")))
            {
                foreach (var fileTemp in sorted)
                {
                    string tempName = fileTemp.Replace("'", "'\\''");
                    outputFile.WriteLine("file '" + tempName + "'");
                }
            }

            bool   audio = MainWindow.trackOne || MainWindow.trackTwo || MainWindow.trackThree || MainWindow.trackFour;
            bool   vfr   = MainWindow.VFRVideo;
            bool   sub   = MainWindow.subSoftSubEnabled;
            string ffmpegCommand;

            // Replace ' with "'", else muxing will fail with single quotes in filename
            MainWindow.TempPathFileName.Replace("'", "\"'\"");

            if (!audio && !vfr && !sub)
            {
                ffmpegCommand = "/C ffmpeg.exe -y -f concat -safe 0 -i " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Chunks", "chunks.txt") + '\u0022' + " -c copy " + '\u0022' + MainWindow.VideoOutput + '\u0022';
                SmallFunctions.Logging("Muxing: " + ffmpegCommand);
                await Task.Run(() => SmallFunctions.ExecuteFfmpegTask(ffmpegCommand));
            }
            else
            {
                // First Concats the video to a temp.mkv file
                ffmpegCommand = "/C ffmpeg.exe -y -f concat -safe 0 -i " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Chunks", "chunks.txt") + '\u0022' + " -c copy " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022';
                SmallFunctions.Logging("Muxing: " + ffmpegCommand);
                await Task.Run(() => SmallFunctions.ExecuteFfmpegTask(ffmpegCommand));
            }


            if (audio)
            {
                if (!sub)
                {
                    if (!vfr)
                    {
                        // Muxes Video & Audio together (required for MP4 output)
                        ffmpegCommand = "/C ffmpeg.exe -y -i " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022' + " -i " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv") + '\u0022' + " -map 0:v -map 1:a -c copy " + '\u0022' + MainWindow.VideoOutput + '\u0022';
                        SmallFunctions.Logging("Muxing: " + ffmpegCommand);
                        await Task.Run(() => SmallFunctions.ExecuteFfmpegTask(ffmpegCommand));
                    }
                    else
                    {
                        // Run mkvmerge command - only supports mkv / webm
                        string mkvmergeCommand = "/C mkvmerge.exe --output " + '\u0022' + MainWindow.VideoOutput + '\u0022' + " " + MainWindow.VFRCMD + " --language 0:und --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022' + " --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv") + '\u0022';
                        SmallFunctions.Logging("Muxing: " + mkvmergeCommand);
                        await Task.Run(() => SmallFunctions.ExecuteMKVMergeTask(mkvmergeCommand));
                    }
                }
                else
                {
                    // Muxes Video & Audio & Subtitles together - MP4 not supported - also supports VFR
                    string mkvmergeCommand = "/C mkvmerge.exe --output " + '\u0022' + MainWindow.VideoOutput + '\u0022' + " " + MainWindow.VFRCMD + " --language 0:und --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022' + " --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv") + '\u0022' + " " + MainWindow.subCommand;
                    SmallFunctions.Logging("Muxing: " + mkvmergeCommand);
                    await Task.Run(() => SmallFunctions.ExecuteMKVMergeTask(mkvmergeCommand));
                }
            }
            else if (!audio)
            {
                if (!sub)
                {
                    if (vfr)
                    {
                        // Run mkvmerge command with VFR Support
                        string mkvmergeCommand = "/C mkvmerge.exe --output " + '\u0022' + MainWindow.VideoOutput + '\u0022' + " " + MainWindow.VFRCMD + " --language 0:und --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022';
                        SmallFunctions.Logging("Muxing: " + mkvmergeCommand);
                        await Task.Run(() => SmallFunctions.ExecuteMKVMergeTask(mkvmergeCommand));
                    }
                }
                else
                {
                    // Muxes Video & Subtitles together
                    string mkvmergeCommand = "/C mkvmerge.exe --output " + '\u0022' + MainWindow.VideoOutput + '\u0022' + " " + MainWindow.VFRCMD + " --language 0:und --default-track 0:yes " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "temp.mkv") + '\u0022' + " " + MainWindow.subCommand;
                    SmallFunctions.Logging("Muxing: " + mkvmergeCommand);
                    await Task.Run(() => SmallFunctions.ExecuteMKVMergeTask(mkvmergeCommand));
                }
            }
        }
Пример #3
0
        public static void Check()
        {
            // Sets / Checks ffmpeg Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "ffmpeg.exe")))
            {
                MainWindow.FFmpegPath = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "ffmpeg", "ffmpeg.exe")))
            {
                MainWindow.FFmpegPath = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "ffmpeg");
            }
            else if (ExistsOnPath("ffmpeg.exe"))
            {
                MainWindow.FFmpegPath = GetFullPathWithOutName("ffmpeg.exe");
            }
            else
            {
                MainWindow.FFmpegPath = null;
            }
            SmallFunctions.Logging("FFmpeg Path: " + MainWindow.FFmpegPath);

            // Sets / Checks aomenc Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "aomenc.exe")))
            {
                MainWindow.AomencPath = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "aomenc", "aomenc.exe")))
            {
                MainWindow.AomencPath = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "aomenc");
            }
            else if (ExistsOnPath("aomenc.exe"))
            {
                MainWindow.AomencPath = GetFullPathWithOutName("aomenc.exe");
            }
            else
            {
                MainWindow.AomencPath = null;
            }
            SmallFunctions.Logging("Aomenc Path: " + MainWindow.AomencPath);

            // Sets / Checks rav1e Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "rav1e.exe")))
            {
                MainWindow.Rav1ePath = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "rav1e", "rav1e.exe")))
            {
                MainWindow.Rav1ePath = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "rav1e");
            }
            else if (ExistsOnPath("rav1e.exe"))
            {
                MainWindow.Rav1ePath = GetFullPathWithOutName("rav1e.exe");
            }
            else
            {
                MainWindow.Rav1ePath = null;
            }
            SmallFunctions.Logging("Rav1e Path: " + MainWindow.Rav1ePath);

            // Sets / Checks svt-av1 Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "SvtAv1EncApp.exe")))
            {
                MainWindow.SvtAV1Path = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "svt-av1", "SvtAv1EncApp.exe")))
            {
                MainWindow.SvtAV1Path = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "svt-av1");
            }
            else if (ExistsOnPath("SvtAv1EncApp.exe"))
            {
                MainWindow.SvtAV1Path = GetFullPathWithOutName("SvtAv1EncApp.exe");
            }
            else
            {
                MainWindow.SvtAV1Path = null;
            }
            SmallFunctions.Logging("SVT-AV1 Path: " + MainWindow.SvtAV1Path);

            // Sets / Checks vpx Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "vpxenc.exe")))
            {
                MainWindow.VPXPath = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "vpx", "vpxenc.exe")))
            {
                MainWindow.VPXPath = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "vpx");
            }
            else if (ExistsOnPath("vpxenc.exe"))
            {
                MainWindow.VPXPath = GetFullPathWithOutName("vpxenc.exe");
            }
            else
            {
                MainWindow.VPXPath = null;
            }
            SmallFunctions.Logging("VPXEnc Path: " + MainWindow.VPXPath);

            // Sets / Checks mkvtoolnix Path
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "mkvmerge.exe")))
            {
                MainWindow.MKVToolNixPath = Directory.GetCurrentDirectory();
            }
            else if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Apps", "mkvtoolnix", "mkvmerge.exe")))
            {
                MainWindow.MKVToolNixPath = Path.Combine(Directory.GetCurrentDirectory(), "Apps", "mkvtoolnix");
            }
            else if (ExistsOnPath("mkvmerge.exe"))
            {
                MainWindow.MKVToolNixPath = GetFullPathWithOutName("mkvmerge.exe");
            }
            else if (File.Exists(@"C:\Program Files\MKVToolNix\mkvmerge.exe"))
            {
                MainWindow.MKVToolNixPath = @"C:\Program Files\MKVToolNix\";
            }
            else
            {
                MainWindow.MKVToolNixPath = null;
            }
            SmallFunctions.Logging("MKVToolNix Path: " + MainWindow.MKVToolNixPath);

            // Checks if PySceneDetect is found in the Windows PATH environment
            if (ExistsOnPath("scenedetect.exe"))
            {
                MainWindow.PySceneFound = true;
            }
            SmallFunctions.Logging("PySceneDetect found: " + MainWindow.PySceneFound);

            NotifyUser();
        }
Пример #4
0
        public static void Encode()
        {
            // Skips Audio Encoding if the audio file already exist
            if (File.Exists(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv")) == false)
            {
                //Creates Audio Directory in the temp dir
                if (!Directory.Exists(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio")))
                {
                    Directory.CreateDirectory(Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio"));
                }
                string audioCodec   = "";
                int    activeTracks = 0;

                //Counts the number of active audio tracks for audio mapping purposes
                if (MainWindow.trackOne)
                {
                    activeTracks += 1;
                }
                if (MainWindow.trackTwo)
                {
                    activeTracks += 1;
                }
                if (MainWindow.trackThree)
                {
                    activeTracks += 1;
                }
                if (MainWindow.trackFour)
                {
                    activeTracks += 1;
                }

                if (activeTracks == 1)
                {
                    audioCodec = OneTrackCommandGenerator(MainWindow.audioBitrateTrackOne, MainWindow.audioCodecTrackOne, MainWindow.audioChannelsTrackOne);
                }
                else if (activeTracks >= 2)
                {
                    if (MainWindow.trackOne == true)
                    {
                        audioCodec += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackOne, "0", MainWindow.audioCodecTrackOne, MainWindow.audioChannelsTrackOne, MainWindow.trackOneLanguage);
                    }
                    if (MainWindow.trackTwo == true)
                    {
                        audioCodec += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackTwo, "1", MainWindow.audioCodecTrackTwo, MainWindow.audioChannelsTrackTwo, MainWindow.trackTwoLanguage);
                    }
                    if (MainWindow.trackThree == true)
                    {
                        audioCodec += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackThree, "2", MainWindow.audioCodecTrackThree, MainWindow.audioChannelsTrackThree, MainWindow.trackThreeLanguage);
                    }
                    if (MainWindow.trackFour == true)
                    {
                        audioCodec += MultipleTrackCommandGenerator(MainWindow.audioBitrateTrackFour, "3", MainWindow.audioCodecTrackFour, MainWindow.audioChannelsTrackFour, MainWindow.trackFourLanguage);
                    }
                    if (MainWindow.audioCodecTrackOne != "Copy Audio" && MainWindow.audioCodecTrackTwo != "Copy Audio" && MainWindow.audioCodecTrackThree != "Copy Audio" && MainWindow.audioCodecTrackFour != "Copy Audio")
                    {
                        audioCodec += " -af aformat=channel_layouts=" + '\u0022' + "7.1|5.1|stereo|mono" + '\u0022' + " ";
                    }
                }

                // ══════════════════════════════════════ Audio Encoding ══════════════════════════════════════
                string ffmpegAudioCommands = "/C ffmpeg.exe -y -i " + '\u0022' + MainWindow.VideoInput + '\u0022' + " " + MainWindow.TrimCommand + " -map_metadata -1 -vn -sn -dn " + audioCodec + " " + '\u0022' + Path.Combine(MainWindow.TempPath, MainWindow.TempPathFileName, "Audio", "audio.mkv") + '\u0022';
                SmallFunctions.Logging("Encoding Audio: " + ffmpegAudioCommands);
                SmallFunctions.ExecuteFfmpegTask(ffmpegAudioCommands);
                // ════════════════════════════════════════════════════════════════════════════════════════════
            }
        }