예제 #1
0
        public VideoFrames(string fileLocation)
        {
            if (fileLocation == null)
            {
                _mode = Mode.None;
                return;
            }

            string lower = fileLocation.ToLower();
            fileloc = fileLocation;
            if (lower.EndsWith(".avi"))
            {
                _aviManager = new AviManager(fileLocation, true);
                _aviStream = _aviManager.GetVideoStream();
                _aviStream.GetFrameOpen();
                _mode = Mode.Video;
            }
            else if (lower.EndsWith(".png"))
            {
                _singleFrame = new System.Drawing.Bitmap(fileLocation);
                _mode = Mode.SingleFrame;
            }
            else
            {
                _mode = Mode.None;
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: rubyrose/gorich
 private void AddFile()
 {
     if (System.IO.File.Exists(uiAviFileNameTextBox.Text))
     {
         try
         {
             var aviManager = new AviManager(uiAviFileNameTextBox.Text, true);
             VideoStream aviStream = aviManager.GetVideoStream();
             aviStream.GetFrameOpen();
             Bitmap bmp = aviStream.GetBitmap(aviStream.CountFrames/2);
             var videoStreamControl = new VideoStreamBrowseControl {Dock = DockStyle.Top};
             videoStreamControl.SetFileName(GetCurrentFileName());
             videoStreamControl.SetFrame(GetResizedBitmap(bmp, 50, 50));
             videoStreamControl.VideoStream = aviStream;
             videoStreamControl.SelectVideoStream += SelectVideoStreamControl;
             uiVideoListPanel.Controls.Add(videoStreamControl);
             _selectedVideoStreamBrowseControl = videoStreamControl;
             foreach (VideoStreamBrowseControl browseControl in uiVideoListPanel.Controls.OfType<VideoStreamBrowseControl>())
             {
                 (browseControl).uiMainPanel.BackColor = Color.Lavender;
             }
             videoStreamControl.uiMainPanel.BackColor = Color.Aquamarine;
             aviManager.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
예제 #3
0
        private void btnAppend_Click(object sender, System.EventArgs e)
        {
            //open file
            Bitmap bmp = (Bitmap)Image.FromFile(txtFileNames.Lines[0]);
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);
            VideoStream aviStream = aviManager.GetVideoStream();

            //streams cannot be edited - copy to a new file
            VideoStream newStream;
            AviManager newManager = aviStream.DecompressToNewFile(@"..\..\testdata\temp.avi", true, out newStream);
            aviStream = newStream; //newManager.GetOpenStream(0);

            //add images
            Bitmap bitmap;
            for (int n = 0; n < txtFileNames.Lines.Length; n++) {
                if (txtFileNames.Lines[n].Trim().Length > 0) {
                    bitmap = (Bitmap)Bitmap.FromFile(txtFileNames.Lines[n]);
                    aviStream.AddFrame(bitmap);
                    bitmap.Dispose();
                }
            }

            //close old file
            aviManager.Close();
            //save and close new file
            newManager.Close();

            //delete old file, replace with new file
            System.IO.File.Delete(txtAviFileName.Text);
            System.IO.File.Move(@"..\..\testdata\temp.avi", txtAviFileName.Text);
        }
예제 #4
0
        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) { }
        }
예제 #5
0
 private void btnAddSound_Click(object sender, System.EventArgs e)
 {
     String fileName = GetFileName("Sounds (*.wav)|*.wav");
     if (fileName != null) {
         txtReportSound.Text = "Adding to sound.wav to " + txtAviFileName.Text + "...\r\n";
         AviManager aviManager = new AviManager(txtAviFileName.Text, true);
         try {
             int countFrames = aviManager.GetVideoStream().CountFrames;
             if (countFrames > numInsertWavePosition.Value) {
                 aviManager.AddAudioStream(fileName, (int)numInsertWavePosition.Value);
             } else {
                 MessageBox.Show(this, "Frame " + numInsertWavePosition.Value + " does not exists. The video stream contains frame from 0 to " + (countFrames - 1) + ".");
             }
         } catch (Exception ex) {
             MessageBox.Show(this, "The file does not accept the new wave audio stream.\r\n" + ex.ToString(), "Error");
         }
         aviManager.Close();
         txtReportSound.Text += "...finished.";
     }
 }
 private void openFile_Click(object sender, EventArgs e)
 {
     inputFileDlg.Filter = "Media Files|*.avi;|All files|*.*;";
     if (DialogResult.OK == inputFileDlg.ShowDialog())
     {
         fileNameText.Text = inputFileDlg.FileName;
         try
         {
             AviManager aviManager = new AviManager(fileNameText.Text, true);
             VideoStream stream = aviManager.GetVideoStream();
             startPointTracker.Maximum = stream.CountFrames;
             endPointTracker.Maximum = stream.CountFrames;
             ShowFrameTrackOne();
             ShowFrameTrackTwo();
         }
         catch(Exception ew)
         {
             MessageBox.Show("L�tfen avi formatinda bis dosya se�in");
         }
     }
 }
예제 #7
0
        private void CopyFile(String newName, bool compress)
        {
            //open compressed file
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);
            VideoStream aviStream = aviManager.GetVideoStream();
            //create un-/re-compressed file
            VideoStream newStream;
            AviManager newManager = aviStream.DecompressToNewFile(newName, compress, out newStream);

            //close compressed file
            aviManager.Close();
            //save and close un-/re-compressed file
            newManager.Close();
        }
예제 #8
0
        private void btnRead_Click(object sender, System.EventArgs e)
        {
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);
            VideoStream stream = aviManager.GetVideoStream();
            txtReportRead.Text = "Width: " + stream.Width;
            txtReportRead.Text += "\r\nHeight: " + stream.Height;
            txtReportRead.Text += "\r\nCount of Frames: " + stream.CountFrames;
            txtReportRead.Text += "\r\nFrame Rate: " + stream.FrameRate;

            txtReportRead.Text += "\r\nWave Sound:";

            try {
                AudioStream waveStream = aviManager.GetWaveStream();
                txtReportRead.Text += "\r\nSamples per Second: " + waveStream.CountSamplesPerSecond.ToString();
                txtReportRead.Text += "\r\nBits per Sample: " + waveStream.CountBitsPerSample.ToString();
                txtReportRead.Text += "\r\nChannels: " + waveStream.CountChannels.ToString();
            } catch {
                txtReportRead.Text += " None";
            }
        }
