Exemple #1
0
 void addframe(object bmp)
 {
     lock (avienclock)
     {
         newStream.AddFrame((Bitmap)bmp);
         ((Bitmap)bmp).Dispose();
     }
 }
Exemple #2
0
        private void video_NewFrameEvent(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap   bmp          = null;
            Graphics g            = null;
            Brush    c            = null;
            Bitmap   currentFrame = (Bitmap)eventArgs.Frame.Clone();

            if (firstFrame)
            {
                bta.StoreFirstFrameParams(currentFrame);
                firstFrame = false;
            }

            if (viewASCII && viewOriginal)
            {
                bmp = currentFrame;
                g   = Graphics.FromImage(currentFrame);
                c   = new SolidBrush(Color.White);
            }

            else if (viewASCII && !viewOriginal)
            {
                bmp = new Bitmap(dimensions.Width, dimensions.Height);
                g   = Graphics.FromImage(bmp);
                c   = new TextureBrush(currentFrame);
            }

            else if (!viewASCII && viewOriginal)
            {
                bmp = currentFrame;
            }

            if (viewASCII)
            {
                String A = bta.BitmapToASCIIText(currentFrame);
                g.DrawString(A, new Font("Consolas", 7.0f), c, new System.Drawing.Point(0, 0));
            }

            // Se despliega la imagen en la ventana
            pictureBox1.Image = bmp;

            // Se guarda la primera imagen
            firstImage = (Bitmap)pictureBox1.Image.Clone();



            // Se guarda la imagen en el video
            if (grabando && inicializado)
            {
                aviStream.AddFrame(firstImage);
                firstImage.Dispose();
            }
        }
Exemple #3
0
 private void Save()
 {
     for (int i = 1; i < this._grabFrames.Frames.Count; i++)
     {
         _aviStream.AddFrame((Bitmap)this._grabFrames.Frames[i].Image);
         if (SaveVideoProgressHandler != null)
         {
             SaveVideoProgressHandler(i);
         }
     }
     _aviManager.Close();
 }
        /** Metoda care se foloseste de bibliotecile AviManager pentru a
         * crea un stream video dintr-o lista de imagini format bitmap.
         **/
        private void createMovie(String fileName, List <Bitmap> images)
        {
            AviManager  aviManager  = new AviManager(fileName, false);
            VideoStream videoStream = aviManager.AddVideoStream(false, 30, images.ElementAt(0));

            foreach (var image in images)
            {
                if (finalFrames.IndexOf(image) != 0)
                {
                    videoStream.AddFrame(image);
                }
            }
            aviManager.Close();
        }
    public void CreateMovie(List <Bitmap> imageEntities)
    {
        AviManager  aviManager = new AviManager(Environment.CurrentDirectory + "\\Vedios\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".avi", false);
        VideoStream aviStream  = aviManager.AddVideoStream(true, 2, new Bitmap(width, height));

        Bitmap bitmap;

        foreach (var imageEntity in imageEntities)
        {
            bitmap = ReduceBitmap(imageEntity, width, height);
            aviStream.AddFrame(bitmap);
            bitmap.Dispose();
        }

        aviManager.Close();
    }
Exemple #6
0
        private void NewVideoFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {
            if (_aviStream is null)
            {
                _aviStream = AviManager.AddVideoStream(false, 5, eventArgs.Frame);
            }
            else
            {
                _aviStream.AddFrame(eventArgs.Frame);
            }

            if (CaptureType.Equals(CaptureTypeEnum.VideoCaptureWithVoice) || CaptureType.Equals(CaptureTypeEnum.ScreenCaptureWithVoice))
            {
                BitmapsCount++;
            }
        }
        // Aforge kütüphanesi ile bu şekilde yapılıyor.

        /*public void create_video_from_bitmaps(Bitmap[] BitmapStream,int Height,int Width)
         * {
         *  // instantiate AVI writer, use WMV3 codec
         *  VideoFileWriter writer = new VideoFileWriter();
         *  // create new AVI file and open it
         *  writer.Open("C:\\yazlab\\processed_frames\\result.avi", Width, Height);
         *  // create frame image
         *
         *  foreach(Bitmap Frame in BitmapStream)
         *  {
         *      writer.WriteVideoFrame(Frame);
         *  }
         *  writer.Close();
         *
         * }
         */
        public void create_video_from_bitmaps(Bitmap[] BitmapStream)
        {
            try{
                AviManager aviManager = new AviManager(@"C:\\yazlab\\processed_frames\\result.avi", false);
                //add a new video stream and one frame to the new file
                VideoStream aviStream = aviManager.AddVideoStream(true, 0.2, BitmapStream[0]);

                foreach (Bitmap Frame in BitmapStream)
                {
                    aviStream.AddFrame(Frame);
                }
                aviManager.Close();
            }catch (Exception Exp) {
                System.Windows.Forms.MessageBox.Show(Exp.ToString(), "AviFileHatası");
            }
        }
Exemple #8
0
        private void ThreadRun(object arg)
        {
            if (!_running)
            {
                _running = true;

                while (!_exitEvent.WaitOne(0, false))
                {
                    IntPtr windowHandle = (IntPtr)arg;
                    //Get the active window so we can translate it.
                    Tree window = _windowCapture.CaptureWindowWithPixels(windowHandle, UsePrintWindow, false);

                    if (window != null)
                    {
                        Prefab.Bitmap         capture = window["capturedpixels"] as Prefab.Bitmap;
                        System.Drawing.Bitmap bmp     = _pool.GetInstance(capture.Width, capture.Height);
                        Bitmap.ToSystemDrawingBitmap(capture, bmp);

                        // Get Window features
                        Win32.WINDOWINFO windowinfo = new Win32.WINDOWINFO(true);
                        Win32.GetWindowInfo(windowHandle, ref windowinfo);

                        // Save as png image
                        String filename = string.Format("{0}_f{1:D4}.png", _saveLoc.Substring(0, _saveLoc.Length - 4), frame_num);
                        bmp.Save(@filename, ImageFormat.Png);
                        frame_num++;


                        if (_videoStream == null)
                        {
                            _videoStream = _aviManager.AddVideoStream(false, 20, bmp);
                        }
                        else
                        {
                            _videoStream.AddFrame(bmp);
                        }

                        _pool.ReturnInstance(bmp);
                    }

                    //Let's not melt our processor ;)
                    Thread.Sleep(50);
                }
                _running = false;
                _aviManager.Close();
            }
        }
Exemple #9
0
        private async void makevideo()
        {
            //AppRecordingManager manager = AppRecordingManager.GetDefault();
            //AppRecordingStatus status = manager.GetStatus();
            //StorageFolder folder = await StorageFolder.GetFolderFromPathAsync("C:\\Videos");

            //StorageFile file = await folder.CreateFileAsync(
            //    "capture.mp4", CreationCollisionOption.ReplaceExisting);

            //if (status.CanRecord || status.CanRecordTimeSpan)
            //{
            //    operation = await manager.StartRecordingToFileAsync(file);
            //}
            AviManager aviManager =
                new AviManager(@"C:\Videos\new.avi", false);
            int         i         = 0;
            VideoStream aviStream = null;

            while (continuetomakevideo == true)
            {
                Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb);


                Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                gfxScreenshot.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

                if (i == 0)
                {
                    aviStream = aviManager.AddVideoStream(true, 1, bmpScreenshot);
                }
                else
                {
                    aviStream.AddFrame(bmpScreenshot);
                }
                //bitmapQueue.Enqueue(bmpScreenshot);
                i++;
                await Task.Delay(1000);

                //Change the ImageFormat to jpeg to save hard disk or keep it in Tiff
                //for higher resolution
                //bmpScreenshot.Save("Dependencies\\temp.tif", ImageFormat.Tiff);

                //bmpScreenshot = null;
            }
            aviManager.Close();
        }
        public static bool CheckForVideo(KernelManager kernelManager)
        {
            if (_frame == null)
            {
                return(false);
            }
            var i = _frame.Value / StepsPerPoint;

            if (i >= Frames.Count - 1)
            {
                _frame = null;
                _aviManager.Close();
                RenderWindow.SetStatus("Finished video");
                return(false);
            }
            RenderWindow.SetStatus("Rendering frame " + _frame.Value + " of " + (Frames.Count - 1) * StepsPerPoint);
            var d0     = i == 0 ? Frames[0] : Frames[i - 1];
            var d1     = Frames[i];
            var d2     = Frames[i + 1];
            var d3     = i == Frames.Count - 2 ? Frames[Frames.Count - 1] : Frames[i + 2];
            var t      = (float)(_frame.Value % StepsPerPoint) / StepsPerPoint;
            var config = CameraConfig.CatmullRom(d0, d1, d2, d3, t);
            var bmp    = kernelManager.GetScreenshot(config, 720, 2);

            if (_frame.Value % 256 == 0 || _aviManager == null)
            {
                if (_aviManager != null)
                {
                    _aviManager.Close();
                }
                _videoStream = null;
                _aviManager  = new AviManager(Ext.UniqueFilename("video", "avi"), false);
            }
            if (_videoStream == null)
            {
                _videoStream = _aviManager.AddVideoStream(false, 25, bmp);
            }
            else
            {
                _videoStream.AddFrame(bmp);
            }

            _frame = _frame.Value + 1;

            return(true);
        }
        public void testWrite(List <System.Drawing.Bitmap> bitmaps, String fileName)
        {
            //load the first image
            Bitmap bm = bitmaps[0];
            //create a new AVI file
            AviManager aviManager = new AviManager(fileName, false);
            //add a new video stream and one frame to the new file
            VideoStream aviStream = aviManager.AddVideoStream(true, 2, bm);
            int         count     = 0;

            foreach (System.Drawing.Bitmap bitmap in bitmaps)
            {
                aviStream.AddFrame(bitmap);
                bitmap.Dispose();
                count++;
            }
            aviManager.Close();
        }
