static void Main() { var disk = new FileSystem(); var baseDir = ConfigUtil.FindBasePath(disk); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } var dir = Path.Combine(baseDir, RelativePath); var files = Directory.EnumerateFiles(dir, "*.bin"); foreach (var file in files) { using var stream = File.OpenRead(file); using var br = new BinaryReader(stream); using var s = new AlbionReader(br); var flic = new FlicFile(s); var buffer = new byte[flic.Width * flic.Height]; AviFile.Write( Path.ChangeExtension(file, "avi"), flic.Speed, flic.Width, flic.Height, flic.Play(() => buffer).AllFrames32()); // break; } }
private void toolStripButton7_Click(object sender, EventArgs e) { try { AviFile avi = new AviFile(tstbPath.Text.Trim()); ls = avi.GetMaxFrameCount(); td = new Thread(new ThreadStart(convertavi)); td.Start(); tslfenjie.Visible = true; numericUpDown1.Maximum = ls; numericUpDown1.Minimum = 0; numericUpDown2.Maximum = ls; numericUpDown2.Value = ls; numericUpDown2.Minimum = 0; numericUpDown3.Maximum = ls; numericUpDown3.Minimum = 0; tslframe.Text = ls.ToString(); toolStripButton7.Enabled = false; lblDuration.Text = ls.ToString() + "帧"; FileInfo fi = new FileInfo(tstbPath.Text.Trim()); double x = fi.Length / 1024; lblFileSize.Text = x.ToString() + "KB"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Rewind() { Dispose(); aviManager = new AviFile(filepath); video = aviManager.GetVideoStream(); audio = aviManager.GetAudioStream(); }
public AviVideoStream(string filepath) { this.filepath = filepath; aviManager = new AviFile(filepath); video = aviManager.GetVideoStream(); audio = aviManager.GetAudioStream(); }
public void Dispose() { if (aviManager != null) { aviManager.Close(); } aviManager = null; }
private void convertavi() { try { string strg = Application.StartupPath.ToString(); strg = strg.Substring(0, strg.LastIndexOf("\\")); strg = strg.Substring(0, strg.LastIndexOf("\\")); strg += @"\ConverrtAviToBmp"; al.Clear(); AviFile.Initialize(); string filename = tstbPath.Text.Trim(); using (AviFile avi = new AviFile(filename)) { int max = avi.GetMaxFrameCount(); for (int i = 0; i < max; ++i) { Thread.Sleep(50); Bitmap bmp = avi.GetFrame(i); bmp.Save(strg + "\\" + i + ".bmp"); al.Add(strg + "\\" + i + ".bmp"); bmp.Dispose(); tslfenjie.Text = "正在解析..." + (i + 1) * 100 / max + "%"; ss++; } } AviFile.Terminate(); tslfenjie.Visible = false; toolStripButton2.Enabled = true; } catch { //convertavi(); } }
private void RecordPrivate(DisplayProvider displayProvider, SoundProvider soundProvider) { bool recordDisplay = displayProvider != null; bool recordSound = soundProvider != null; AviFile aviFile = null; AcmEncoder audioEncoder = null; this.duration = TimeSpan.Zero; try { DisplayFormat videoFormat = null; SoundFormat audioFormat = null; int soundReadInterval = 0; if (recordDisplay) { displayProvider.Open(); videoFormat = displayProvider.Format; } if (recordSound) { soundProvider.Open(); soundReadInterval = (int)Math.Ceiling(soundProvider.BufferLength / 2.0); // ms audioFormat = soundProvider.Format; audioEncoder = soundProvider.GetEncoder(); } // Open AVI file aviFile = new AviFile(); aviFile.Open(fileName, videoFormat, fps, this.compressor, audioFormat, audioEncoder); // Initialize helper variables int frameIndex = 0; int frameDuration = recordDisplay ? (int)(msPerSecond / this.fps) : 0; int frameBufferLength = recordDisplay ? displayProvider.BitmapBytes : 0; int startingFrameIndex = 0; int soundSampleIndex = 0; long startTime = DateTime.Now.Ticks; long lastSoundRead = DateTime.Now.Ticks; TimeSpan prevDuration = TimeSpan.Zero; TimeSpan currentDuration = TimeSpan.Zero; // Update state lock (syncRoot) { this.state = RecordingState.Recording; } if (recordSound) { // Start sound recording soundProvider.Start(); } // Recording loop; this is a long one huh?! do { // Check if paused if (this.state == RecordingState.Paused) { prevDuration = prevDuration.Add(currentDuration); if (recordSound) { // Read remaining sound data and stop sound recording byte[] soundData = soundProvider.Read(true); soundSampleIndex += aviFile.AddSound(soundSampleIndex, soundData, true); soundProvider.Stop(); } // Let the thread executing Pause() know that pause is done this.stateTransition.Set(); while (this.state == RecordingState.Paused) { Thread.Sleep(pauseDelay); } // State is changed, check new state if (this.state == RecordingState.Idle) { return; } // Resume() is called if (recordSound) { soundProvider.Start(); lastSoundRead = DateTime.Now.Ticks; } if (recordDisplay) { startingFrameIndex = frameIndex; } // Reset duration variables startTime = DateTime.Now.Ticks; currentDuration = TimeSpan.Zero; // Let that executing thread known resume is done this.stateTransition.Set(); } // Add a video from if (recordDisplay) { // Render display and add rendered bitmap to the avi file displayProvider.Render(); IntPtr pFrameData = displayProvider.Lock(); try { aviFile.AddFrame(pFrameData, frameIndex, 1, frameBufferLength); } finally { displayProvider.Unlock(); } frameIndex++; } // Add sound if (recordSound) { // Read recorded sound if it's time to do so if ((DateTime.Now.Ticks - lastSoundRead) / ticksPerMs >= soundReadInterval) { // Read sound data SoundFormat sourceFormat = soundProvider.SourceFormat; byte[] soundData = soundProvider.Read(); int samplesRead = (int)(soundData.Length / sourceFormat.BlockAlign); // Get number of out of sync samples TimeSpan durationByNow = prevDuration + new TimeSpan(DateTime.Now.Ticks - startTime); int nOutOfSyncSamples = GetOutOfSyncSamples(soundProvider, soundSampleIndex, durationByNow, samplesRead); if (nOutOfSyncSamples > 0) { // Add silence samples if we have less than expected samples soundSampleIndex += aviFile.AddSilence(soundSampleIndex, nOutOfSyncSamples); } else if (nOutOfSyncSamples < 0) { // Drop read samples as much as possible if we have more than expected samples int nSamplesToKeep = Math.Max(0, samplesRead + nOutOfSyncSamples); if (nSamplesToKeep > 0) { int nBytesToKeep = nSamplesToKeep * sourceFormat.BlockAlign; int nBytesToDrop = soundData.Length - nBytesToKeep; byte[] droppedSoundData = new byte[nBytesToKeep]; Array.Copy(soundData, nBytesToDrop, droppedSoundData, 0, nBytesToKeep); soundData = droppedSoundData; } samplesRead = nSamplesToKeep; } // Add sound data to the avi file if (samplesRead > 0) { soundSampleIndex += aviFile.AddSound(soundSampleIndex, soundData, false); } lastSoundRead = DateTime.Now.Ticks; } } // Synchronize display if (recordDisplay) { long delay = (DateTime.Now.Ticks - startTime) / ticksPerMs - frameDuration * ((frameIndex - startingFrameIndex) - 1); if (delay < frameDuration) { // Extra delay to synchornize with fps Thread.Sleep((int)(frameDuration - delay)); } else { // Calculate how many frames are lost int lostFrames = (int)Math.Floor((decimal)delay / frameDuration); frameIndex += lostFrames; // Extra delay to synchornize with fps Thread.Sleep((int)(frameDuration - delay % frameDuration)); } } else /* No display recording, just sleep for a while so that sound buffers get filled */ { Thread.Sleep(1); } // Update duration currentDuration = new TimeSpan(DateTime.Now.Ticks - startTime); this.duration = prevDuration + currentDuration; } while (this.state != RecordingState.Idle); // Read remaining sound data and stop sound recording if (recordSound) { byte[] soundData = soundProvider.Read(true); soundSampleIndex += aviFile.AddSound(soundSampleIndex, soundData, true); soundProvider.Stop(); } } finally { if (recordSound) { soundProvider.Close(); if (audioEncoder != null) { audioEncoder.Dispose(); } } if (recordDisplay) { displayProvider.Close(); } if (aviFile != null) { aviFile.Dispose(); } } }