コード例 #1
0
		public FormatSelector(CommandLineBuilder builder, IList<MediaFormat> forbiddenFormat, IList<VideoEncoding> forbiddenVideoCodec, IList<AudioEncoding> forbiddenAudioCodec) {
			InitializeComponent();
			
			_builder = builder;
			
			cbFormat.DataSource = Enum.GetValues(typeof(MediaFormat))
				.Cast<MediaFormat>()
				.Where(p => { return forbiddenFormat == null || !forbiddenFormat.Contains(p); })
				.Select(p => new { Key = p.LongName(), Value = p.Command() })
				.ToList();
			cbFormat.DisplayMember = "Key";
			cbFormat.ValueMember = "Value";
			
			cbCV.DataSource = Enum.GetValues(typeof(VideoEncoding))
				.Cast<VideoEncoding>()
				.Where(p => { return forbiddenVideoCodec == null || !forbiddenVideoCodec.Contains(p); })
				.Select(p => new { Key = p.LongName(), Value = (int)p })
				.ToList();
			cbCV.DisplayMember = "Key";
			cbCV.ValueMember = "Value";
			
			cbCA.DataSource = Enum.GetValues(typeof(AudioEncoding))
				.Cast<AudioEncoding>()
				.Where(p => { return forbiddenAudioCodec == null || !forbiddenAudioCodec.Contains(p); })
				.Select(p => new { Key = p.LongName(), Value = (int)p })
				.ToList();
			cbCA.DisplayMember = "Key";
			cbCA.ValueMember = "Value";
			
			cbBA.DataSource = Enum.GetValues(typeof(BitrateMp3))
				.Cast<BitrateMp3>()
				.Select(p => new { Key = p.ToString() + (p == BitrateMp3.Defaut ? string.Empty : " (" + ((int)p).ToString() + ")"), Value = (int)p })
				.ToList();
			cbBA.DisplayMember = "Key";
			cbBA.ValueMember = "Value";
			
			cbSR.DataSource = Enum.GetValues(typeof(SamplingRate))
				.Cast<SamplingRate>()
				.Select(p => new { Key = p.ToString() + (p == SamplingRate.Defaut ? string.Empty : " (" + ((int)p).ToString() + ")"), Value = (int)p })
				.ToList();
			cbSR.DisplayMember = "Key";
			cbSR.ValueMember = "Value";
		}
コード例 #2
0
		public FilterComplexBuilder(CommandLineBuilder owner) {
			_owner = owner;
			PreviousOutput = "[0:v]";
			CurrentOperation = 0;
		}
コード例 #3
0
		public ConcatSelector() {
			InitializeComponent();
			Builder = new CommandLineBuilder();
			Mode = ConcatMode.Undefined;
			lblMode.Text = Mode.LongName();
		}
コード例 #4
0
 public FilterComplexBuilder(CommandLineBuilder owner)
 {
     _owner           = owner;
     PreviousOutput   = "[0:v]";
     CurrentOperation = 0;
 }
コード例 #5
0
		public FormatSelector(CommandLineBuilder builder) : this(builder, new List<MediaFormat>(), new List<VideoEncoding>(), new List<AudioEncoding>()) {}
コード例 #6
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;
            }
        }