Exemple #12
0
        public void SaveAsVideo()
        {
            List <System.Drawing.Bitmap> bitmaps = new List <System.Drawing.Bitmap>();
            BitmapSource bmp = _images[0];

            bitmaps.Add(BitmapFromSource(bmp));
            AviManager  aviManager = new AviManager(Path.Combine(_targetPath, "video.avi"), false);
            VideoStream aviStream  = aviManager.AddVideoStream(false, _fps, bitmaps[0]);

            for (int n = 1; n < _images.Count; n++)
            {
                bitmaps.Add(BitmapFromSource(_images[n]));
                aviStream.AddFrame(bitmaps[n]);
            }

            aviManager.Close();
            ClearImages(bitmaps);
        }
Exemple #13
0
        public void AddFrame(Bitmap frame)
        {
            var storeName = store.GetStoreName();

            if (!storeName.Equals(currentStoreName))
            {
                this.Close();
            }
            lock (syncRoot)
            {
                if (aviManager == null)
                {
                    aviManager       = new AviManager(storeName, false);
                    videoStream      = aviManager.AddVideoStream(true, VIDEO_FRAME_RATE, frame);
                    currentStoreName = storeName;
                }
                else
                {
                    videoStream.AddFrame(frame);
                }
            }
        }
        public void test()
        {
            DoubleAnimation anim  = new DoubleAnimation(50, 400, TimeSpan.FromSeconds(10), System.Windows.Media.Animation.FillBehavior.HoldEnd);
            var             clock = anim.CreateClock();

            this.ellipse1.ApplyAnimationClock(Canvas.LeftProperty, clock);
            clock.Controller.Pause();

            int dpi = 96;
            int fps = 24;
            int anim_length_in_secs = 5;
            int num_total_frames    = fps * anim_length_in_secs;

            var         secs       = Enumerable.Range(0, num_total_frames).Select(t => (((double)t) / fps));
            AviManager  aviManager = new AviFile.AviManager(filename, false);
            VideoStream aviStream  = null;

            foreach (var sec in secs)
            {
                clock.Controller.SeekAlignedToLastTick(TimeSpan.FromSeconds(sec),
                                                       System.Windows.Media.Animation.TimeSeekOrigin.BeginTime);
                this.canvas1.UpdateLayout();

                string temp_bitmap = "d:\\canvas_frame.png";
                util.SaveCanvas(this, this.canvas1, dpi, temp_bitmap);

                System.Drawing.Bitmap bm = new System.Drawing.Bitmap(temp_bitmap);
                if (aviStream == null)
                {
                    aviStream = aviManager.AddVideoStream(compress, fps, bm);
                }
                else
                {
                    aviStream.AddFrame(bm);
                }
                bm.Dispose();
            }
            aviManager.Close();
        }
