Esempio n. 1
0
        public void FromVegas(Vegas myVegas)
        {
            string configString = File.ReadAllText("./tmp.csv");

            string[] configArray = configString.Split(';');
            if (renderProject(myVegas, configArray[0], configArray[1], configArray[2], configArray[3]))
            {
                // Success
                myVegas.Exit();
            }
            else
            {
                // Failed
                myVegas.Exit();
            }
        }
        public void FromVegas(Vegas vegas)
        {
            string         rendererName = Script.Args.ValueOf("renderer");
            string         templateName = Script.Args.ValueOf("template");
            Renderer       renderer     = vegas.Renderers.FindByName(rendererName);
            RenderTemplate template     = null;

            if (renderer != null)
            {
                template = renderer.Templates.FindByName(templateName);
            }
            if (template == null)
            {
                vegas.ShowError("Render template not found.");
                return;
            }
            string       path   = vegas.Project.FilePath;
            string       saveas = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".rendered.mp4";
            RenderStatus status = vegas.Render(saveas, template);

            if (status == RenderStatus.Complete || status == RenderStatus.Canceled || status == RenderStatus.Quit)
            {
                vegas.Exit();
            }
            else
            {
                vegas.ShowError("Render incomplete. Please try again.");
                return;
            }
        }
        public void FromVegas(Vegas vegas)
        {
            string         rendererName = Script.Args.ValueOf("renderer");
            string         templateName = Script.Args.ValueOf("template");
            string         saveas       = Script.Args.ValueOf("saveas", true);
            Renderer       renderer     = vegas.Renderers.FindByName(rendererName);
            RenderTemplate template     = null;

            if (renderer != null)
            {
                template = renderer.Templates.FindByName(templateName);
            }
            if (template == null)
            {
                vegas.ShowError("Render template not found.");
                return;
            }
            if (string.IsNullOrWhiteSpace(saveas))
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog
                {
                    Filter           = ".mp4 file (*.mp4)|*.mp4",
                    Title            = "Select render location",
                    InitialDirectory = vegas.Project.FilePath,
                    CheckPathExists  = true,
                    AddExtension     = true
                };

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    saveas = Path.GetFullPath(saveFileDialog.FileName);
                }
            }
            if (string.IsNullOrWhiteSpace(saveas))
            {
                vegas.ShowError("No valid save path exists.");
                return;
            }

            RenderStatus status = vegas.Render(saveas, template);

            if (status == RenderStatus.Complete || status == RenderStatus.Canceled || status == RenderStatus.Quit)
            {
                vegas.Exit();
            }
            else
            {
                vegas.ShowError("Render incomplete. Please try again.");
                return;
            }
        }
        public void FromVegas(Vegas vegas)
        {
            Media media = vegas.Project.MediaPool.AddMedia(Script.Args.ValueOf("media"));

            foreach (MediaStream stream in media.Streams)
            {
                if (stream is VideoStream)
                {
                    VideoTrack t = vegas.Project.AddVideoTrack();
                    VideoEvent e = t.AddVideoEvent(new Timecode(), media.Length);
                    e.ResampleMode = VideoResampleMode.Disable;
                    e.AddTake(stream);
                }
                else if (stream is AudioStream)
                {
                    AudioTrack t = vegas.Project.AddAudioTrack();
                    AudioEvent e = t.AddAudioEvent(new Timecode(), media.Length);
                    e.AddTake(stream);
                }
            }

            vegas.SaveProject(Script.Args.ValueOf("output"));
            vegas.Exit();
        }
        public void FromVegas(Vegas vegas)
        {
            try
            {
                _vegas = vegas;

                ScriptArgs args = Script.Args;
                if (args.Count > 0)
                {
                    _closeonfinish = System.Convert.ToBoolean(args.ValueOf("closeonfinish") ?? "false");
                    _savewhendone  = System.Convert.ToBoolean(args.ValueOf("savewhendone") ?? "false");
                    _makeveg       = System.Convert.ToBoolean(args.ValueOf("makeveg") ?? "false");
                    _file          = args.ValueOf("file");
                }
                else
                {
                    var dialog = new OpenFileDialog {
                        Filter = ".srt files (*.srt)|*.srt", CheckPathExists = true, InitialDirectory = vegas.Project.FilePath
                    };
                    DialogResult result = dialog.ShowDialog();
                    vegas.UpdateUI();

                    if (result == DialogResult.OK)
                    {
                        _file = Path.GetFullPath(dialog.FileName);
                    }
                    else
                    {
                        return;
                    }
                }

                if (_makeveg)
                {
                    Media media = vegas.Project.MediaPool.AddMedia(Script.Args.ValueOf("media"));

                    foreach (MediaStream stream in media.Streams)
                    {
                        if (stream is VideoStream)
                        {
                            VideoTrack t = vegas.Project.AddVideoTrack();
                            VideoEvent e = t.AddVideoEvent(new Timecode(), media.Length);
                            e.ResampleMode = VideoResampleMode.Disable;
                            e.AddTake(stream);
                        }
                        else if (stream is AudioStream)
                        {
                            AudioTrack t = vegas.Project.AddAudioTrack();
                            AudioEvent e = t.AddAudioEvent(new Timecode(), media.Length);
                            e.AddTake(stream);
                        }
                    }

                    vegas.SaveProject(Script.Args.ValueOf("output"));
                }

                using (FileStream fs = new FileStream(_file, FileMode.Open, FileAccess.Read))
                    using (StreamReader stream = new StreamReader(fs))
                    {
                        while (!stream.EndOfStream)
                        {
                            string line = stream.ReadLine();

                            if (Regex.IsMatch(line, "^[0-9]+$"))
                            {
                                line = stream.ReadLine();

                                if (Regex.IsMatch(line, "^" + SRT_TIME_PATTERN + " --> " + SRT_TIME_PATTERN + "$"))
                                {
                                    MatchCollection stamps = Regex.Matches(line, SRT_TIME_PATTERN);

                                    TimeSpan s = TimeSpan.ParseExact(stamps[0].Value, SRT_TIME_FORMAT, null);
                                    TimeSpan e = TimeSpan.ParseExact(stamps[1].Value, SRT_TIME_FORMAT, null);
                                    string   t = string.Empty;

                                    while (!stream.EndOfStream)
                                    {
                                        line = stream.ReadLine();
                                        if (!string.IsNullOrEmpty(line))
                                        {
                                            if (!string.IsNullOrEmpty(t))
                                            {
                                                t += "[br]";
                                            }

                                            t += line;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }

                                    Region r = Convert(s, e, t);
                                    if (r != null)
                                    {
                                        vegas.Project.Regions.Add(r);
                                    }
                                }
                            }
                        }
                    }

                if (_savewhendone)
                {
                    vegas.SaveProject();
                }
                if (_closeonfinish)
                {
                    vegas.Exit();
                }
            }
            catch (VegasException e)
            {
                Vegas.COM.ShowError(e.Title, e.Message);
            }
        }