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(); }
public void Dispose() { Stream.GetFrameClose(); PixelBuffer.Dispose(); screen.Dispose(); videoMat.Dispose(); videoTex.Dispose(); videoTex = null; videoMat = null; screen = null; PixelBuffer = null; FrameNum = 0; }
public void Close() { lock (this) { if (_threadFillBuffer != null) { _threadFillBuffer.Abort(); } _videoStream.GetFrameClose(); _aviManager.Close(); _frameBuffer.Clear(); } }
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()); } } }
private void ShowFrameTrackTwo() { 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(endPointTracker.Value)); bmp.SetResolution(rlPicBox.Width, rlPicBox.Height); smplPicBox.Image = bmp; aviStream.GetFrameClose(); aviManager.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
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(); }
public static SnmFile FromAviFile(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException(); } var snm = new SnmFile(); var aviManager = new AviManager(fileName); try { AudioStream audioStream = aviManager.GetWaveStream(); byte[] audioData = null; if (audioStream != null) { if (audioStream.ChannelsCount != 2 || audioStream.BitsPerSample != 16) { throw new InvalidDataException(); } if (audioStream.SamplesPerSecond != 22050 && audioStream.SamplesPerSecond != 44100) { throw new NotSupportedException(); } snm.AudioHeader = new SnmAudioHeader { Frequency = audioStream.SamplesPerSecond, NumChannels = audioStream.ChannelsCount }; audioData = audioStream.GetStreamData(); if (snm.AudioHeader.Frequency == 44100) { snm.AudioHeader.Frequency = 22050; audioData = SnmFile.ConvertAudio44100To22050(audioData); } } VideoStream videoStream = aviManager.GetVideoStream(); if (videoStream.BitsPerPixel != 24 && videoStream.BitsPerPixel != 32) { throw new NotSupportedException(); } snm.Header.FrameDelay = (int)(1000000 / videoStream.FrameRate + 0.5); snm.Header.Width = (short)videoStream.Width; snm.Header.Height = (short)videoStream.Height; snm.Header.NumFrames = (short)videoStream.FramesCount; for (int i = 0; i < videoStream.FramesCount; i++) { snm.VideoHeaders.Add(new SnmVideoHeader { Width = snm.Header.Width, Height = snm.Header.Height }); } videoStream.GetFrameOpen(); try { int fps = (1000000 + snm.Header.FrameDelay / 2) / snm.Header.FrameDelay; int samplesPerFrame = snm.AudioHeader.Frequency / fps; if (samplesPerFrame * fps != snm.AudioHeader.Frequency) { throw new InvalidDataException(); } for (int i = 0; i < videoStream.FramesCount; i++) { byte[] videoData = videoStream.GetFrameData(i); var frame = new SnmFrame(); if (audioData != null) { int audioPosition = i * samplesPerFrame * 4; int audioLength = Math.Min(samplesPerFrame * 4, audioData.Length - audioPosition); if (audioPosition < audioData.Length && audioLength != 0) { frame.Audio = new SnmAudioFrame { NumSamples = audioLength / 4 }; byte[] buffer = new byte[audioLength]; Array.Copy(audioData, audioPosition, buffer, 0, audioLength); //frame.Audio.Data = Imc.Vima.Compress(buffer, 2); frame.Audio.Data = buffer; } } if (videoData != null) { frame.Video = new SnmVideoFrame { Width = snm.Header.Width, Height = snm.Header.Height, RleOutputSize = snm.Header.Width * snm.Header.Height * 2, SubcodecId = (byte)videoStream.BitsPerPixel, Data = videoData }; //byte[] buffer; //if (videoStream.BitsPerPixel == 24) //{ // buffer = SnmFile.Convert24BppTo16Bpp(videoData); //} //else //{ // buffer = SnmFile.Convert32BppTo16Bpp(videoData); //} //byte subcodecId; //frame.Video.Data = Blocky16.Compress(buffer, out subcodecId); //frame.Video.SubcodecId = subcodecId; } snm.Frames.Add(frame); } } finally { videoStream.GetFrameClose(); } } finally { aviManager.Close(); } snm.Frames .AsParallel() .ForAll(frame => { if (frame.Audio != null) { frame.Audio.Data = Imc.Vima.Compress(frame.Audio.Data, 2); } if (frame.Video != null) { byte[] buffer; if (frame.Video.SubcodecId == 24) { buffer = SnmFile.Convert24BppTo16Bpp(frame.Video.Data); } else { buffer = SnmFile.Convert32BppTo16Bpp(frame.Video.Data); } frame.Video.Data = Blocky16.Compress(buffer, out byte subcodecId); frame.Video.SubcodecId = subcodecId; } }); return(snm); }
public void Dispose() { Stream.GetFrameClose(); PixelBuffer.Dispose(); FrameNum = 0; }
public void Stop() { video.GetFrameClose(); positionInSeconds = 0f; }