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; } }
public VideoTexture(SceneManager scm, float width, float height, string aviFileName) { AviManager aviMgr = new AviManager(aviFileName, true); Stream = aviMgr.GetVideoStream(); TexturePtr VideoTexture = TextureManager.Singleton.CreateManual( "Video", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, Convert.ToUInt32(Stream.Width), Convert.ToUInt32(Stream.Height), 0, PixelFormat.PF_R8G8B8A8, (int)TextureUsage.TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); MaterialPtr VideoMat = MaterialManager.Singleton.Create( "VideoMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); VideoMat.GetTechnique(0).GetPass(0).LightingEnabled = false; VideoMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("Video"); PixelBuffer = VideoTexture.GetBuffer(); screen = scm.CreateManualObject("Screen"); screen.Dynamic = true; screen.Begin("VideoMat", RenderOperation.OperationTypes.OT_TRIANGLE_LIST); screen.Position(0, 0, 0); screen.TextureCoord(0, 0); screen.Position(width, 0, 0); screen.TextureCoord(1, 0); screen.Position(width, height, 0); screen.TextureCoord(1, 1); screen.Triangle(0, 1, 2); screen.Position(0, 0, 0); screen.TextureCoord(0, 0); screen.Position(width, height, 0); screen.TextureCoord(1, 1); screen.Position(0, height, 0); screen.TextureCoord(0, 1); screen.Triangle(3, 4, 5); screen.End(); SceneNode node = scm.RootSceneNode.CreateChildSceneNode(); node.Position = new Vector3(0, 0, 0); node.AttachObject(screen); Stream.GetFrameOpen(); FrameNum = 0; }
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 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(); }
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 open() { aviManager = new AviManager(file, true); aviStream = aviManager.GetVideoStream(); aviStream.GetFrameOpen(); framecount = aviStream.CountFrames; label2.Text = framecount.ToString(); bmp = aviStream.GetBitmap(i); label6.Text = bmp.Width.ToString(); //宽度 label4.Text = bmp.Height.ToString(); //高度 pictureBox1.Width = (bmp.Width); pictureBox1.Height = (bmp.Height); pictureBox1.Image = bmp; label8.Text = i.ToString();//当前帧数 Form2 f = new Form2(); f.Width = (bmp.Width) + 200; f.Height = (bmp.Height) + 300; }
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 Play() { video.GetFrameOpen(); }