Exemple #15
0
        private void doExporting(string tmpFilePath, DicomElement dicomElement, BackgroundWorker worker)
        {
            //create a new AVI file
            AviManager aviManager = new AviManager(tmpFilePath, false);
            //add a new video stream and one frame to the new file
            // todo mozda ce moci drugaciji konstruktor...
            Bitmap      bitmap    = dicomElement.GetBitmap(1);
            VideoStream aviStream = aviManager.AddVideoStream(createCompressedOptions(), Settings.Default.Fps, bitmap);

            bitmap.Dispose();
            worker.ReportProgress(1);

            for (int n = 2; n <= dicomElement.FrameCount; n++)
            {
                bitmap = dicomElement.GetBitmap(n);
                aviStream.AddFrame(bitmap);
                bitmap.Dispose();
                worker.ReportProgress(1);
            }

            aviManager.Close();
        }
        private void btnAddFrame_Click(object sender, EventArgs e)
        {
            String     tempFileName = System.IO.Path.GetTempFileName() + ".avi";
            AviManager tempFile     = new AviManager(tempFileName, false);

            Bitmap bitmap = (Bitmap)Image.FromFile(txtNewFrameFileName.Lines[0].Trim());

            tempFile.AddVideoStream(false, 1, bitmap);
            VideoStream stream = tempFile.GetVideoStream();

            for (int n = 1; n < txtNewFrameFileName.Lines.Length; n++)
            {
                if (txtNewFrameFileName.Lines[n].Trim().Length > 0)
                {
                    stream.AddFrame((Bitmap)Image.FromFile(txtNewFrameFileName.Lines[n]));
                }
            }

            editableStream.Paste(stream, 0, (int)numPastePositionBitmap.Value, stream.CountFrames);

            tempFile.Close();
            try { File.Delete(tempFileName); } catch (IOException) { }
        }
Exemple #17
0
 private void AddImageToAvi(Image image)
 {
     stream.AddFrame((Bitmap)image);
     image.Dispose();
 }
Exemple #18
0
        public override void saveToMovie()
        {
            //save starting state & stop playback
            bool startPlaying = _animationTimer.Enabled;
            int  startFrame   = _animationControl.currentFrame;

            _animationTimer.Stop();

            //show save dialogue
            MovieExportOptions dialog = new MovieExportOptions(_wrist.subjectPath, _animationControl.FPS);

            dialog.ShowDialog();

            //okay, now lets figure out what we are doing here
            switch (dialog.results)
            {
            case MovieExportOptions.SaveType.CANCEL:
                //nothing to do, we were canceled
                break;

            case MovieExportOptions.SaveType.IMAGES:
                //save images
                string outputDir = dialog.OutputFileName;
                //save it to a movie
                _viewer.cacheOffscreenRenderer();
                for (int i = 0; i < _animationControl.NumberOfFrames; i++)
                {
                    setAnimationToFrame(i);      //change to current frame
                    string fname = Path.Combine(outputDir, String.Format("outfile{0:d3}.jpg", i));
                    _viewer.saveToJPEG(fname);
                }
                _viewer.clearOffscreenRenderer();
                break;

            case MovieExportOptions.SaveType.MOVIE:
                //save movie
                try
                {
                    AviManager aviManager = new AviManager(dialog.OutputFileName, false);
                    int        smooth     = dialog.SmoothFactor;
                    _viewer.cacheOffscreenRenderer(smooth); //TODO: Check that output is multiple of 4!!!!
                    setAnimationToFrame(0);                 //set to first frame, so we can grab it.
                    System.Drawing.Bitmap frame   = getSmoothedFrame(smooth);
                    VideoStream           vStream = aviManager.AddVideoStream(dialog.MovieCompress, (double)dialog.MovieFPS, frame);
                    for (int i = 1; i < _animationControl.NumberOfFrames; i++) //start from frame 1, frame 0 was added when we began
                    {
                        setAnimationToFrame(i);                                //change to current frame
                        vStream.AddFrame(getSmoothedFrame(smooth));
                    }
                    aviManager.Close();      //close out and save
                    _viewer.clearOffscreenRenderer();
                }
                catch (Exception ex)
                {
                    string msg = "Error saving to movie file.\n\n" + ex.Message;
                    libWrist.ExceptionHandling.HandledExceptionManager.ShowDialog(msg, "", "", ex);
                }
                break;
            }

            //wrap us up, resume frame and playing status
            updateAnimationFrame();
            if (startPlaying)
            {
                _animationTimer.Start();
            }
        }
