Example #1
0
        /// <summary>
        /// Event handler to resize video frame when the picturebox size changes (if required to do so).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pb_SizeChanged(object sender, EventArgs e)
        {
            if (m_videoWindow == null)
            {
                return;
            }

            if (m_bAutoResize)
            {
                int hr;

                PictureBox pb = sender as PictureBox;
                if (pb == null)
                {
                    return;
                }

                hr = m_videoWindow.put_Width(pb.Width);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                hr = m_videoWindow.put_Height(pb.Height);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
        }
        ////////////////
        /// Get/Put Width
        private void TestWidth()
        {
            int hr;
            int Width1, Width2;

            // Read the current value
            hr = m_ivw.get_Width(out Width1);
            Marshal.ThrowExceptionForHR(hr);

            // Change it
            hr = m_ivw.put_Width(Width1 + 1);
            Marshal.ThrowExceptionForHR(hr);

            // Re-read
            hr = m_ivw.get_Width(out Width2);
            Marshal.ThrowExceptionForHR(hr);

            // Make sure the value we set is what we just read
            Debug.Assert(Width1 + 1 == Width2, "Put/Get Width");
        }
Example #3
0
        private void loadVideo(String videoPath)
        {
            videoFilepath = videoPath;
                videoFileName.Text = getDisplayVideoName();

                if (graph != null)
                {
                    graph = null;

                }
                if (mediaControl != null)
                {
                    // Stop media playback
                    this.mediaControl.Stop();
                    mediaControl = null;
                }

                if (videoWindow != null)
                {
                    videoWindow.put_Owner(IntPtr.Zero);
                    videoWindow = null;
                }

                if (mediaSeeking != null)
                {

                    mediaSeeking = null;
                }
                if (basicAudio != null)
                {

                    basicAudio = null;
                }
                GC.Collect();

               /* if (mediaPosition != null)
                {
                    mediaPosition = null;
                }*/

                graph = (IGraphBuilder)new FilterGraph();
                mediaControl = (IMediaControl)graph;
                //mediaPosition = (IMediaPosition)graph;
                videoWindow = (IVideoWindow)graph;
                mediaSeeking = (IMediaSeeking)graph;
                basicAudio = (IBasicAudio)graph;

                AviSplitter spliter = new AviSplitter();
                graph.AddFilter((IBaseFilter)spliter, null);
                graph.RenderFile(videoPath, null);
                graph.SetDefaultSyncSource();

                /*
                 * AMSeekingSeekingCapabilities cap = AMSeekingSeekingCapabilities.CanGetCurrentPos;
                if (mediaSeeking.CheckCapabilities(ref cap) > 0)
                {
                    this.consoleErreur.AppendText("Impossible de recuperer la position de la frame");
                }
                 * */

                videoWindow.put_Owner(videoPanel.Handle);

                videoWindow.put_MessageDrain(videoPanel.Handle);

                videoWindow.put_WindowStyle(WindowStyle.Child);
                videoWindow.put_WindowStyleEx(WindowStyleEx.ControlParent);
                videoWindow.put_Left(0);
                videoWindow.put_Top(0);
                videoWindow.put_Width(videoPanel.Width);
                videoWindow.put_Height(videoPanel.Height);

                //positionTrackbar.Enabled = true;
                speedTrackBar.Enabled = true;
                mediaSeeking.SetTimeFormat(TimeFormat.Frame);

                double rate;
                mediaSeeking.GetRate(out rate);
                rateText.Text = rate.ToString();
                speedTrackBar.Value = (int)(speedTrackBar.Maximum * rate / 2);

                trackBar1.Value = trackBar1.Maximum / 2;
                this.basicAudio.put_Volume(-5000 + 5000 * trackBar1.Value / trackBar1.Maximum);
            //mediaPosition.put_Rate(0.5);
                running = false;
                frameChanged = false;
        }
Example #4
0
        public void openVid(string fileName)
        {
            if (!File.Exists(fileName))
            {
                errorMsg("El archivo '" + fileName + "' no existe.");
                videoPanel.Visible = false;
                isVideoLoaded = false;
                drawPositions();
                return;
            }

            if (VideoBoxType == PreviewType.AviSynth)
            {
                avsClip = null;
                //butPause.Enabled = true;
                //butPlayR.Enabled = true;
                //butPlay.Enabled = true;
                //butStop.Enabled = true;
                videoPictureBox.Visible = false;
                //closeVidDShow(); // añadido
            }

            if (mediaControl != null)
            {
                mediaControl.Stop();
                videoWindow.put_Visible(DirectShowLib.OABool.False);
                videoWindow.put_Owner(IntPtr.Zero);
            }

            // Dshow :~~

            graphBuilder = (IGraphBuilder)new FilterGraph();
            graphBuilder.RenderFile(fileName, null);
            mediaControl = (IMediaControl)graphBuilder;
            // mediaEventEx = (IMediaEventEx)this.graphBuilder;
            mediaSeeking = (IMediaSeeking)graphBuilder;
            mediaPosition = (IMediaPosition)graphBuilder;
            basicVideo = graphBuilder as IBasicVideo;
            videoWindow = graphBuilder as IVideoWindow;

            VideoBoxType = PreviewType.DirectShow;

            // sacando información

            int x, y; double atpf;
            basicVideo.GetVideoSize(out x, out y);
            if (x == 0 || y == 0)
            {
                errorMsg("No se puede abrir un vídeo sin dimensiones.");
                videoPanel.Visible = false;
                isVideoLoaded = false;
                drawPositions();
                return;
            }

            if (videoInfo == null) videoInfo = new VideoInfo(fileName);

            videoInfo.Resolution = new Size(x, y);

            basicVideo.get_AvgTimePerFrame(out atpf);
            videoInfo.FrameRate = Math.Round(1 / atpf, 3);

            //labelResFPS.Text = x.ToString() + "x" + y.ToString() + " @ " + videoInfo.FrameRate.ToString() + " fps";
            textResX.Text = x.ToString();
            textResY.Text = y.ToString();
            textFPS.Text = videoInfo.FrameRate.ToString();

            if (File.Exists(Application.StartupPath+"\\MediaInfo.dll") && File.Exists(Application.StartupPath+"\\MediaInfoWrapper.dll"))
            {
                treeView1.Enabled = true;
                try
                {
                    RetrieveMediaFileInfo(fileName);
                }
                catch { treeView1.Enabled = false; }
            }
            else treeView1.Enabled = false;

            if (x != 0)
            {
                vidScaleFactor.Enabled = true;

                try
                {
                    vidScaleFactor.Text = getFromConfigFile("mainW_Zoom");
                }
                catch
                {
                    vidScaleFactor.Text = "50%";
                };

                double p = double.Parse(vidScaleFactor.Text.Substring(0, vidScaleFactor.Text.IndexOf('%')));
                p = p / 100;

                int new_x = (int)(x * p);
                int new_y = (int)(y * p);

                videoWindow.put_Height(new_x);
                videoWindow.put_Width(new_y);
                videoWindow.put_Owner(videoPanel.Handle);
                videoPanel.Size = new System.Drawing.Size(new_x, new_y);
                videoWindow.SetWindowPosition(0, 0, videoPanel.Width, videoPanel.Height);
                videoWindow.put_WindowStyle(WindowStyle.Child);
                videoWindow.put_Visible(DirectShowLib.OABool.True);

            }
            else vidScaleFactor.Enabled = false;

            // timer
            actualizaFrames.Interval = 10;
            actualizaFrames.Enabled = true;

            //mediaControl.Run();
            drawPositions();

            framesFin.Enabled = true;
            buttonAddFrameInicio.Enabled = buttonAddFrameInicio.Visible = true;
            framesInicio.Enabled = true;
            buttonAddFrameFin.Enabled = buttonAddFrameFin.Visible = true;
            butClip.Enabled = false;

            mediaSeeking.SetTimeFormat(DirectShowLib.TimeFormat.Frame);

            videoInfo.FrameTotal = VideoUnitConversion.getTotal(mediaSeeking, videoInfo.FrameRate);
            seekBar.Maximum = FrameTotal;
            seekBar.TickFrequency = seekBar.Maximum / 10;

            // VFW ( __ SOLO AVIs __ )

            try
            {
                AVIFileWrapper.AVIFileInit();
                int aviFile = 0;
                IntPtr aviStream;
                int res = AVIFileWrapper.AVIFileOpen(ref aviFile, fileName, 0x20, 0);
                res = AVIFileWrapper.AVIFileGetStream(aviFile, out aviStream, 1935960438, 0);

                videoInfo.KeyFrames = new ArrayList();
                int nFrames = FrameTotal;

                for (int i = 0; i < nFrames; i++)
                {
                    if (isKeyFrame(aviStream.ToInt32(), i))
                        videoInfo.KeyFrames.Add(i);
                }

                setStatus(videoInfo.KeyFrames.Count + " detectados");

                AVIFileWrapper.AVIStreamRelease(aviStream);
                AVIFileWrapper.AVIFileRelease(aviFile);
                AVIFileWrapper.AVIFileExit();
                KeyframesAvailable = true;
                /*
                nextK.Enabled = true;
                prevK.Enabled = true;

                drawKeyFrameBox();
                 */

            }
            catch
            {
                /*
                nextK.Enabled = false;
                prevK.Enabled = false;
                keyFrameBox.Visible = false;
                 */
                KeyframesAvailable = false;
            }

            if (openFile != null && al.Count > 1 && gridASS.RowCount>0)
            {
                gridASS.Rows[1].Selected = true;
                gridASS.Rows[0].Selected = true;
                gridASS.Rows[1].Selected = false;

            }

            frameTime = new Hashtable();
            for (int i = 0; i < FrameTotal; i++)
                frameTime.Add(i, new Tiempo((double)((double)i / videoInfo.FrameRate)));

            isVideoLoaded = true;

            updateMenuEnables();
            mediaControl.Pause();

            setStatus("Vídeo " + fileName + " cargado. [DirectShow]");

            script.GetHeader().SetHeaderValue("Video File", fileName);

            if (isKeyframeGuessNeeded())
                KeyframeGuess(false);
            //FrameIndex = 0;
        }
Example #5
0
        private void translateW_Load(object sender, EventArgs e)
        {
            //this.MaximumSize = this.Size;
            //this.MinimumSize = this.Size;
            toolStripStatusLabel2.Text = "Cargando el Asistente de Traducción...";
            // cargamos script
            autoComplete = new ArrayList();
            al = mW.al;
            gridCont.RowCount = al.Count;

            bool hasAutoComplete = (mW.script.GetHeader().GetHeaderValue("AutoComplete") != string.Empty);

            for (int i = 0; i < al.Count; i++)
            {
                lineaASS lass = (lineaASS)al[i];
                gridCont[0, i].Value = lass.personaje;
                if (!autoComplete.Contains(lass.personaje) && !hasAutoComplete)
                    if (lass.personaje.Trim()!="")
                        autoComplete.Add(lass.personaje);
                gridCont[1, i].Value = lass.texto;
            }
            if (hasAutoComplete) InsertAutoCompleteFromScript();

            labelLineaActual.Text = "1 de " + (al.Count) + " (0%)";
            textPersonaje.Text = gridCont[0, 0].Value.ToString();
            textOrig.Text = gridCont[1, 0].Value.ToString();

            // cargamos video

            graphBuilder = (IGraphBuilder)new FilterGraph();
            graphBuilder.RenderFile(videoInfo.FileName, null);
            mediaControl = (IMediaControl)graphBuilder;
            // mediaEventEx = (IMediaEventEx)this.graphBuilder;
            mediaSeeking = (IMediaSeeking)graphBuilder;
            mediaPosition = (IMediaPosition)graphBuilder;
            basicVideo = graphBuilder as IBasicVideo;
            basicAudio = graphBuilder as IBasicAudio;
            videoWindow = graphBuilder as IVideoWindow;

            try
            {
                int x, y; double atpf;
                basicVideo.GetVideoSize(out x, out y);
                basicVideo.get_AvgTimePerFrame(out atpf);
                videoInfo.FrameRate = Math.Round(1 / atpf, 3);

                int new_x = videoPanel.Width;
                int new_y = (new_x * y) / x;
                videoWindow.put_Height(new_x);
                videoWindow.put_Width(new_y);
                videoWindow.put_Owner(videoPanel.Handle);
                videoPanel.Size = new System.Drawing.Size(new_x, new_y);
                videoWindow.SetWindowPosition(0, 0, videoPanel.Width, videoPanel.Height);
                videoWindow.put_WindowStyle(WindowStyle.Child);
                videoWindow.put_Visible(DirectShowLib.OABool.True);
                mediaSeeking.SetTimeFormat(DirectShowLib.TimeFormat.Frame);

                mediaControl.Run();
            }
            catch { mW.errorMsg("Imposible cargar el vídeo. Debe haber algún problema con el mismo, y el asistente será muy inestable"); }
            // activamos timers & handlers

            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Enabled = true;
            timer2.Tick += new EventHandler(timer2_Tick);
            AutoSaveTimer.Tick += new EventHandler(timer3_Tick);
            AutoSaveTimer.Enabled = true;

            gridCont.CellClick += new DataGridViewCellEventHandler(gridCont_CellClick);
            textPersonaje.TextChanged += new EventHandler(textPersonaje_TextChanged);
            textTradu.TextChanged += new EventHandler(textTradu_TextChanged);
            textTradu.KeyUp += new KeyEventHandler(textBox1_KeyUp);
            textTradu.KeyDown += new KeyEventHandler(textTradu_KeyDown);
            textTradu.KeyPress += new KeyPressEventHandler(textTradu_KeyPress);
            textPersonaje.KeyDown += new KeyEventHandler(textPersonaje_KeyDown);
            textPersonaje.KeyPress += new KeyPressEventHandler(textPersonaje_KeyPress);
            button8.GotFocus += new EventHandler(button8_GotFocus);
            button9.GotFocus += new EventHandler(button9_GotFocus);
            gridCont.DoubleClick += new EventHandler(gridCont_DoubleClick);
            gridCont.SelectionChanged += new EventHandler(gridCont_SelectionChanged);
            gridCont.KeyUp += new KeyEventHandler(gridCont_KeyUp);
            listBox1.KeyUp += new KeyEventHandler(listBox1_KeyUp);
            textToAdd.KeyPress += new KeyPressEventHandler(textToAdd_KeyPress);
            progressBar1.MouseDown += new MouseEventHandler(progressBar1_MouseDown);
            tiempoInicio_.TimeValidated += new TimeTextBox.OnTimeTextBoxValidated(tiempo_TimeValidated);
            tiempoFin_.TimeValidated += new TimeTextBox.OnTimeTextBoxValidated(tiempo_TimeValidated);
            this.Move += new EventHandler(translateW_Move);

            //textTradu.ContextMenu = new ASSTextBoxRegExDefaultContextMenu(textTradu);

            mediaControl.Pause();

            // cargar de config

            try
            {
                checkAutoComplete.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_autoC"));
                checkTagSSA.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_tagSSA"));
                checkComment.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_Comment"));
                checkVideo.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_aud"));
                checkAudio.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_vid"));
                checkSaveTime.Checked = Convert.ToBoolean(mW.getFromConfigFile("translateW_preTime"));
            }
            catch {}

            try
            {
                AutoSaveTimer.Interval = int.Parse(mW.getFromConfigFile("translateW_AutoSaveInterval"));
            }
            catch
            {
                AutoSaveTimer.Interval = 30000;
            }

            // fin de inicializacion vil
            textTradu.Focus();

            try
            {
                string[] bleh = mW.getFromConfigFileA("translateW_Reference");
                for (int i = 0; i < bleh.Length; i++)
                    Diccionarios.Add(bleh[i]);
            }
            catch
            {
                Diccionarios.Add("WordReference|http://www.wordreference.com/");
                Diccionarios.Add("Wikipedia|http://es.wikipedia.org");
                Diccionarios.Add("RAE|http://www.rae.es");
                Diccionarios.Add("Dictionary|http://dictionary.reference.com/");
            }
            diccionarios.DataSource = Diccionarios;

            CreateReferenceTabs();
            UpdateStatusFile();

            TiempoInicio = DateTime.Now;

            Estadisticas.Interval = 1000;
            Estadisticas.Tick += new EventHandler(Estadisticas_Tick);
            Estadisticas.Enabled = true;

            InitRPC();

            archivosView.KeyDown += new KeyEventHandler(archivosView_KeyDown);
            archivosView.SelectedIndexChanged += new EventHandler(archivosView_SelectedIndexChanged);

            textTradu.EnableSpellChecking = mW.spellEnabled;

            if (mW.spellEnabled)
            {
                textTradu.DictionaryPath = mW.dictDir;
                textTradu.Dictionary = mW.ActiveDict;
            }

            toolStripStatusLabel2.Text = "Asistente cargado correctamente.";

            bool showpopup = true;

            try
            {
                showpopup = Convert.ToBoolean(mW.getFromConfigFile("translateW_ShowPopup"));

            }
            catch
            {
                mW.updateReplaceConfigFile("translateW_ShowPopup", showpopup.ToString());
            }

            if (showpopup)
            {
                TranslationStyle estilo = TranslationStyle.FromScriptWithActors;
                translateW_Popup pop = new translateW_Popup(mW);
                switch (pop.ShowDialog())
                {
                    case DialogResult.Yes:
                        estilo = TranslationStyle.FromScriptWithActors;
                        break;
                    case DialogResult.No:
                        estilo = TranslationStyle.FromScriptWithoutActors;
                        break;
                    case DialogResult.Cancel:
                        estilo = TranslationStyle.FromScratch;
                        break;
                    case DialogResult.Ignore:
                        estilo = TranslationStyle.FromScratchAudio;
                        break;
                }

                switch (estilo)
                {
                    case TranslationStyle.FromScriptWithActors:
                        modeSelector.Checked = true;
                        splitText.Checked = false;
                        audioMode.Checked = false;
                        break;
                    case TranslationStyle.FromScriptWithoutActors:
                        modeSelector.Checked = true;
                        splitText.Checked = true;
                        audioMode.Checked = false;
                        break;
                    case TranslationStyle.FromScratch:
                        modeSelector.Checked = false;
                        splitText.Checked = false;
                        audioMode.Checked = false;
                        break;
                    case TranslationStyle.FromScratchAudio:
                        modeSelector.Checked = false;
                        splitText.Checked = true;
                        audioMode.Checked = true;
                        break;
                }
            }
        }