Пример #1
0
        private void SetSelection(int index, string file, TextBox tb, Label lbAudio, Label lbVideo)
        {
            try {
                _medias[index] = MediaInfo.Query(file);
                tb.Text        = file;
                if (_medias[index].VideoInfo != null)
                {
                    lbVideo.Text = I18n.Get("ConcatVideoStreamHeadDesc") +
                                   _medias[index].VideoInfo.codec_name + " - " +
                                   _medias[index].VideoInfo.width.ToString() + "x" + _medias[index].VideoInfo.height.ToString() + " - " +
                                   _medias[index].VideoInfo.duration.ToString() + "s" +
                                   (_medias[index].VideoInfo.bit_rateSpecified ? " - Bitrate " + _medias[index].VideoInfo.bit_rate.ToReadableString() : string.Empty);
                }
                else
                {
                    lbVideo.Text = I18n.Get("ConcatNoVideoStream");
                }
                if (_medias[index].AudioInfo != null)
                {
                    lbAudio.Text = I18n.Get("ConcatAudioStreamHeadDesc") +
                                   _medias[index].AudioInfo.codec_name + " - " +
                                   _medias[index].AudioInfo.duration.ToString() + "s" +
                                   (_medias[index].AudioInfo.bit_rateSpecified ? " - Bitrate " + _medias[index].AudioInfo.bit_rate.ToReadableString() : string.Empty) +
                                   (_medias[index].AudioInfo.sample_rateSpecified ? " - SampleRate " + _medias[index].AudioInfo.sample_rate.ToReadableString() : string.Empty);
                }
                else
                {
                    lbAudio.Text = I18n.Get("ConcatNoAudioStream");
                }
            } catch (CoreException cex) {
                MessageBox.Show(cex.Message);
                _medias[index] = null;
                lbVideo.Text   = I18n.Get("ConcatNoVideoStream");
                lbAudio.Text   = I18n.Get("ConcatNoAudioStream");
                tb.Text        = string.Empty;
            }

            if (_medias[0] != null)
            {
                if (_medias[0].VideoInfo != null && _medias[0].AudioInfo != null)
                {
                    Mode = ConcatMode.Both;
                }
                else if (_medias[0].VideoInfo != null)
                {
                    Mode = ConcatMode.Video;
                }
                else
                {
                    Mode = ConcatMode.Audio;
                }
            }
            else if (_medias[1] != null)
            {
                if (_medias[1].VideoInfo != null && _medias[1].AudioInfo != null)
                {
                    Mode = ConcatMode.Both;
                }
                else if (_medias[1].VideoInfo != null)
                {
                    Mode = ConcatMode.Video;
                }
                else
                {
                    Mode = ConcatMode.Audio;
                }
            }
            else if (_medias[2] != null)
            {
                if (_medias[2].VideoInfo != null && _medias[2].AudioInfo != null)
                {
                    Mode = ConcatMode.Both;
                }
                else if (_medias[2].VideoInfo != null)
                {
                    Mode = ConcatMode.Video;
                }
                else
                {
                    Mode = ConcatMode.Audio;
                }
            }
            else
            {
                Mode = ConcatMode.Undefined;
            }
            lblMode.Text = Mode.LongName();
        }
Пример #2
0
        public void CreatePictures(string output)
        {
            if (_cancelFlag)
            {
                return;
            }

            string tn  = output.Substring(0, output.LastIndexOf(".")) + "-tn.png";
            string cde = "-ss 00:00:01 -i \"" + FileFullPath + "\"" + ParamI + " -vframes 1 -an" + ParamFilter + ParamOW + " \"" + output + "\"";

            SendLog("\r\nffmpeg " + cde);
            SendLog("------------------------------------------------------------");
            ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, cde);

            psi.UseShellExecute       = false;
            psi.CreateNoWindow        = true;
            psi.RedirectStandardError = true;
            using (Process p = new Process()) {
                p.StartInfo = psi;
                p.Start();
                string line;
                while ((line = p.StandardError.ReadLine()) != null)
                {
                    SendLog(line);
                    Application.DoEvents();
                }
                p.WaitForExit();
            }

            if (Thumbnail)
            {
                using (Image org = Image.FromFile(output)) {
                    Bitmap   bmp = new Bitmap(TnWidth, TnHeight);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.DrawImage(org, new Rectangle(0, 0, TnWidth, TnHeight));

                    if (LengthOnTn)
                    {
                        try {
                            MediaInfo mi = MediaInfo.Query(string.IsNullOrWhiteSpace(_outputForLength) ? FileFullPath : _outputForLength);
                            g.FillRectangle(Brushes.MidnightBlue, new Rectangle(5, 5, 45, 20));
                            g.DrawRectangle(Pens.Black, new Rectangle(5, 5, 45, 20));
                            using (Font f = new Font("Arial", 8, FontStyle.Bold))
                                g.DrawString(
                                    string.Format("{0:g}", new TimeSpan(0, 0, (int)Math.Round(mi.FormatInfo.duration))),
                                    f, new SolidBrush(Color.White),
                                    8,
                                    8
                                    );
                        } catch (Exception ex) {
                            SendLog(ex.Message);
                            SendLog(ex.StackTrace);
                        }
                    }
                    bmp.Save(tn, ImageFormat.Png);
                }
            }
            if (!Poster)
            {
                File.Delete(output);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public static void NoSound(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, true, true, true))
                    {
                        continue;
                    }

                    // Processing
                    using (SaveFileDialog sfd = new SaveFileDialog()) {
                        sfd.Title = "Sortie : " + Path.GetFileName(path);
                        string ext = Path.GetExtension(path);
                        sfd.Filter     = "*" + ext + "|*" + ext;
                        sfd.DefaultExt = ext.Substring(1);
                        if (sfd.ShowDialog() != DialogResult.OK)
                        {
                            continue;
                        }

                        LogWindow lw = new LogWindow();
                        lw.Show();
                        using (Process p = new Process()) {
                            ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, CommandLineBuilder.RemoveSound(path, sfd.FileName));
                            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);
            }
        }
