Esempio n. 1
0
        public static string getMediaInfo(string mediaName)
        {
            /**
              * 支持视频格式:mpeg,mpg,avi,dat,mkv,rmvb,rm,mov.
              *不支持:wmv
              * **/

            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            //ffmpeg.exe的路径,程序会在执行目录(....FFmpeg测试\bin\Debug)下找此文件,
            enc.FFmpegPath = System.Environment.CurrentDirectory + "\\ffmpeg.exe";
            //视频路径
            VideoFile videoFile = new VideoFile(mediaName);

            enc.GetVideoInfo(videoFile);

            TimeSpan totaotp = videoFile.Duration;
            string totalTime = string.Format("{0:00}:{1:00}:{2:00}", (int)totaotp.TotalHours, totaotp.Minutes, totaotp.Seconds);

            Console.WriteLine("时间长度:{0}", totalTime);
            Console.WriteLine("高度:{0}", videoFile.Height);
            Console.WriteLine("宽度:{0}", videoFile.Width);
            Console.WriteLine("数据速率:{0}", videoFile.VideoBitRate);
            Console.WriteLine("数据格式:{0}", videoFile.VideoFormat);
            Console.WriteLine("比特率:{0}", videoFile.BitRate);
            Console.WriteLine("文件路径:{0}", videoFile.Path);

            return totalTime;
 
        }
Esempio n. 2
0
        public static string getMediaPlayTime(string mediaName)
        {
            /**
             * 支持视频格式:mpeg,mpg,avi,dat,mkv,rmvb,rm,mov.
             *不支持:wmv
             * **/

            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            //ffmpeg.exe的路径,程序会在执行目录(....FFmpeg测试\bin\Debug)下找此文件,
            enc.FFmpegPath = System.Environment.CurrentDirectory + "\\ffmpeg.exe";
            //视频路径
            VideoFile videoFile = new VideoFile(mediaName);

            enc.GetVideoInfo(videoFile);

            TimeSpan totaotp   = videoFile.Duration;
            string   totalTime = string.Format("{0:00}:{1:00}:{2:00}", (int)totaotp.TotalHours, totaotp.Minutes, totaotp.Seconds);

            //Console.WriteLine("时间长度:{0}", totalTime);
            //Console.WriteLine("高度:{0}", videoFile.Height);
            //Console.WriteLine("宽度:{0}", videoFile.Width);
            //Console.WriteLine("数据速率:{0}", videoFile.VideoBitRate);
            //Console.WriteLine("数据格式:{0}", videoFile.VideoFormat);
            //Console.WriteLine("比特率:{0}", videoFile.BitRate);
            //Console.WriteLine("文件路径:{0}", videoFile.Path);

            return(totalTime);
        }
Esempio n. 3
0
 public TimeSpan GetVideoTotalTime(string videoPath)
 {
     Encoder encoder = new Encoder {
         FFmpegPath = AppDomain.CurrentDomain.BaseDirectory + this.ffmpegTools
     };
     string path = videoPath;
     VideoFile input = new VideoFile(path);
     encoder.GetVideoInfo(input);
     return input.Duration;
 }
Esempio n. 4
0
        private void VideoSplitByTime()
        {
            int time = Int32.Parse(boxPartHour.Text) * 3600
                       + Int32.Parse(boxPartMin.Text) * 60
                       + Int32.Parse(boxPartSec.Text);

            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            enc.FFmpegPath = "ffmpeg.exe";
            VideoFile vf = new VideoFile(file);

            enc.GetVideoInfo(vf);
            TimeSpan t = vf.Duration;
            //int tt =(int)t.TotalSeconds;
            int parts = (int)t.TotalSeconds / time + 1;

            #region thread start

            //EnableUI(false);//Kullanıcı tıklaması için kapalı
            new Thread(() =>
            {
                for (int i = 0; i < parts; i++)
                {
                    Process p = new Process();
                    string ph = Environment.CommandLine;
                    ph        = ph.Substring(0, ph.LastIndexOf('\\') + 1);
                    if (ph[0] == '"')
                    {
                        ph = ph.Substring(1);
                    }
                    p.StartInfo.FileName  = "\"" + ph + "ffmpeg.exe\"";
                    p.StartInfo.Arguments = " -ss " + (i == 0 ? 0 : time * i - 10).ToString()
                                            + " -i " + "\"" + file + "\""
                                            + " -vcodec copy -acodec copy "
                                            + " -t " + (i == 0 ? time : (time + 10)).ToString() + " "
                                            + "\"" + path + (i + 1).ToString("00") + formate + "\"";
                    p.StartInfo.RedirectStandardError = true;
                    p.ErrorDataReceived        += new DataReceivedEventHandler(SplitOutput);
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.CreateNoWindow  = true;
                    p.Start();
                    p.BeginErrorReadLine();
                    p.WaitForExit();
                    p.Close();
                    p.Dispose();
                }

                this.BeginInvoke(new MethodInvoker(() =>
                {
                    EnableUI(true); //Kullanıcı tık açık
                }));
            }).Start();
            #endregion
        }
