コード例 #1
0
        public void EncodeMP4(string output)
        {
            if (_cancelFlag)
            {
                return;
            }

            _outputForLength = output;
            CommandLineBuilder cb = new CommandLineBuilder();

            if (StartOffset != TimeSpan.Zero)
            {
                cb.Seek(string.Format("{0:c}", StartOffset));
            }

            cb.AddEntry(FileFullPath);

            for (int i = 0; i < Overlays.Length; i++)
            {
                if (Overlays[i].Item1 >= 0 && !string.IsNullOrWhiteSpace(Overlays[i].Item2))
                {
                    cb.AddEntry(Overlays[i].Item2);
                }
            }
            if (EndOffset != TimeSpan.Zero)
            {
                cb.To(string.Format("{0:c}", EndOffset - StartOffset));
            }

            if (!string.IsNullOrWhiteSpace(ResizeHeight) || !string.IsNullOrWhiteSpace(ResizeWidth))
            {
                cb.FilterComplex.Resize(ResizeWidth, ResizeHeight);
            }
            if (Rotate < 4)
            {
                cb.FilterComplex.Transpose((Transpose)Rotate);
            }
            int j = 1;

            for (int i = 0; i < Overlays.Length; i++)
            {
                if (Overlays[i].Item1 >= 0 && !string.IsNullOrWhiteSpace(Overlays[i].Item2))
                {
                    cb.FilterComplex.Overlay((Overlay)Overlays[i].Item1, string.Format("[{0}]", j++));
                }
            }

            cb.VideoCodec(VideoEncoding.X264).Param(Parameter.V_BITRATE, MP4_bv);

            if (NoSound)
            {
                cb.AudioCodec(AudioEncoding.NOAUDIO);
            }
            else
            {
                cb.AudioCodec(AudioEncoding.AAC).Param(Parameter.A_BITRATE, MP4_ba);
            }

            if (Overwrite)
            {
                cb.Param(Parameter.MISC_OVERWRITE_YES);
            }
            else
            {
                cb.Param(Parameter.MISC_OVERWRITE_NO);
            }

            string cde = cb.Output(output);

            SendLog("\r\nffmpeg " + cde);
            SendLog("------------------------------------------------------------");
            if (output.Equals(FileFullPath, StringComparison.CurrentCultureIgnoreCase))
            {
                SendLog(I18n.Get("ErrorSameInputOutput"));
            }
            else
            {
                ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, cde);
                psi.UseShellExecute       = false;
                psi.CreateNoWindow        = true;
                psi.RedirectStandardError = true;
                using (Process p = new Process()) {
                    _currentProcess = p;
                    p.StartInfo     = psi;
                    p.Start();
                    string line;
                    while ((line = p.StandardError.ReadLine()) != null)
                    {
                        SendLog(line);
                        Application.DoEvents();
                    }
                    p.WaitForExit();
                }
                _currentProcess = null;
            }
        }