Пример #5
0
		public static MediaInfo Query(string file) {
			if(!File.Exists(file))
				throw new CoreException(I18n.Get("ErrorFileNotExists"));
			if(!File.Exists(Common.ffprobe))
				throw new CoreException(I18n.Get("ErrorFfprobeNotFound"));
			StringBuilder xml = new StringBuilder();
			ProcessStartInfo psi = new ProcessStartInfo(Common.ffprobe, "-i \"" + file + "\" -v quiet -of xml -show_format -show_streams");
			psi.UseShellExecute = false;
			psi.CreateNoWindow = true;
			psi.RedirectStandardError = true;
			psi.RedirectStandardOutput = true;
			using(Process p = new Process()) {
				p.StartInfo = psi;
				p.Start();
				string line;
				while ((line = p.StandardOutput.ReadLine()) != null) {
					xml.AppendLine(line);
					Application.DoEvents();
				}
				p.WaitForExit();
			}
			MediaInfo mi = new MediaInfo(xml.ToString());
			if(mi.FormatInfo == null)
				throw new CoreException(I18n.Get("ErrorInvalidFormat"));
			if(mi.AudioInfo == null && mi.VideoInfo == null)
				throw new CoreException(I18n.Get("ErrorNoAudioVideo"));
			
			return mi;
		}
Пример #6
0
		private void SelectFile(object sender, EventArgs e) {
			using(OpenFileDialog ofd = new OpenFileDialog()) {
				ofd.Filter = I18n.Get("FilterAllMedia");
				if(ofd.ShowDialog() != DialogResult.OK)
					return;
				try {
					_media = MediaInfo.Query(ofd.FileName);
					tbFile.Text = ofd.FileName;
					if(_media.VideoInfo != null) {
						EnableVideo();
						lV.Text = I18n.Get("ConcatVideoStreamHeadDesc") +
							_media.VideoInfo.codec_name + " - " +
							_media.VideoInfo.width.ToString() + "x" + _media.VideoInfo.height.ToString()+ " - " +
							_media.VideoInfo.duration.ToString() + "s" +
							(_media.VideoInfo.bit_rateSpecified ? " - Bitrate " + _media.VideoInfo.bit_rate.ToReadableString() : string.Empty);
					} else {
						DisableVideo();
						lV.Text = I18n.Get("ConcatNoVideoStream");
					}
					if(_media.AudioInfo != null) {
						EnableAudio();
						lA.Text = I18n.Get("ConcatAudioStreamHeadDesc") +
							_media.AudioInfo.codec_name + " - " +
							_media.AudioInfo.duration.ToString() + "s" +
							(_media.AudioInfo.bit_rateSpecified ? " - Bitrate " + _media.AudioInfo.bit_rate.ToReadableString() : string.Empty) +
							(_media.AudioInfo.sample_rateSpecified ? " - SampleRate " + _media.AudioInfo.sample_rate.ToReadableString() : string.Empty);
					} else {
						DisableAudio();
						lA.Text = I18n.Get("ConcatNoAudioStream");
					}
				} catch(CoreException cex) {
					MessageBox.Show(cex.Message);
					_media = null;
					lV.Text = I18n.Get("ConcatNoVideoStream");
					lA.Text = I18n.Get("ConcatNoAudioStream");
					tbFile.Text = string.Empty;
				}
			}
		}