Esempio n. 5
0
        /// <summary>
        /// 获得视频总时长
        /// </summary>
        public TimeSpan GetVideoTotalTime(string videoPath)
        {
            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            //ffmpeg.exe的路径,程序会在执行目录下找此文件,
            enc.FFmpegPath = AppDomain.CurrentDomain.BaseDirectory + ffmpegTools;
            //视频路径
            string    videoFilePath = videoPath;
            VideoFile videoFile     = new VideoFile(videoFilePath);

            enc.GetVideoInfo(videoFile);

            TimeSpan totaotp = videoFile.Duration;

            return(totaotp);
        }
Esempio n. 6
0
        public static VideoFile GetVideoInfo(string iFile)
        {
            VideoEncoder.Encoder encoder = new VideoEncoder.Encoder();
            encoder.FFmpegPath = ffmpeg;
            VideoFile videoFile = new VideoFile(iFile);

            encoder.GetVideoInfo(videoFile);
            TimeSpan      duration      = videoFile.Duration;
            StringBuilder stringBuilder = new StringBuilder();
            string        arg           = $"{(int)duration.TotalHours:00}:{duration.Minutes:00}:{duration.Seconds:00}";

            stringBuilder.AppendFormat("时间长度:{0}\n", arg);
            stringBuilder.AppendFormat("高度:{0}\n", videoFile.Height);
            stringBuilder.AppendFormat("宽度:{0}\n", videoFile.Width);
            stringBuilder.AppendFormat("数据格式:{0}\n", videoFile.VideoFormat);
            stringBuilder.AppendFormat("比特率:{0}\n", videoFile.BitRate);
            stringBuilder.AppendFormat("文件路径:{0}\n", videoFile.File);
            return(videoFile);
        }