예제 #9
0
        private void btnExtract_Click(object sender, System.EventArgs e)
        {
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);

            VideoStream stream = aviManager.GetVideoStream();
            stream.GetFrameOpen();

            txtReportCopy.Text = txtFileNames.Text = String.Empty;
            String path = @"..\..\testdata\";
            for (int n = 0; n < stream.CountFrames; n++) {
                stream.ExportBitmap(n, path + n.ToString() + ".bmp");
                txtReportCopy.Text += n + ".bmp finished...\r\n";
                txtFileNames.Text += path + n + ".bmp\r\n";
            }

            stream.GetFrameClose();
            aviManager.Close();
        }
예제 #10
0
 private void btnExtractVideo_Click(object sender, System.EventArgs e)
 {
     txtReportCopy.Text = "Extracting " + txtAviFileName.Text + " to video.avi...\r\n";
     AviManager aviManager = new AviManager(txtAviFileName.Text, true);
     VideoStream videoStream = aviManager.GetVideoStream();
     videoStream.ExportStream(@"..\..\testdata\video.avi");
     aviManager.Close();
     txtReportCopy.Text += "...finished.";
 }
 private void ShowFrameTrackTwofromtext()
 {
     if (System.IO.File.Exists(fileNameText.Text))
     {
         try
         {
             AviManager aviManager = new AviManager(fileNameText.Text, true);
             VideoStream aviStream = aviManager.GetVideoStream();
             aviStream.GetFrameOpen();
             Bitmap bmp = aviStream.GetBitmap(Convert.ToInt32(endPointTrackerText.Text));
             bmp.SetResolution(rlPicBox.Width, rlPicBox.Height);
             smplPicBox.Image = bmp;
             aviStream.GetFrameClose();
             aviManager.Close();
             endPointTracker.Value = Convert.ToInt32(endPointTrackerText.Text);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
예제 #12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            /*Console.WriteLine("private int[,,] VxTable0_A_Ref_Simple = {");
            for (int i = 0; i < 32; i++)
            {
                Console.Write("{");
                for (int j = 0; j < 64; j++)
                {
                    Console.Write("{");
                    for (int k = 0; k < 2; k++)
                    {
                        ushort search = (ushort)((i << 4) | (j << 9) | (k << 15));
                        int idx = Array.FindIndex(LibMobiclip.Codec.Mobiclip.MobiConst.Vx2Table0_A, (a) => (a & 0xFFF0) == search);
                        Console.Write("{0}", idx);
                        if (k < 1) Console.Write(", ");
                    }
                    Console.Write("}");
                    if (j < 63) Console.Write(", ");
                }
                Console.WriteLine("}, ");
            }
            Console.WriteLine("};");*/
            //tempoarly use a memorystream
            //Use a filestream later on
            AviManager m = new AviManager(@"d:\Projects\DS\Moflex\Test\TestVid.avi", true);
            VideoStream ss = m.GetVideoStream();
            FileStream fs = File.Create(@"d:\Projects\DS\Moflex\Test\bw_TestVid_new_short_9.moflex");
            int scale = 1;
            double rate = Math.Round(ss.FrameRate, 3);
            while ((rate % 1.0) != 0)
            {
                scale *= 10;
                rate *= 10;
            }
            ss.GetFrameOpen();
            MoflexSimpleVideoMuxer mux = new MoflexSimpleVideoMuxer(fs, ss.GetBitmap(0), (int)rate, scale);
            for (int i = 1; i < ss.CountFrames / 4; i++)
            {
                mux.AddFrame(ss.GetBitmap(i));
            }
            ss.GetFrameClose();
            mux.FinalizeMoflex();
            fs.Close();
            return;
            /* MemoryStream m = new MemoryStream();
             MoflexMuxer mux = new MoflexMuxer(m);
             mux.WriteSynchroHeader();
             mux.WriteSynchroChunk(new MoLiveStreamVideo(25, 1, 400, 240, 1, 1));
             mux.WriteSynchroChunk(null);
             byte[] data = MobiclipEncoder.Encode(new Bitmap(new MemoryStream(File.ReadAllBytes(@"d:\Projects\DS\Moflex\TestPic3.png"))));
             if (data.Length <= (0x1000 - 0x80))//save margin
             {
                 mux.WriteDataBlock();
                 mux.WriteEp(0, data, 0, data.Length, true);
                 mux.WriteEp(0, null, 0, 0);
             }
             else
             {
                 int pos = 0;
                 int left = data.Length;
                 while (left >= (0x1000 - 0x80))
                 {
                     mux.WriteDataBlock();
                     mux.WriteEp(0, data, pos, 0x1000 - 0x80, left == (0x1000 - 0x80));
                     mux.WriteEp(0, null, 0, 0);
                     pos += 0x1000 - 0x80;
                     left -= 0x1000 - 0x80;
                 }
                 if (left > 0)
                 {
                     mux.WriteDataBlock();
                     mux.WriteEp(0, data, pos, left, true);
                     mux.WriteEp(0, null, 0, 0);
                 }
             }
             m.Write(new byte[0x1000], 0, 0x1000);
             byte[] res = m.ToArray();
             m.Close();
             File.Create(@"d:\Projects\DS\Moflex\TestPic3.moflex").Close();
             File.WriteAllBytes(@"d:\Projects\DS\Moflex\TestPic3.moflex", res);*/

            //return;
            /*byte[] data = File.ReadAllBytes(@"d:\Temp\ev110.sfd");
            int offs = 0;//0x01D718 + 4;// 70 16 02 00; 
            while (true)
            {
                AsmData d = new AsmData(160, 120, AsmData.MobiclipVersion.Moflex3DS);
                d.Data = data;
                d.Offset = offs++;
                Bitmap b = d.MobiclipUnpack_0_0();
                if (b != null)
                {
                    //offs = d.Offset;// +4;
                }
            }*/
            /* var d = new MoLiveDemux(new MemoryStream(File.ReadAllBytes(@"d:\Old\Temp\3DS Files\MK7\Mobi\CourseSelectRace\CourseSelectRace.moflex")));
             uint res;
             while ((res = d.ReadPacket()) == 0) ;
             d.s2.Flush();
             d.s2.Close();*/
            OpenFileDialog f = new OpenFileDialog();
            f.Filter = "All Supported Mobiclip Video Files (*.moflex;*.mods;*.dat)|*.moflex;*.mods;*.dat;*.mo|3DS Mobiclip Video Files (*.moflex)|*.moflex|DS Mobiclip Video Files (*.mods)|*.mods|Wii Mobiclip Video Files (*.dat;*.mo)|*.dat;*.mo";
            if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK
                && f.FileName.Length > 0)
            {
                byte[] sig = new byte[4];
                Stream s = File.OpenRead(f.FileName);
                s.Read(sig, 0, 4);
                s.Close();
                if (sig[0] == 0x4C && sig[1] == 0x32 && sig[2] == 0xAA && sig[3] == 0xAB)
                {
                    MobiThread = new Thread((ParameterizedThreadStart)MoflexThreadMain);
                    MobiThread.Start(f.FileName);
                }
                else if (sig[0] == 0x4D && sig[1] == 0x4F && sig[2] == 0x44 && sig[3] == 0x53)
                {
                    MobiThread = new Thread((ParameterizedThreadStart)ModsThreadMain);
                    MobiThread.Start(f.FileName);
                }
                else if (sig[0] == 0x4D && sig[1] == 0x4F && sig[2] == 0x43 && sig[3] == 0x35)
                {
                    MobiThread = new Thread((ParameterizedThreadStart)MOC5ThreadMain);
                    MobiThread.Start(f.FileName);
                }
                //else if (sig[0] == 0x56 && sig[1] == 0x58 && sig[2] == 0x44 && sig[3] == 0x53)
                //{
                //    MobiThread = new Thread((ParameterizedThreadStart)VxThreadMain);
                //    MobiThread.Start(f.FileName);
                //}
                else Application.Exit();
            }
            else Application.Exit();
        }
예제 #13
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (editableStream != null) {
                editableStream.Close();
            }

            AviManager file = new AviManager(txtAviFileName.Text, true);
            VideoStream stream = file.GetVideoStream();
            editableStream = new EditableVideoStream(stream);
            file.Close();

            numFirst.Maximum = editableStream.CountFrames - 1;
            numFirst.Value = 0;

            numPastePositionStream.Maximum = editableStream.CountFrames - 1;
            numPastePositionStream.Value = 0;

            numLast.Maximum = editableStream.CountFrames - 1;
            numLast.Value = editableStream.CountFrames - 1;

            if (numFrameRate.Maximum < (decimal)editableStream.FrameRate) {
                numFrameRate.Maximum = (decimal)editableStream.FrameRate;
            }
            numFrameRate.Value = (decimal)editableStream.FrameRate;

            panelEditor.Enabled = true;
        }