Exemple #19
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
            case Keys.Escape:
                if (dragActive)
                {
                    // There's a drag going on so assume pressing escape is trying to cancel it.
                    dragActive           = false;
                    dragBoxFromMouseDown = Rectangle.Empty;
                    panel1.Visible       = false;
                    //panel1.Refresh();
                }
                else
                {
                    Application.Exit();
                }
                return(true);       // indicate that you handled this keystroke

            // case (char)Keys.Up:
            case Keys.O:
            case Keys.Left:
                // Request to zoom out.
                if (MandImage.imageCalcInProgress)
                {
                    // Ignore keystroke as calculating.
                    Console.Beep();
                }
                else
                {
                    if (popBitmap())
                    {
                        // Succeeded in getting a new bitmap off the stack so display it.
                        Invalidate(new Rectangle(mainBmpLocationInForm, new Size(MandImage.bitmapWidth, MandImage.bitmapHeight)));
                        //Refresh();
                    }
                    else
                    {
                        // No bitmap to pop so beep.
                        Console.Beep();
                    }
                }
                return(true);       // indicate that you handled this keystroke

            //case (char)Keys.Down:
            case Keys.I:
            case Keys.Right:
                // Request to zoom in.
                if (MandImage.imageCalcInProgress)
                {
                    // Ignore keystroke as calculating.
                    Console.Beep();
                }
                else
                {
                    if (nextBitmap())
                    {
                        // Succeeded in getting a new bitmap off the stack so display it.
                        Invalidate(new Rectangle(mainBmpLocationInForm, new Size(MandImage.bitmapWidth, MandImage.bitmapHeight)));
                        //Refresh();
                    }
                    else
                    {
                        // No bitmap to go to so beep.
                        Console.Beep();
                    }
                }
                return(true);       // indicate that you handled this keystroke

            case Keys.W:
                // Write images to file
                if (mainBmpImageList.Count <= 0)
                {
                    // No images to write.
                    Console.Beep();
                    return(true);       // indicate that you handled this keystroke
                }

                // Write images in arraylist
                string     newFileName = @"E:\UP\Peter4\Documents\Visual Studio 2015\Projects\Mandlebrot Set\Mandlebrot Set\test.avi";
                AviManager newFile     = new AviManager(newFileName, false);
                try
                {
                    Bitmap bmp = ((MandImage)(mainBmpImageList[0])).MainBmp;

                    VideoStream newStream = newFile.AddVideoStream(false, 1, bmp);
                    for (int n = 1; n < mainBmpImageList.Count; n++)
                    {
                        bmp = ((MandImage)(mainBmpImageList[n])).MainBmp;
                        newStream.AddFrame(bmp);
                    }
                    newFile.Close();
                }
                catch (Exception ex)
                {
                    newFile.Close();
                    throw ex;
                }
                return(true);       // indicate that you handled this keystroke

            default:
                // Call the base class
                return(base.ProcessCmdKey(ref msg, keyData));
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("MobiConverter by Gericom");
            Console.WriteLine();
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }
            switch (args[0])
            {
            case "-d":
            {
                if (args.Length != 2 && args.Length != 3)
                {
                    goto default;
                }
                if (!File.Exists(args[1]))
                {
                    Console.WriteLine("Error! File not found: " + args[1]);
                    return;
                }
                String outfile = (args.Length == 3) ? args[2] : Path.ChangeExtension(args[1], "avi");
                byte[] sig     = new byte[4];
                Stream s       = File.OpenRead(args[1]);
                s.Read(sig, 0, 4);
                s.Close();
                if (sig[0] == 0x4C && sig[1] == 0x32 && sig[2] == 0xAA && sig[3] == 0xAB)        //moflex
                {
                    Console.WriteLine("Moflex container detected!");
                    Console.Write("Converting: ");
                    Console.CursorVisible = false;
                    MobiclipDecoder    ddd   = null;
                    AviManager         m     = new AviManager(outfile, false);
                    MemoryStream       audio = null;
                    FastAudioDecoder[] mFastAudioDecoders = null;
                    int         audiorate          = -1;
                    int         audiochannels      = 0;
                    VideoStream vs                 = null;
                    FileStream  stream             = File.OpenRead(args[1]);
                    var         d                  = new MoLiveDemux(stream);
                    int         PlayingVideoStream = -1;
                    d.OnCompleteFrameReceived += delegate(MoLiveChunk Chunk, byte[] Data)
                    {
                        if ((Chunk is MoLiveStreamVideo || Chunk is MoLiveStreamVideoWithLayout) && ((PlayingVideoStream == -1) || ((MoLiveStream)Chunk).StreamIndex == PlayingVideoStream))
                        {
                            if (ddd == null)
                            {
                                ddd = new MobiclipDecoder(((MoLiveStreamVideo)Chunk).Width, ((MoLiveStreamVideo)Chunk).Height, MobiclipDecoder.MobiclipVersion.Moflex3DS);
                                PlayingVideoStream = ((MoLiveStream)Chunk).StreamIndex;
                            }
                            ddd.Data   = Data;
                            ddd.Offset = 0;
                            Bitmap b = ddd.DecodeFrame();
                            if (vs == null)
                            {
                                vs = m.AddVideoStream(false, Math.Round(((double)((MoLiveStreamVideo)Chunk).FpsRate) / ((double)((MoLiveStreamVideo)Chunk).FpsScale), 3), b);
                            }
                            else
                            {
                                vs.AddFrame(b);
                            }
                        }
                        else if (Chunk is MoLiveStreamAudio)
                        {
                            if (audio == null)
                            {
                                audio         = new MemoryStream();
                                audiochannels = (int)((MoLiveStreamAudio)Chunk).Channel;
                                audiorate     = (int)((MoLiveStreamAudio)Chunk).Frequency;
                            }
                            switch ((int)((MoLiveStreamAudio)Chunk).CodecId)
                            {
                            case 0:            //fastaudio
                            {
                                if (mFastAudioDecoders == null)
                                {
                                    mFastAudioDecoders = new FastAudioDecoder[(int)((MoLiveStreamAudio)Chunk).Channel];
                                    for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                    {
                                        mFastAudioDecoders[i] = new FastAudioDecoder();
                                    }
                                }
                                List <short>[] channels = new List <short> [(int)((MoLiveStreamAudio)Chunk).Channel];
                                for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                {
                                    channels[i] = new List <short>();
                                }

                                int offset = 0;
                                int size   = 40;
                                while (offset + size < Data.Length)
                                {
                                    for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                    {
                                        mFastAudioDecoders[i].Data   = Data;
                                        mFastAudioDecoders[i].Offset = offset;
                                        channels[i].AddRange(mFastAudioDecoders[i].Decode());
                                        offset = mFastAudioDecoders[i].Offset;
                                    }
                                }
                                short[][] channelsresult = new short[(int)((MoLiveStreamAudio)Chunk).Channel][];
                                for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                {
                                    channelsresult[i] = channels[i].ToArray();
                                }
                                byte[] result = InterleaveChannels(channelsresult);
                                audio.Write(result, 0, result.Length);
                            }
                            break;

                            case 1:            //IMA-ADPCM
                            {
                                IMAADPCMDecoder[] decoders = new IMAADPCMDecoder[(int)((MoLiveStreamAudio)Chunk).Channel];
                                List <short>[]    channels = new List <short> [(int)((MoLiveStreamAudio)Chunk).Channel];
                                for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                {
                                    decoders[i] = new IMAADPCMDecoder();
                                    decoders[i].GetWaveData(Data, 4 * i, 4);
                                    channels[i] = new List <short>();
                                }

                                int offset = 4 * (int)((MoLiveStreamAudio)Chunk).Channel;
                                int size   = 128 * (int)((MoLiveStreamAudio)Chunk).Channel;
                                while (offset + size < Data.Length)
                                {
                                    for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                    {
                                        channels[i].AddRange(decoders[i].GetWaveData(Data, offset, 128));
                                        offset += 128;
                                    }
                                }
                                short[][] channelsresult = new short[(int)((MoLiveStreamAudio)Chunk).Channel][];
                                for (int i = 0; i < (int)((MoLiveStreamAudio)Chunk).Channel; i++)
                                {
                                    channelsresult[i] = channels[i].ToArray();
                                }
                                byte[] result = InterleaveChannels(channelsresult);
                                audio.Write(result, 0, result.Length);
                            }
                            break;

                            case 2:            //PCM16
                            {
                                audio.Write(Data, 0, Data.Length - (Data.Length % ((int)((MoLiveStreamAudio)Chunk).Channel * 2)));
                            }
                            break;
                            }
                        }
                    };
                    bool left    = false;
                    int  counter = 0;
                    while (true)
                    {
                        uint error = d.ReadPacket();
                        if (error == 73)
                        {
                            break;
                        }
                        //report progress
                        if (counter == 0)
                        {
                            Console.Write("{0,3:D}%", stream.Position * 100 / stream.Length);
                            Console.CursorLeft -= 4;
                        }
                        counter++;
                        if (counter == 50)
                        {
                            counter = 0;
                        }
                    }
                    if (audio != null)
                    {
                        byte[] adata = audio.ToArray();
                        audio.Close();
                        var sinfo = new Avi.AVISTREAMINFO();
                        sinfo.fccType      = Avi.streamtypeAUDIO;
                        sinfo.dwScale      = audiochannels * 2;
                        sinfo.dwRate       = audiorate * audiochannels * 2;
                        sinfo.dwSampleSize = audiochannels * 2;
                        sinfo.dwQuality    = -1;
                        var sinfo2 = new Avi.PCMWAVEFORMAT();
                        sinfo2.wFormatTag      = 1;
                        sinfo2.nChannels       = (short)audiochannels;
                        sinfo2.nSamplesPerSec  = audiorate;
                        sinfo2.nAvgBytesPerSec = audiorate * audiochannels * 2;
                        sinfo2.nBlockAlign     = (short)(audiochannels * 2);
                        sinfo2.wBitsPerSample  = 16;
                        unsafe
                        {
                            fixed(byte *pAData = &adata[0])
                            {
                                m.AddAudioStream((IntPtr)pAData, sinfo, sinfo2, adata.Length);
                            }
                        }
                    }
                    m.Close();
                    stream.Close();
                    Console.WriteLine("Done!");
                    Console.CursorVisible = true;
                }
                else if (sig[0] == 0x4D && sig[1] == 0x4F && sig[2] == 0x44 && sig[3] == 0x53)
                {
                    //mods
                    Console.WriteLine("Mods container detected!");
                    Console.Write("Converting: ");
                    Console.CursorVisible = false;
                    AviManager   m      = new AviManager(outfile, false);
                    FileStream   stream = File.OpenRead(args[1]);
                    ModsDemuxer  dm     = new ModsDemuxer(stream);
                    MemoryStream audio  = null;
                    if ((dm.Header.AudioCodec == 1 || dm.Header.AudioCodec == 3) && dm.Header.NbChannel > 0 && dm.Header.Frequency > 0)
                    {
                        audio = new MemoryStream();
                    }
                    MobiclipDecoder    d          = new MobiclipDecoder(dm.Header.Width, dm.Header.Height, MobiclipDecoder.MobiclipVersion.ModsDS);
                    VideoStream        vs         = null;
                    int                CurChannel = 0;
                    List <short>[]     channels   = new List <short> [dm.Header.NbChannel];
                    IMAADPCMDecoder[]  decoders   = new IMAADPCMDecoder[dm.Header.NbChannel];
                    SxDecoder[]        sxd        = new SxDecoder[dm.Header.NbChannel];
                    FastAudioDecoder[] fad        = new FastAudioDecoder[dm.Header.NbChannel];
                    bool[]             isinit     = new bool[dm.Header.NbChannel];
                    for (int i = 0; i < dm.Header.NbChannel; i++)
                    {
                        channels[i] = new List <short>();
                        decoders[i] = new IMAADPCMDecoder();
                        sxd[i]      = new SxDecoder();
                        fad[i]      = new FastAudioDecoder();
                        isinit[i]   = false;
                    }
                    int counter = 0;
                    while (true)
                    {
                        uint   NrAudioPackets;
                        bool   IsKeyFrame;
                        byte[] framedata = dm.ReadFrame(out NrAudioPackets, out IsKeyFrame);
                        if (framedata == null)
                        {
                            break;
                        }
                        d.Data   = framedata;
                        d.Offset = 0;
                        Bitmap b = d.DecodeFrame();
                        if (vs == null)
                        {
                            vs = m.AddVideoStream(false, Math.Round(dm.Header.Fps / (double)0x01000000, 3), b);
                        }
                        else
                        {
                            vs.AddFrame(b);
                        }
                        if (NrAudioPackets > 0 && audio != null)
                        {
                            int Offset = d.Offset - 2;
                            if (dm.Header.TagId == 0x334E && (IOUtil.ReadU16LE(framedata, 0) & 0x8000) != 0)
                            {
                                Offset += 4;
                            }
                            if (dm.Header.AudioCodec == 3)
                            {
                                if (IsKeyFrame)
                                {
                                    for (int i = 0; i < dm.Header.NbChannel; i++)
                                    {
                                        channels[i] = new List <short>();
                                        decoders[i] = new IMAADPCMDecoder();
                                        sxd[i]      = new SxDecoder();
                                        fad[i]      = new FastAudioDecoder();
                                        isinit[i]   = false;
                                    }
                                }
                                for (int i = 0; i < NrAudioPackets; i++)
                                {
                                    channels[CurChannel].AddRange(decoders[CurChannel].GetWaveData(framedata, Offset, 128 + (!isinit[CurChannel] ? 4 : 0)));
                                    Offset            += 128 + (!isinit[CurChannel] ? 4 : 0);
                                    isinit[CurChannel] = true;
                                    CurChannel++;
                                    if (CurChannel >= dm.Header.NbChannel)
                                    {
                                        CurChannel = 0;
                                    }
                                }
                            }
                            else if (dm.Header.AudioCodec == 1)
                            {
                                for (int i = 0; i < NrAudioPackets; i++)
                                {
                                    if (!isinit[CurChannel])
                                    {
                                        sxd[CurChannel].Codebook = dm.AudioCodebooks[CurChannel];
                                    }
                                    isinit[CurChannel]     = true;
                                    sxd[CurChannel].Data   = framedata;
                                    sxd[CurChannel].Offset = Offset;
                                    channels[CurChannel].AddRange(sxd[CurChannel].Decode());
                                    Offset = sxd[CurChannel].Offset;
                                    CurChannel++;
                                    if (CurChannel >= dm.Header.NbChannel)
                                    {
                                        CurChannel = 0;
                                    }
                                }
                            }
                            else if (dm.Header.AudioCodec == 2)
                            {
                                for (int i = 0; i < NrAudioPackets; i++)
                                {
                                    fad[CurChannel].Data   = framedata;
                                    fad[CurChannel].Offset = Offset;
                                    channels[CurChannel].AddRange(fad[CurChannel].Decode());
                                    Offset = fad[CurChannel].Offset;
                                    CurChannel++;
                                    if (CurChannel >= dm.Header.NbChannel)
                                    {
                                        CurChannel = 0;
                                    }
                                }
                            }
                            int smallest = int.MaxValue;
                            for (int i = 0; i < dm.Header.NbChannel; i++)
                            {
                                if (channels[i].Count < smallest)
                                {
                                    smallest = channels[i].Count;
                                }
                            }
                            if (smallest > 0)
                            {
                                //Gather samples
                                short[][] samps = new short[dm.Header.NbChannel][];
                                for (int i = 0; i < dm.Header.NbChannel; i++)
                                {
                                    samps[i] = new short[smallest];
                                    channels[i].CopyTo(0, samps[i], 0, smallest);
                                    channels[i].RemoveRange(0, smallest);
                                }
                                byte[] result = InterleaveChannels(samps);
                                audio.Write(result, 0, result.Length);
                            }
                        }
                        //report progress
                        if (counter == 0)
                        {
                            Console.Write("{0,3:D}%", stream.Position * 100 / stream.Length);
                            Console.CursorLeft -= 4;
                        }
                        counter++;
                        if (counter == 50)
                        {
                            counter = 0;
                        }
                    }
                    if (audio != null)
                    {
                        byte[] adata = audio.ToArray();
                        audio.Close();
                        var sinfo = new Avi.AVISTREAMINFO();
                        sinfo.fccType      = Avi.streamtypeAUDIO;
                        sinfo.dwScale      = dm.Header.NbChannel * 2;
                        sinfo.dwRate       = (int)dm.Header.Frequency * dm.Header.NbChannel * 2;
                        sinfo.dwSampleSize = dm.Header.NbChannel * 2;
                        sinfo.dwQuality    = -1;
                        var sinfo2 = new Avi.PCMWAVEFORMAT();
                        sinfo2.wFormatTag      = 1;
                        sinfo2.nChannels       = (short)dm.Header.NbChannel;
                        sinfo2.nSamplesPerSec  = (int)dm.Header.Frequency;
                        sinfo2.nAvgBytesPerSec = (int)dm.Header.Frequency * dm.Header.NbChannel * 2;
                        sinfo2.nBlockAlign     = (short)(dm.Header.NbChannel * 2);
                        sinfo2.wBitsPerSample  = 16;
                        unsafe
                        {
                            fixed(byte *pAData = &adata[0])
                            {
                                m.AddAudioStream((IntPtr)pAData, sinfo, sinfo2, adata.Length);
                            }
                        }
                    }
                    m.Close();
                    stream.Close();
                    Console.WriteLine("Done!");
                    Console.CursorVisible = true;
                    return;
                }
                else if (sig[0] == 0x4D && sig[1] == 0x4F && sig[2] == 0x43 && sig[3] == 0x35)
                {
                    //moc5
                    Console.WriteLine("MOC5 container detected!");
                    Console.WriteLine("Error! Not supported yet!");
                    return;
                }
                else if (Path.GetExtension(args[1]).ToLower() == ".vx2")
                {
                    //mods
                    Console.WriteLine("VX2 container detected!");
                    Console.Write("Converting: ");
                    Console.CursorVisible = false;
                    AviManager      m         = new AviManager(outfile, false);
                    FileStream      fs        = File.OpenRead(args[1]);
                    MemoryStream    audio     = new MemoryStream();
                    MobiclipDecoder d         = new MobiclipDecoder(256, 192, MobiclipDecoder.MobiclipVersion.Moflex3DS);
                    VideoStream     vs        = null;
                    int             framerate = 20;
                    int             counter   = 0;
                    int             frame     = 0;
                    while (true)
                    {
                        if (fs.Position >= fs.Length)
                        {
                            break;
                        }
                        if ((frame % framerate) == 0)        //Audio
                        {
                            byte[] adata = new byte[32768 * 2];
                            fs.Read(adata, 0, 32768 * 2);
                            audio.Write(adata, 0, adata.Length);
                        }
                        int    length = (fs.ReadByte() << 0) | (fs.ReadByte() << 8) | (fs.ReadByte() << 16) | (fs.ReadByte() << 24);
                        byte[] data   = new byte[length];
                        fs.Read(data, 0, length);
                        d.Data   = data;
                        d.Offset = 0;
                        Bitmap b = d.DecodeFrame();
                        if (vs == null)
                        {
                            vs = m.AddVideoStream(false, framerate, b);
                        }
                        else
                        {
                            vs.AddFrame(b);
                        }
                        frame++;
                        //report progress
                        if (counter == 0)
                        {
                            Console.Write("{0,3:D}%", fs.Position * 100 / fs.Length);
                            Console.CursorLeft -= 4;
                        }
                        counter++;
                        if (counter == 50)
                        {
                            counter = 0;
                        }
                    }
                    if (audio != null)
                    {
                        byte[] adata = audio.ToArray();
                        audio.Close();
                        var sinfo = new Avi.AVISTREAMINFO();
                        sinfo.fccType      = Avi.streamtypeAUDIO;
                        sinfo.dwScale      = 1 * 2;
                        sinfo.dwRate       = (int)32768 * 1 * 2;
                        sinfo.dwSampleSize = 1 * 2;
                        sinfo.dwQuality    = -1;
                        var sinfo2 = new Avi.PCMWAVEFORMAT();
                        sinfo2.wFormatTag      = 1;
                        sinfo2.nChannels       = (short)1;
                        sinfo2.nSamplesPerSec  = (int)32768;
                        sinfo2.nAvgBytesPerSec = (int)32768 * 1 * 2;
                        sinfo2.nBlockAlign     = (short)(1 * 2);
                        sinfo2.wBitsPerSample  = 16;
                        unsafe
                        {
                            fixed(byte *pAData = &adata[0])
                            {
                                m.AddAudioStream((IntPtr)pAData, sinfo, sinfo2, adata.Length);
                            }
                        }
                    }
                    m.Close();
                    fs.Close();
                    Console.WriteLine("Done!");
                    Console.CursorVisible = true;
                    return;
                }
                else
                {
                    Console.WriteLine("Error! Unrecognized format!");
                    return;
                }
                break;
            }

            case "-e":
            {
                break;
            }

            default:
            case "-h":
                PrintUsage();
                return;
            }
        }
