private void SplitWithFadeout(string inputFile, List <double> splitPoints,
                                      string sFadeLength)
        {
            const int sampleRate  = 44100;
            string    outFilename = inputFile + "_fadeout.m4a";

            if (!double.TryParse(sFadeLength, out double fadeLength) || fadeLength <= 0)
            {
                throw new CsDownloadVidException("Invalid fadelength, expected a number of " +
                                                 "seconds like 4");
            }
            else if (splitPoints.Count == 0)
            {
                throw new CsDownloadVidException("Enter a time, in seconds");
            }
            else if (splitPoints.Count != 1)
            {
                throw new CsDownloadVidException("It looks like you have entered more than " +
                                                 "one time point. Please enter just one time, in seconds.");
            }
            else if (!inputFile.EndsWith(".m4a"))
            {
                throw new CsDownloadVidException("We currently only support adding fadeout " +
                                                 "for m4a files (if you have a .mp4 song, please rename it to .m4a first).");
            }
            else if (File.Exists(outFilename))
            {
                throw new CsDownloadVidException("Output file already exists " + outFilename);
            }

            // preemptively make sure we have a path to qaac.
            CsDownloadVidFilepaths.GetQaac();

            // run all in a separate thread, so that UI remains responsive.
            _runner.RunInThread(() =>
            {
                var log = "";
                new AddFadeoutUsingRawAacData().Go(inputFile, sampleRate, splitPoints[0],
                                                   fadeLength, outFilename, ref log);

                _runner.TraceFiltered(log.Replace("\n", Utils.NL));
                _runner.Trace(File.Exists(outFilename) ? "Successfully saved to " + outFilename :
                              "Error(s) occurred");
            });
        }
Пример #2
0
        string ConvertWavToM4aSynchronous(string input, string bitrate, ref string log)
        {
            var outFilename = Path.GetDirectoryName(input) + Utils.Sep +
                              Path.GetFileNameWithoutExtension(input) + ".m4a";

            var args = new List <string>();

            args.Add("--quality");
            args.Add("2");
            args.Add("-a");
            args.Add(bitrate);
            args.Add("--rate");
            args.Add("keep");
            args.Add(input);
            args.Add("-d");
            args.Add(Path.GetDirectoryName(input));

            RunGetStdout(CsDownloadVidFilepaths.GetQaac(),
                         Utils.CombineProcessArguments(args.ToArray()),
                         "convert to m4a", outFilename, ref log);

            Utils.AssertTrue(File.Exists(outFilename));
            return(outFilename);
        }