Example #1
0
        // TODO: 变更编码参数
        public QAACEncoder(AudioJob j, int bitrate = Constants.QAACBitrate) : base()
        {
            if (j.Input != "-")
            { //not from stdin, but an actual file
                j.Input = $"\"{j.Input}\"";
            }

            executable  = Constants.QAACPath;
            commandLine = $"-i -v {bitrate} -q 2 --no-delay -o \"{j.Output}\" {j.Input}";
        }
Example #2
0
        // TODO: 变更编码参数
        public QAACEncoder(string QAACPath, AudioJob j, int bitrate = 128) : base()
        {
            if (j.Input == "-")
            {
                // stdin
            }

            executable  = QAACPath;
            commandLine = "-i -v " + bitrate + " -q 2 --no-delay -o " + j.Output + " " + j.Input;
        }
Example #3
0
        // TODO: 变更编码参数
        public FLACDecoder(string FlacPath, AudioJob j) : base()
        {
            commandLine = "-d ";
            if (j.Output == "-")
            {
                commandLine += "--stdout ";
            }
            else if (j.Output != "")
            {
                commandLine += "-o " + j.Output;
            }

            if (Path.GetExtension(j.Input) == ".flac")
            {
                commandLine += j.Input;
            }

            executable = FlacPath;
        }
Example #4
0
        public void Start()
        {
            // TODO: 只考虑完整的视频压制流程
            if (job.JobType != "video")
            {
                return;
            }

            VideoJob vjob = job as VideoJob;

            // 抽取音轨
            FileInfo eacInfo = new FileInfo(".\\tools\\eac3to\\eac3to.exe");

            if (!eacInfo.Exists)
            {
                throw new Exception("Eac3to 不存在");
            }
            EACDemuxer eac         = new EACDemuxer(eacInfo.FullName, vjob.config.InputFile);
            var        audioTracks = eac.Extract((double progress, EACProgressType type) => {
                switch (type)
                {
                case EACProgressType.Analyze:
                    vjob.config.Status        = "轨道分析中";
                    vjob.config.ProgressValue = progress;
                    break;

                case EACProgressType.Process:
                    vjob.config.Status        = "抽取音轨中";
                    vjob.config.ProgressValue = progress;
                    break;

                case EACProgressType.Completed:
                    vjob.config.Status        = "音轨抽取完毕";
                    vjob.config.ProgressValue = progress;
                    break;

                default:
                    return;
                }
            });

            // 默认列表是按照顺序来
            string audioTrack = audioTracks[0].OutFileName;

            // 音频转码
            List <string> audioFile = new List <string>();

            foreach (var track in vjob.config.AudioTracks)
            {
                var    audioOutput  = audioTracks[track.TrackId];
                string audioOutpath = audioOutput.OutFileName;

                if (track.Format.ToUpper() == "AAC")
                {
                    vjob.config.Status        = "音轨转码中";
                    vjob.config.ProgressValue = -1;

                    if (audioOutput.FileExtension == ".flac")
                    {
                        AudioJob aDecode = new AudioJob("WAV");
                        aDecode.Input  = audioOutput.OutFileName;
                        aDecode.Output = "-";
                        FLACDecoder flac = new FLACDecoder(".\\tools\\flac\\flac.exe", aDecode);

                        AudioJob aEncode = new AudioJob("AAC");
                        aEncode.Input  = "-";
                        aEncode.Output = Path.ChangeExtension(audioOutpath, ".aac");
                        QAACEncoder qaac = new QAACEncoder(".\\tools\\qaac\\qaac.exe", aEncode, track.Bitrate);

                        CMDPipeJobProcessor cmdpipe = CMDPipeJobProcessor.NewCMDPipeJobProcessor(flac, qaac);
                        cmdpipe.start();
                        cmdpipe.waitForFinish();

                        audioOutpath = aEncode.Output;
                    }
                }

                var audioFileInfo = new FileInfo(audioOutpath);
                if (audioFileInfo.Length < 1024)
                {
                    // 无效音轨
                    // TODO: 提示用户不能封装
                    File.Move(audioOutpath, Path.ChangeExtension(audioOutpath, ".bak") + audioFileInfo.Extension);
                    continue;
                }

                if (!track.SkipMuxing)
                {
                    audioFile.Add(audioOutpath);
                }
            }

            vjob.config.Status = "获取信息中";
            IJobProcessor processor = x265Encoder.init(vjob, vjob.config.EncoderParam);

            vjob.config.Status        = "压制中";
            vjob.config.ProgressValue = 0.0;
            processor.start();
            processor.waitForFinish();

            if (vjob.config.ContainerFormat != "")
            {
                // 封装
                vjob.config.Status = "封装中";
                FileInfo mkvInfo = new FileInfo(".\\tools\\mkvtoolnix\\mkvmerge.exe");
                if (!mkvInfo.Exists)
                {
                    throw new Exception("mkvmerge不存在");
                }

                FileInfo lsmash = new FileInfo(".\\tools\\l-smash\\muxer.exe");
                if (!lsmash.Exists)
                {
                    throw new Exception("l-smash 封装工具不存在");
                }

                AutoMuxer muxer = new AutoMuxer(mkvInfo.FullName, lsmash.FullName);
                muxer.ProgressChanged += progress => vjob.config.ProgressValue = progress;

                List <string> mergeList = new List <string> {
                    vjob.config.InputFile + ".hevc",
                    Path.ChangeExtension(vjob.config.InputFile, ".txt"),
                };
                mergeList.AddRange(audioFile);

                muxer.StartMerge(mergeList, vjob.Output);
            }

            vjob.config.Status        = "完成";
            vjob.config.ProgressValue = 100;
        }