Exemple #21
0
        public void CDGtoAVI(string aviFileName, string cdgFileName, string mp3FileName, double frameRate, string backgroundFileName = "")
        {
            Bitmap      backgroundBmp = null;
            Bitmap      mergedBMP     = null;
            VideoStream aviStream     = default(VideoStream);
            CDGFile     myCDGFile     = new CDGFile(cdgFileName);

            myCDGFile.renderAtPosition(0);
            Bitmap bitmap__1 = (Bitmap)myCDGFile.RGBImage;

            if (!string.IsNullOrEmpty(backgroundFileName))
            {
                try
                {
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp = MovieFrameExtractor.GetBitmap(0, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT);
                    }
                    if (IsGraphic(backgroundFileName))
                    {
                        backgroundBmp = CDGNet.GraphicUtil.GetCDGSizeBitmap(backgroundFileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
            AviManager aviManager = new AviManager(aviFileName, false);

            if (backgroundBmp != null)
            {
                mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1);
                aviStream = aviManager.AddVideoStream(true, frameRate, mergedBMP);
                mergedBMP.Dispose();
                if (IsMovie(backgroundFileName))
                {
                    backgroundBmp.Dispose();
                }
            }
            else
            {
                aviStream = aviManager.AddVideoStream(true, frameRate, bitmap__1);
            }

            int    count         = 0;
            double frameInterval = 1000 / frameRate;
            long   totalDuration = myCDGFile.getTotalDuration();
            double position      = 0;

            while (position <= totalDuration)
            {
                count   += 1;
                position = count * frameInterval;
                myCDGFile.renderAtPosition(Convert.ToInt64(position));
                bitmap__1 = (Bitmap)myCDGFile.RGBImage;
                if (!string.IsNullOrEmpty(backgroundFileName))
                {
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp = MovieFrameExtractor.GetBitmap(position / 1000, backgroundFileName, CDGFile.CDG_FULL_WIDTH, CDGFile.CDG_FULL_HEIGHT);
                    }
                }
                if (backgroundBmp != null)
                {
                    mergedBMP = GraphicUtil.MergeImagesWithTransparency(backgroundBmp, bitmap__1);
                    aviStream.AddFrame(mergedBMP);
                    mergedBMP.Dispose();
                    if (IsMovie(backgroundFileName))
                    {
                        backgroundBmp.Dispose();
                    }
                }
                else
                {
                    aviStream.AddFrame(bitmap__1);
                }
                bitmap__1.Dispose();
                double percentageDone = (position / totalDuration) * 100;

                if (Status != null)
                {
                    Status(percentageDone.ToString());
                }
                Application.DoEvents();
            }
            myCDGFile.Dispose();
            aviManager.Close();
            if (backgroundBmp != null)
            {
                backgroundBmp.Dispose();
            }

            // Add MP3 to AVI
            Console.Write("|nAVI terminated, add MP3 to AVI");
            AddMP3toAVI(aviFileName, mp3FileName);
        }
Exemple #22
0
        public override void saveToMovie()
        {
            //save starting state & stop playback
            bool startPlaying = _timer.Enabled;
            int  startFrame   = _currentFrame;

            _timer.Enabled = false;
            //TODO: Disable buttons....

            //CurrentFrame = 0;
            //_viewer.saveToJPEG(@"C:\Temp\testMovie\test1.jpg");
            //System.Drawing.Image im = _viewer.getImage();
            //im.Save(@"C:\Temp\testMovie\test2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            ////debug.
            //return;

            //show save dialogue
            MovieExportOptions dialog = new MovieExportOptions(_posFileName, _posViewControl.FPS);

            dialog.ShowDialog();

            //okay, now lets figure out what we are doing here
            switch (dialog.results)
            {
            case MovieExportOptions.SaveType.CANCEL:
                //nothing to do, we were canceled
                break;

            case MovieExportOptions.SaveType.IMAGES:
                //save images
                string outputDir = dialog.OutputFileName;
                //save it to a movie
                for (int i = 0; i < NumPositions; i++)
                {
                    CurrentFrame = i;      //change to current frame
                    string fname = Path.Combine(outputDir, String.Format("outfile{0:d3}.jpg", i));
                    _viewer.saveToJPEG(fname);
                }
                break;

            case MovieExportOptions.SaveType.MOVIE:
                //save movie
                try
                {
                    AviManager aviManager = new AviManager(dialog.OutputFileName, false);
                    CurrentFrame = 0;     //set to first frame, so we can grab it.
                    System.Drawing.Bitmap frame   = (System.Drawing.Bitmap)_viewer.getImage();
                    VideoStream           vStream = aviManager.AddVideoStream(dialog.MovieCompress, (double)dialog.MovieFPS, frame);
                    for (int i = 1; i < NumPositions; i++) //start from frame 1, frame 0 was added when we began
                    {
                        CurrentFrame = i;                  //change to current frame
                        vStream.AddFrame((System.Drawing.Bitmap)_viewer.getImage());
                    }
                    aviManager.Close();      //close out and save
                }
                catch (Exception ex)
                {
                    string msg = "Error saving to movie file.\n\n" + ex.Message;
                    libWrist.ExceptionHandling.HandledExceptionManager.ShowDialog(msg, "", "", ex);
                }
                break;
            }

            //wrap us up, resume frame and playing status
            CurrentFrame   = startFrame;
            _timer.Enabled = startPlaying;
        }
Exemple #23
0
        private void SplineChart(string filedirectory)
        {
            chart2.Series.Clear();
            var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name              = "Series1",
                Color             = System.Drawing.Color.Green,
                IsVisibleInLegend = false,
                IsXValueIndexed   = true,
                ChartType         = SeriesChartType.Line
            };

            chart2.Series.Add(series1);

            //Set X and Y Axis Minimum and Maximum
            chart2.ChartAreas[0].AxisX.Minimum = 0;
            //chart2.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(lines.Count() - 1);
            chart2.ChartAreas[0].AxisX.Interval          = 25;
            chart2.ChartAreas[0].AxisX.IntervalAutoMode  = IntervalAutoMode.VariableCount;
            chart2.ChartAreas[0].AxisX.IntervalType      = DateTimeIntervalType.Number;
            chart2.ChartAreas[0].AxisX.IsStartedFromZero = true;
            chart2.ChartAreas[0].AxisY.Minimum           = Math.Floor(Convert.ToDouble(lines[lines.Count() - 1][0]));
            chart2.ChartAreas[0].AxisY.Maximum           = Math.Ceiling(Convert.ToDouble(lines[1][0]));

            double        cost            = -1;
            double        previouscost    = double.MaxValue;
            int           lasti           = int.MinValue;
            List <Bitmap> designpics      = new List <Bitmap>();
            List <Bitmap> chartpics       = new List <Bitmap>();
            List <Bitmap> mergedpics      = new List <Bitmap>();
            MemoryStream  ms              = new MemoryStream();
            int           maxWidthdesign  = -1;
            int           maxHeightdesign = -1;

            //Create bmp pictures and save them for every iteration
            for (int i = 1; i < lines.Count(); i++)
            {
                cost = Convert.ToDouble(lines[i][0]);
                //There is a new design picture if this is true
                if (cost < previouscost)
                {
                    lasti = (i - 1);
                    designpics.Add(new Bitmap(filedirectory + "/" + (i - 1).ToString() + ".bmp"));
                    if (designpics[i - 1].Width > maxWidthdesign)
                    {
                        maxWidthdesign = designpics[i - 1].Width;
                    }
                    if (designpics[i - 1].Height > maxHeightdesign)
                    {
                        maxHeightdesign = designpics[i - 1].Height;
                    }
                    previouscost = cost;
                }
                else//No new picture use the old picture
                {
                    designpics.Add(new Bitmap(filedirectory + "/" + lasti.ToString() + ".bmp"));
                }
                series1.Points.AddXY(Convert.ToDouble(i - 1), cost);
                chart2.Invalidate();
                //chart2.SaveImage(filedirectory + "/chart" + (i - 1).ToString() + ".bmp", System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Bmp);
                chart2.SaveImage(ms, ChartImageFormat.Bmp);
                chartpics.Add(new Bitmap(ms));
            }

            //Merge pictures
            for (int i = 0; i < lines.Count() - 1; i++)
            {
                mergedpics.Add(MergeTwoImages(chartpics[i], designpics[i], maxWidthdesign > chart2.Width ? maxWidthdesign : chart2.Width, maxHeightdesign + chart2.Width + 1));
            }

            //Create avi video from images
            AviManager avimanager = new AviManager(filedirectory + "/video.avi", false);
            //add a new video stream and one frame to the new file
            VideoStream aviStream = avimanager.AddVideoStream(false, 10, mergedpics[0]);

            for (int i = 1; i < lines.Count() - 1; i++)
            {
                //aviStream.AddFrame(chartpics[i]);
                aviStream.AddFrame(mergedpics[i]);
            }
            avimanager.Close();
        }