コード例 #7
0
ファイル: Execution.cs プロジェクト: tika06/GUI-ffmpeg
        public static void Concat(IList <string> files)
        {
            if (!ffmpegPresent() || !ffprobePresent())
            {
                return;
            }
            try {
                CommandLineBuilder builder = null;
                using (ConcatSelector cs = new ConcatSelector()) {
                    if (files != null)
                    {
                        int j = 0;
                        for (int i = 0; i < files.Count && j < 3; i++)
                        {
                            if (!string.IsNullOrWhiteSpace(files[i]))
                            {
                                if (File.Exists(files[i]) && MediaInfo.Check(files[i], null, null))
                                {
                                    cs.SetSelection(i, files[i]);
                                    if (j++ == 0)
                                    {
                                        cs.Lock1stLine();
                                    }
                                }
                            }
                        }
                    }
                    if (cs.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    builder = cs.Builder;

                    // Choix du format de sortie
                    using (FormatSelector fs = new FormatSelector(
                               builder,
                               cs.Mode == ConcatMode.Audio ? Common.GetVideoFormats(new MediaFormat[] { MediaFormat.DEFAULT }) : Common.GetAudioFormats(new MediaFormat[] { MediaFormat.DEFAULT }),
                               new VideoEncoding[] { VideoEncoding.COPY, VideoEncoding.DEFAULT, VideoEncoding.NOVIDEO },
                               new AudioEncoding[] { AudioEncoding.COPY, AudioEncoding.DEFAULT, AudioEncoding.NOAUDIO })
                           ) {
                        if (cs.Mode == ConcatMode.Video)
                        {
                            fs.DisableAudio();
                        }
                        if (cs.Mode == ConcatMode.Audio)
                        {
                            fs.DisableVideo();
                        }
                        if (fs.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Tout type de fichier media|*.*";
                if (sfd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                string str = builder.Output(sfd.FileName);

                LogWindow lw = new LogWindow();
                lw.Show();
                using (Process p = new Process()) {
                    ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, str);
                    psi.UseShellExecute       = false;
                    psi.CreateNoWindow        = true;
                    psi.RedirectStandardError = true;
                    p.StartInfo = psi;
                    p.Start();
                    string line;
                    while ((line = p.StandardError.ReadLine()) != null)
                    {
                        lw.Log(line);
                        Application.DoEvents();
                    }
                    p.WaitForExit();
                }
                lw.Log("\r\n---------------------------------------------\r\nFin de l'opération\r\n---------------------------------------------");
                lw.CanBeClosed = true;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
コード例 #8
0
ファイル: Execution.cs プロジェクト: tika06/GUI-ffmpeg
        public static void GetMp3(IList <string> files)
        {
            if (!ffmpegPresent() || !ffprobePresent())
            {
                return;
            }
            if (files == null)
            {
                throw new ArgumentNullException("files");
            }
            try {
                foreach (string path in files)
                {
                    // Checks
                    if (!File.Exists(path))
                    {
                        MessageBox.Show("Le fichier demandé n'existe pas !\r\n" + path);
                        continue;
                    }
                    if (!MediaInfo.Check(path, null, true, true))
                    {
                        continue;
                    }

                    // Processing
                    using (SaveFileDialog sfd = new SaveFileDialog()) {
                        sfd.Title      = "Sortie : " + Path.GetFileName(path);
                        sfd.Filter     = "Fichier de sortie mp3|*.mp3";
                        sfd.DefaultExt = "mp3";
                        if (sfd.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        LogWindow lw = new LogWindow();
                        lw.Show();
                        using (Process p = new Process()) {
                            ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, CommandLineBuilder.ExtractMp3(path, sfd.FileName, BitrateMp3.Standard, SamplingRate.AudioCD));
                            psi.UseShellExecute       = false;
                            psi.CreateNoWindow        = true;
                            psi.RedirectStandardError = true;
                            p.StartInfo = psi;
                            p.Start();
                            string line;
                            while ((line = p.StandardError.ReadLine()) != null)
                            {
                                lw.Log(line);
                                Application.DoEvents();
                            }
                            p.WaitForExit();
                        }
                        lw.Log("\r\n---------------------------------------------\r\nFin de l'opération\r\n---------------------------------------------");
                        lw.CanBeClosed = true;
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
コード例 #9
0
		private void Cancel(object sender, EventArgs e) {
			_builder = null;
			this.DialogResult = DialogResult.Cancel;
		}
コード例 #10
0
		private void Validate(object sender, EventArgs e) {
			if(_media == null) {
				MessageBox.Show("Aucun fichier valable en entrée.");
				return;
			}
			
			if(tbOut.Text.Length == 0) {
				MessageBox.Show("Choisissez un fichier de sortie.");
				return;
			}
			
			if(tbFile.Text.Equals(tbOut.Text)) {
				MessageBox.Show(I18n.Get("ErrorSameInputOutput"));
				return;
			}
			
			_builder = new CommandLineBuilder();
			_builder.AddEntry(tbFile.Text);
			
			int tmp;
			if(gbVideo.Enabled) {
				// Vérification CRF
				if(tbCRF.Text.Length != 0) {
					if(!int.TryParse(tbCRF.Text, out tmp)) {
						MessageBox.Show(string.Format(I18n.Get("FormatCrf"), Common.CRF_MIN, Common.CRF_MAX));
						_builder = null;
						return;
					}
					if(tmp < Common.CRF_MIN || tmp > Common.CRF_MAX) {
						MessageBox.Show(string.Format(I18n.Get("FormatCrf"), Common.CRF_MIN, Common.CRF_MAX));
						_builder = null;
						return;
					}
					_builder.Param(Parameter.V_CRF, tbCRF.Text);
				}
				
				// Vérification Qscale
				if(tbQscale.Text.Length != 0) {
					if(!int.TryParse(tbQscale.Text, out tmp)) {
						MessageBox.Show(string.Format(I18n.Get("FormatQscale"), Common.QSCALE_MIN, Common.QSCALE_MAX));
						_builder = null;
						return;
					}
					if(tmp < Common.QSCALE_MIN || tmp > Common.QSCALE_MAX) {
						MessageBox.Show(string.Format(I18n.Get("FormatQscale"), Common.QSCALE_MIN, Common.QSCALE_MAX));
						_builder = null;
						return;
					}
					_builder.Param(Parameter.V_QSCALE, tbQscale.Text);
				}
				
				// Vérification Qmin
				int qmin = 4;
				if(tbQmin.Text.Length != 0) {
					if(!int.TryParse(tbQmin.Text, out qmin)) {
						MessageBox.Show(string.Format(I18n.Get("FormatQmin"), Common.QMIN_MIN, Common.QMIN_MAX));
						_builder = null;
						return;
					}
					if(qmin < Common.QMIN_MIN || qmin > Common.QMIN_MAX) {
						MessageBox.Show(string.Format(I18n.Get("FormatQmin"), Common.QMIN_MIN, Common.QMIN_MAX));
						_builder = null;
						return;
					}
					_builder.Param(Parameter.V_QMIN, tbQmin.Text);
				}
				
				// Vérification Qmax
				if(tbQmax.Text.Length != 0) {
					if(!int.TryParse(tbQmax.Text, out tmp)) {
						MessageBox.Show(string.Format(I18n.Get("FormatQmax"), qmin, Common.QMAX_MAX));
						_builder = null;
						return;
					}
					if(tmp < qmin || tmp > Common.QMAX_MAX) {
						MessageBox.Show(string.Format(I18n.Get("FormatQmax"), qmin, Common.QMAX_MAX));
						_builder = null;
						return;
					}
					_builder.Param(Parameter.V_QMAX, tbQmax.Text);
				}
				
				// Vérification Bitrate
				if(tbBV.Text.Length != 0) {
					bool unit = tbBV.Text.EndsWith("k", StringComparison.CurrentCultureIgnoreCase) || tbBV.Text.EndsWith("m", StringComparison.CurrentCultureIgnoreCase);
					if(!int.TryParse(unit ? tbBV.Text.Substring(0, tbBV.Text.Length - 1) : tbBV.Text, out tmp)) {
						MessageBox.Show(I18n.Get("FormatBitrate"));
						_builder = null;
						return;
					}
					if(tmp <= 0) {
						MessageBox.Show(I18n.Get("FormatBitrate"));
						_builder = null;
						return;
					}
					_builder.Param(Parameter.V_BITRATE, tbBV.Text);
				}
				
				_builder.VideoCodec((VideoEncoding)cbCV.SelectedValue);
			} else {
				_builder.VideoCodec(VideoEncoding.NOVIDEO);
			}
			
			if(gbAudio.Enabled) {
				_builder.AudioCodec((AudioEncoding)cbCA.SelectedValue);
				BitrateMp3 br = (BitrateMp3)Enum.Parse(typeof(BitrateMp3), cbBA.SelectedValue.ToString());
				if(br != BitrateMp3.Defaut)
					_builder.Param(Parameter.A_BITRATE, ((int)br).ToString());
				SamplingRate sr = (SamplingRate)Enum.Parse(typeof(SamplingRate), cbSR.SelectedValue.ToString());
				if(sr != SamplingRate.Defaut)
					_builder.Param(Parameter.A_SAMPLE, ((int)sr).ToString());
			} else {
				_builder.AudioCodec(AudioEncoding.NOAUDIO);
			}
			
			_builder.Param(Parameter.NONE, cbFormat.SelectedValue.ToString()).Param(Parameter.MISC_OVERWRITE_YES);
			
			this.DialogResult = DialogResult.OK;
		}