Esempio n. 7
0
        private void buttonSplit_Click(object sender, EventArgs e)
        {
            if (!textFlv.Text.EndsWith(".flv"))
            {
                MessageBox.Show("It's not flv file!", "not flv", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!File.Exists(textFlv.Text))
            {
                MessageBox.Show("flv file does not exist!", "no such file.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            EnableUI(false);
            this.Text = title + " - 正在分割...";
            textStat.Clear();
            int parts = int.Parse(comboBoxPart.Text);
            int seconds = 0;
            if (parser != null)
            {
                seconds = (int)(parser.Duration / 1000) / parts + 10;
            }
            else
            {
                VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
                enc.FFmpegPath = "ffmpeg.exe";
                VideoFile vf = new VideoFile(textFlv.Text);
                enc.GetVideoInfo(vf);
                TimeSpan t = vf.Duration;
                //int tt =(int)t.TotalSeconds;
                seconds = (int)t.TotalSeconds / parts + 10;
            }
            new Thread(() =>
            {
                for (int i = 0; i < parts; i++)
                {
                    Process p = new Process();
                    string ph = Environment.CommandLine;
                    ph = ph.Substring(0, ph.LastIndexOf('\\') + 1);
                    if (ph[0] == '"')
                        ph = ph.Substring(1);
                    p.StartInfo.FileName = "\"" + ph + "ffmpeg.exe\"";
                    p.StartInfo.Arguments = " -ss " + (i == 0 ? 0 : seconds * i - 10).ToString()
                        + " -i " + textFlv.Text
                        + " -vcodec copy -acodec copy "
                        + " -t " + (i == 0 ? seconds : (seconds + 10)).ToString() + " "
                        + textFlv.Text.Substring(0, textFlv.Text.LastIndexOf(".")) + (i + 1).ToString("00") + ".flv";
                    p.StartInfo.RedirectStandardError = true;
                    p.ErrorDataReceived += new DataReceivedEventHandler(SplitOutput);
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.CreateNoWindow = true;
                    p.Start();
                    p.BeginErrorReadLine();
                    p.WaitForExit();
                    p.Close();
                    p.Dispose();

                }

                this.BeginInvoke(new MethodInvoker(() =>
                {
                    EnableUI(true);
                    this.Text = title + " - 分割完成!";
                }));
            }).Start();
        }
Esempio n. 8
0
        private void VideoSplitByTime()
        {
            int time = Int32.Parse(boxPartHour.Text) * 3600
                + Int32.Parse(boxPartMin.Text) * 60
                + Int32.Parse(boxPartSec.Text);
            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            enc.FFmpegPath = "ffmpeg.exe";
            VideoFile vf = new VideoFile(file);
            enc.GetVideoInfo(vf);
            TimeSpan t = vf.Duration;
            //int tt =(int)t.TotalSeconds;
            int parts = (int)t.TotalSeconds / time + 1;

            #region thread start

            //EnableUI(false);
            new Thread(() =>
            {
                for (int i = 0; i < parts; i++)
                {
                    Process p = new Process();
                    string ph = Environment.CommandLine;
                    ph = ph.Substring(0, ph.LastIndexOf('\\') + 1);
                    if (ph[0] == '"')
                        ph = ph.Substring(1);
                    p.StartInfo.FileName = "\"" + ph + "ffmpeg.exe\"";
                    p.StartInfo.Arguments = " -ss " + (i == 0 ? 0 : time * i - 10).ToString()
                        + " -i " + "\"" + file + "\""
                        + " -vcodec copy -acodec copy "
                        + " -t " + (i == 0 ? time : (time + 10)).ToString() + " "
                        + "\"" + path + (i + 1).ToString("00") + formate + "\"";
                    p.StartInfo.RedirectStandardError = true;
                    p.ErrorDataReceived += new DataReceivedEventHandler(SplitOutput);
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.CreateNoWindow = true;
                    p.Start();
                    p.BeginErrorReadLine();
                    p.WaitForExit();
                    p.Close();
                    p.Dispose();

                }

                this.BeginInvoke(new MethodInvoker(() =>
                {
                    EnableUI(true);
                    //this.Text = title + " - 分割完成!";
                }));
            }).Start();
            #endregion
        }
Esempio n. 9
0
        private void listViewFlv_DragDrop(object sender, DragEventArgs e)
        {
            string[] stringTemp = (string[])e.Data.GetData(DataFormats.FileDrop);
            //textStat.Clear();
            listViewFlv.Items.Clear();
            VideoEncoder.Encoder enc = new VideoEncoder.Encoder();
            enc.FFmpegPath = "ffmpeg.exe";

            for (int i = 0; i < stringTemp.Length; i++)
            {

                VideoFile vf = new VideoFile(stringTemp[i]);
                enc.GetVideoInfo(vf);
                TimeSpan t = vf.Duration;
                //int tt =(int)t.TotalSeconds;
                //seconds = (int)t.TotalSeconds / parts + 10;
                ListViewItem it = new ListViewItem();
                it.Text = stringTemp[i];
                it.SubItems.Add(vf.Duration.ToString().Substring(0, vf.Duration.ToString().LastIndexOf(".")));
                it.SubItems.Add(vf.BitRate.ToString());
                it.SubItems.Add(vf.VideoBitRate.ToString());
                it.SubItems.Add(vf.AudioBitRate.ToString());

                listViewFlv.Items.Add(it);
                //                 stringTemp[i] = stringTemp[i]
                //                     + " Duration:" + t.TotalSeconds
                //                     + " VideoRate:" + vf.VideoBitRate
                //                     + " AudioRate:" + vf.AudioBitRate;

            }
            listViewFlv.Columns[0].Width = -1;
            //listViewFlv.Columns[1].Width = -1;
            //listViewFlv.Columns[4].Width = -1;
        }