예제 #14
0
        public void DoCompressionWork()
        {
            AviManager videoManager = new AviManager(tempFilePath, true);
            VideoStream stream = videoManager.GetVideoStream();

            Exception exception = null;

            VideoStream newStream = null;
            AviManager newManager = null;

            try
            {
                newManager = stream.DecompressToNewFile(finalFilePath, true, out newStream);
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                try { videoManager.Close(); }
                catch (Exception) { }

                try { newManager.Close(); }
                catch (Exception) { }
            }

            InvokeCompressionCompleteEvents(exception);
            isCompressionRunning = false;
        }
 private void startToConvert_Click(object sender, EventArgs e)
 {
     AviManager aviManager = new AviManager(fileNameText.Text, true);
     VideoStream stream = aviManager.GetVideoStream();
     stream.GetFrameOpen();
     fileName = fileNameText.Text;
     int length = fileName.Length, j;
     for (j = length - 1; j > 0; j--)
     {
         if (fileName[j] != '\\')
             newfileName += fileName[j];
         else
             break;
     }
     fileName = "";
     for (j = newfileName.Length - 1; j >= 0; j--)
         fileName += newfileName[j];
     fileName = fileName.ToLower();
     j = 0;
     path = "";
     for (j = 0; j < fileNameText.Text.Length - fileName.Length; j++)
         path += fileNameText.Text[j];
     int startFrame = Convert.ToInt32(startPointTrackerText.Text);
     int endFrame = Convert.ToInt32(endPointTrackerText.Text);
     string bmpname = "";
     int ali = 0;
     for (int n = startFrame; n < endFrame; n++)
     {
         bmpname = ali.ToString();
         stream.ExportBitmap(n, "c:/temp/" + bmpname + ".bmp");
         pathBox.Items.Add("c:/temp/" + bmpname + ".bmp");
         ali++;
         startPointTracker.Value = n;
         textBox3.Text = n.ToString();
     }
     stream.GetFrameClose();
     aviManager.Close();
     makeAvi();
 }