Exemple #24
0
        public static void StartRecording()
        {
            Console.WriteLine("Start Recording ...");

            var videoTransfert = new InterProcessCommunication.VideoTranfert();

            VideoStream aviStream  = null;
            AviManager  aviManager = null;

            bool   endOfReccord    = false;
            string lastFileReccord = "";

            do
            {
                // Récupère le frame suivant
                Console.Write("Reading frame");
                var frame = videoTransfert.ReadFrame();
                Console.WriteLine(" ...");

                // Vérfie que nous somme pas à la fin de l'enregistrement
                endOfReccord = frame.EndOfRecord;
                if (!endOfReccord)
                {
                    var bitmap = frame.Bitmap;
                    // Si le nom du fichier d'enregistrement est changé un nouveau fichier vidéo doit être créé
                    if (lastFileReccord.Equals(frame.FileName) == false)
                    {
                        // Ferme le fichier s'il y en a un d'ouvert
                        if (aviManager != null)
                        {
                            Console.WriteLine(@"Close video stream ""{0}"" ...", lastFileReccord);
                            aviManager.Close();
                        }

                        lastFileReccord = frame.FileName;

                        Console.Write(@"Creating video stream ""{0}"" ...", lastFileReccord);

                        // Si le fichier est déjà existant on le supprime
                        if (System.IO.File.Exists(lastFileReccord))
                        {
                            System.IO.File.Delete(lastFileReccord);
                        }

                        aviManager = new AviManager(lastFileReccord, false);
                        aviStream  = aviManager.AddVideoStream(false, frame.FrameRate, bitmap); //bitmap étant la première image, elle sert a sizer le format du vidéo de sorti
                        Console.WriteLine(" ...");
                    }
                    else
                    {
                        Console.Write("Add frame to stream");
                        aviStream.AddFrame(bitmap);
                        Console.WriteLine(" ...");
                    }
                    bitmap.Dispose();
                }
            } while (!endOfReccord);

            // Ferme le fichier s'il y en a un d'ouvert
            if (aviManager != null)
            {
                Console.WriteLine(@"Close video stream ""{0}"" ...", lastFileReccord);
                aviManager.Close();
            }


            Console.WriteLine("End Recording ...");
        }