Пример #1
0
        private static void Main(string[] args)
        {
            //File.WriteAllBytes("bc",Convert.FromBase64String("vg23gr25u7ov2fjema8b0s5sb5as2ym5"));
            //var fvd=parseFlashVars(File.ReadAllText("phex0.js",Encoding.GetEncoding(1251)));
            vc = new FFMpegConverter();
            vc.FFMpegExeName  = "c:\\progra~1\\Audacity\\FFmpeg\\ffmpeg.exe";
            vc.FFMpegToolPath = "c:\\progra~1\\Audacity\\FFmpeg";
            vcs = new ConvertSettings();
            vc.ConvertProgress += new EventHandler <ConvertProgressEventArgs>(vc_ConvertProgress);
            System.Diagnostics.Debug.WriteLine(args[1]);
            string bufl = Path.GetExtension(args[1]);

            bufl = args[1].Replace(bufl, "_0" + bufl);
            if (File.Exists(bufl))
            {
                File.Delete(bufl);
            }
            File.Copy(args[1], bufl);
            string[] fnl = File.ReadAllLines(args[1], Encoding.GetEncoding(1251));
            fdI = Path.GetDirectoryName(fnl[0]);
            fdO = fdI;
            fnO = fdI + "\\" + Path.GetFileNameWithoutExtension(fnl[0]);
            fmt = "mp4";
            switch (args[0])
            {
            case "flv": xFLV(fnl); break;

            case "cbu": xCBU(fnl); break;

            case "ac3": vcs.VideoCodec = "copy";     vcs.AudioBitRate = "640k"; vcs.AudioCodec = "ac3"; xEnc(fnl); break;

            case "cat": xCAT(fnl); break;

            case "ogg": vcs.VideoBitRate = "2400k"; vcs.VideoCodec = "libtheora"; vcs.AudioBitRate = "192k"; vcs.AudioCodec = "libvorbis"; xEnc(fnl); break;

            case "av1": vcs.VideoBitRate = "2400k"; vcs.VideoCodec = "libaom_av1"; vcs.AudioBitRate = "192k"; vcs.AudioCodec = "libopus"; fmt = "ogv"; xEnc(fnl); break;

            case "m3v": vcs.VideoCodec = "mpeg4"; vcs.AudioCodec = "libmp3lame"; vcs.CustomOutputArgs = "-qscale 9"; xEnc(fnl); break;

            case "m4v": vcs.VideoCodec = "libx264"; vcs.AudioCodec = "aac"; vcs.CustomOutputArgs = "-crf 30"; xEnc(fnl); break;

            case "m5v": vcs.VideoCodec = "libx265"; vcs.AudioCodec = "aac"; vcs.CustomOutputArgs = "-crf 22"; xEnc(fnl); break;

            case "cpy": vcs.VideoCodec = "copy"; vcs.AudioCodec = "copy"; vcs.CustomInputArgs = "-allowed_extensions ALL"; xEnc(fnl); break;
            }
        }
Пример #2
0
        private static void Convert(string path, string[] ext, bool delNotConv)
        {
            var files = new List <string>();

            GetFiles(path, ref files);
            if (files.Count > 0)
            {
                Console.WriteLine("Конвертиция файлов в mp4 началась");
                var err = new List <string>();
                for (int i = 0; i < files.Count; i++)
                {
                    string tmpFile = string.Empty;
                    try
                    {
                        var finfo = new FileInfo(files[i]);
                        if (ext.Contains(finfo.Extension))
                        {
                            Console.WriteLine($"{i}/{files.Count} - {files[i]} ");
                            tmpFile = files[i] + Guid.NewGuid();
                            FFMpegConverter ffMpeg = new FFMpegConverter();
                            ffMpeg.ConvertMedia(files[i], tmpFile, Format.mp4);
                            File.Delete(files[i]);
                            File.Move(tmpFile, files[i]);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(e.Message);
                        err.Add($"Ошибка конвертации файла {i}/{files.Count} - {files[i]} ({e.Message})");
                        if (delNotConv)
                        {
                            Console.WriteLine($"Файл будет удален {i}/{files.Count} - {files[i]}");
                            try
                            {
                                File.Delete(files[i]);
                                if (!string.IsNullOrEmpty(tmpFile))
                                {
                                    try { File.Delete(tmpFile); }catch (Exception ex) { }
                                }
                            }
                            catch (Exception ex)
                            {
                                var msg = $"Не удалось удалить файл {i}/{files.Count} - {files[i]} ({ex.Message})";
                                Console.WriteLine(msg);
                                err.Add(msg);
                            }
                        }
                        Console.ResetColor();
                    }
                }

                Console.WriteLine("Конвертиция файлов завершена");
                Console.ForegroundColor = ConsoleColor.Red;
                foreach (var e in err)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                Console.WriteLine("Файлов для конвертации не обнаружено.");
            }
            Console.WriteLine("Нажмите любую клавишу ....");
            Console.ReadKey();
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //var result = openFileDialog1.ShowDialog();
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                FileInfo fi = new FileInfo(ofd.FileName);
                fExt  = fi.Extension;
                fName = fi.FullName.Substring(0, fi.FullName.Length - fExt.Length);
                //if (!fExt.Equals(".wmv"))
                //{
                //    MessageBox.Show("Only WMV file type is supported");
                //}
                //else
                //{ }
                try
                {
                    var x       = false;
                    var message = "";
                    var input   = ofd.FileName;//Path.Combine(@"D:\Dev\Company\Exalted Solutions 2016 July\Projects\CaliberMatrix-Development\CaliberMatrix\SeleniumTestCaseRecording\SeleniumTest-3034ef9ce96dfb5b02fb76a04851ae61", "Video-2017-04-07_12-02-10-AM.wmv");
                    if (!File.Exists(input))
                    {
                        MessageBox.Show(@"File does not exist", @"Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        var fileName = Path.GetFileNameWithoutExtension(input);

                        var outputFileNameOgg  = fileName + ".ogg";
                        var outputFileNameMp4  = fileName + ".mp4";
                        var outputFileNameWebm = fileName + ".webm";

                        var bytes = File.ReadAllBytes(input);
                        var data  = new MemoryStream(bytes);
                        var t     = Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                //backgroundWorker1.RunWorkerAsync();
                                var ffMpeg = new FFMpegConverter();
                                //backgroundWorker1.RunWorkerAsync();
                                ffMpeg.ConvertProgress += UpdateProgress;
                                //ffMpeg.ConvertMedia(input, outputFileNameWebm, Format.webm);
                                //ffMpeg.ConvertMedia(input, outputFileNameOgg, Format.ogg);
                                //ffMpeg.ConvertMedia(input, outputFileNameMp4, Format.mp4);
                                ffMpeg.ConvertMedia(input, null, outputFileNameMp4, null, new ConvertSettings()
                                {
                                    CustomOutputArgs = "-profile:v baseline -level 3.0 -pix_fmt yuv420p -threads 2 -movflags +faststart"
                                });

                                x       = true;
                                p       = 100;
                                message = "Video converted successfully";
                                return(x);
                            }
                            catch (Exception ex)
                            {
                                p       = 100;
                                x       = false;
                                message = ex.GetBaseException().Message;
                                return(x);
                            }
                        });
                        t.Wait();
                        if (t.IsCompleted)
                        {
                            if (x)
                            {
                                MessageBox.Show(message, @"Success", MessageBoxButtons.OK);
                            }
                            else
                            {
                                MessageBox.Show(message, @"Error", MessageBoxButtons.OK);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().Message, @"Error", MessageBoxButtons.OK);
                }
            }
        }