예제 #16
0
        private void ShowFrame()
        {
            if (System.IO.File.Exists(txtAviFileName.Text)) {
                try {
                    AviManager aviManager = new AviManager(txtAviFileName.Text, true);
                    VideoStream aviStream = aviManager.GetVideoStream();
                    aviStream.GetFrameOpen();

                    Bitmap bmp = aviStream.GetBitmap(Convert.ToInt32(numPosition.Value));
                    picFrame.Image = bmp;
                    aviStream.GetFrameClose();
                    aviManager.Close();
                } catch (Exception ex) {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
예제 #17
0
        public void Open(string file)
        {
            lock (this)
            {
                _aviManager = new AviManager(file, true);
                _videoStream = _aviManager.GetVideoStream();

                _videoStream.GetFrameOpen();
                _currentFrame = 0;
                _frameBuffer.Clear();
            }

            _threadFillBuffer = new Thread(this.FillBuffer) {Priority = ThreadPriority.Highest};
            _threadFillBuffer.Start();
        }
예제 #18
0
        private void btnExtractPart_Click(object sender, EventArgs e)
        {
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);
            VideoStream aviStream = aviManager.GetVideoStream();

            CopyForm dialog = new CopyForm(0, (int)Math.Floor(aviStream.CountFrames / aviStream.FrameRate));
            if (dialog.ShowDialog() == DialogResult.OK) {
                int startSecond = dialog.Start;
                int stopSecond = dialog.Stop;

                txtReportCopy.Text = "Cutting seconds from " + txtAviFileName.Text + " to video.avi...\r\n";
                AviManager newFile = aviManager.CopyTo("..\\..\\testdata\\video.avi", startSecond, stopSecond);
                newFile.Close();
                txtReportCopy.Text += "...finished.";
            }
            aviManager.Close();
        }
        private List<Bitmap> readVideoAsImages(string filepathToOpen)
        {
            AviManager avm = new AviManager(filepathToOpen, true);

            VideoStream vs = avm.GetVideoStream();
            vs.GetFrameOpen();

            List<Bitmap> frames = new List<Bitmap>();

            for(int i = 0; i < vs.CountFrames; i++)
            {
                frames.Add(vs.GetBitmap(i));
            }
            vs.GetFrameClose();
            avm.Close();
            return frames;
        }
예제 #20
0
        /// <summary>
        /// Создание анимации из файла *.avi (при этом палитра если возможно берется из одноименного файла *.pal) (TODO: поддрежка формата *.gif)
        /// </summary>
        /// <param name="file"></param>
        public void ImportFromFile(string file)
        {
            if (!File.Exists(file)) return;
            //Palette = new ushort[0x100];
            //Frames = new List<FrameEdit>();
            //idxextra = 0x00000000; // хз

            ClearFrames();
            switch(Path.GetExtension(file)) {
                case ".avi" :
                    var filename = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));
                    var avi = new AviManager(filename+".avi", true);
                    var stream = avi.GetVideoStream();
                    stream.GetFrameOpen();
                    var frames = new Bitmap[stream.CountFrames];
                    for (int pos = 0; pos < stream.CountFrames; ++pos)
                        frames[pos] = stream.GetBitmap(pos);
                    stream.GetFrameClose();
                    avi.Close();

                    if (File.Exists(filename+".pal"))
                        this.GetPalPalette(filename+".pal");
                    else this.GetImagePalette(frames);

                    if (Frames == null)
                        Frames = new List<FrameEdit>();
                    foreach (var frame in frames)
                        Frames.Add(new FrameEdit(frame, FrameEdit.GetSingleRect(frame), Palette, frame.Width/2, -frame.Height/4));
                        //this.AddFrame(frame);

                    break;
                case ".gif" :
                    throw new NotImplementedException();
                    break;
                default : throw new FileFormatException();
            }
        }
        private void saveWithVoiceStart_Click(object sender, EventArgs e)
        {
            AviManager aviManager = new AviManager(fileNameText.Text, true);
            VideoStream aviStream = aviManager.GetVideoStream();

            CopyForm dialog = new CopyForm(0, (int)Math.Floor(aviStream.CountFrames / aviStream.FrameRate));
            if (dialog.ShowDialog() == DialogResult.OK) {
                int startSecond = dialog.Start;
                int stopSecond = dialog.Stop;
                SaveFileDialog saveWithVoice = new SaveFileDialog();
                if (saveWithVoice.ShowDialog() == DialogResult.OK)
                {
                    noticeText.Text = fileNameText.Text+ " dosyasinin " + saveWithVoice.FileName.ToString() +" dosyasina d�n�s�m� basladi\r\n";
                    AviManager newFile = aviManager.CopyTo(saveWithVoice.FileName.ToString()+".avi", startSecond, stopSecond);
                    newFile.Close();
                    noticeText.Text += "...finished.";
                }
            }
            aviManager.Close();
        }