private bool ReadTag() { uint tagType, dataSize, timeStamp, streamID, mediaInfo; byte[] data; if (_fileLength - _fileOffset < 11) { return(false); } // Read tag header tagType = ReadUInt8(); dataSize = ReadUInt24(); timeStamp = ReadUInt24(); timeStamp |= ReadUInt8() << 24; streamID = ReadUInt24(); // Read tag data if (dataSize == 0) { return(true); } if (_fileLength - _fileOffset < dataSize) { return(false); } mediaInfo = ReadUInt8(); dataSize -= 1; data = ReadBytes((int)dataSize); if (tagType == 0x8) { // Audio if (_audioWriter == null) { _audioWriter = _extractAudio ? GetAudioWriter(mediaInfo) : new DummyAudioWriter(); ExtractedAudio = !(_audioWriter is DummyAudioWriter); } _audioWriter.WriteChunk(data, timeStamp); } else if (tagType == 0x9 && mediaInfo >> 4 != 5) { // Video if (_videoWriter == null) { _videoWriter = _extractVideo ? GetVideoWriter(mediaInfo) : new DummyVideoWriter(); ExtractedVideo = !(_videoWriter is DummyVideoWriter); } if (_timeCodeWriter == null) { var path = _outputPathBase + ".txt"; _timeCodeWriter = new TimeCodeWriter(_extractTimeCodes && CanWriteTo(path) ? path : null); ExtractedTimeCodes = _extractTimeCodes; } _videoTimeStamps.Add(timeStamp); _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4)); _timeCodeWriter.Write(timeStamp); } return(true); }
public void Stop() { lock (frameQueue_) lock (readyFrames_) { foreach (Shared.IMocapRecorder rec in cameras_) { rec.StopRecording(); } while (frameQueue_.Count > 0) { Bitmap bmp = ImageUtil.BitmapUtil.ToStrip(frameQueue_[0].CameraImages, frameQueue_[0].CameraImages[0].Size); readyFrames_.Add(bmp); frameQueue_.RemoveAt(0); } while (readyFrames_.Count > 0) { writer_.PushFrame(readyFrames_[0]); readyFrames_.RemoveAt(0); } writer_.Finish(); writer_ = null; } Program.RemoveThread(workingThread_); Program.RemoveThread(writingThread_); workingThread_.Abort(); writingThread_.Abort(); workingThread_ = null; writingThread_ = null; }
private void CloseOutput(FractionUInt32?averageFrameRate, bool disposing) { if (_videoWriter != null) { _videoWriter.Finish(averageFrameRate ?? new FractionUInt32(25, 1)); if (disposing && _videoWriter.Path != null) { try { File.Delete(_videoWriter.Path); } catch { } } _videoWriter = null; } if (_audioWriter != null) { _audioWriter.Finish(); if (disposing && _audioWriter.Path != null) { try { File.Delete(_audioWriter.Path); } catch { } } _audioWriter = null; } if (_timeCodeWriter != null) { _timeCodeWriter.Finish(); if (disposing && _timeCodeWriter.Path != null) { try { File.Delete(_timeCodeWriter.Path); } catch { } } _timeCodeWriter = null; } }
private bool ReadTag() { uint tagType, dataSize, timeStamp, mediaInfo; if ((_fileLength - _fileOffset) < 11) { return(false); } // Read tag header tagType = ReadUInt8(); dataSize = ReadUInt24(); timeStamp = ReadUInt24(); timeStamp |= ReadUInt8() << 24; ReadUInt24(); // Read tag data if (dataSize == 0) { return(true); } if ((_fileLength - _fileOffset) < dataSize) { return(false); } mediaInfo = ReadUInt8(); dataSize -= 1; byte[] data = ReadBytes((int)dataSize); if (tagType == 0x8 && this.audioOutputStream != null) { // Audio if (_audioWriter == null) { _audioWriter = this.GetAudioWriter(mediaInfo); this.AudioFormat = this._audioWriter.AudioFormat; } _audioWriter.WriteChunk(data, timeStamp); } else if ((tagType == 0x9) && ((mediaInfo >> 4) != 5) && this.videoOutputStream != null) { // Video if (_videoWriter == null) { _videoWriter = this.GetVideoWriter(mediaInfo); this.VideoFormat = this._videoWriter.VideoFormat; } _videoTimeStamps.Add(timeStamp); _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4)); } return(true); }
List <Bitmap> readyFrames_; // Frames that are ready to be written into the video file public ThreadedRecorder(Shared.CameraCollection cameras, IVideoWriter writer) { cameras_ = cameras; frameQueue_ = new List <FrameSet>(); readyFrames_ = new List <Bitmap>(); writer_ = writer; foreach (Shared.IMocapRecorder rec in cameras) { rec.OnFrame += rec_OnFrame; } }
public ThreadedRecorder(Shared.CameraCollection cameras, IVideoWriter writer) { cameras_ = cameras; frameQueue_ = new List<FrameSet>(); readyFrames_ = new List<Bitmap>(); writer_ = writer; foreach (Shared.IMocapRecorder rec in cameras) { rec.OnFrame += rec_OnFrame; } }
private void CloseOutput(FractionUInt32? averageFrameRate) { if (_videoWriter != null) { _videoWriter.Finish(averageFrameRate ?? new FractionUInt32(25, 1)); _videoWriter = null; } if (_audioWriter != null) { _audioWriter.Dispose(); _audioWriter = null; } }
public static IEnumerable <IVideoWriter> GetAllVideoWriters() { var ret = new IVideoWriter[] { new AviWriter(), new JMDWriter(), new WavWriterV(), new FFmpegWriter(), new NutWriter(), new GifWriter(), new SynclessRecorder() }; return(ret); }
/// <summary> /// find an IVideoWriter by its short name /// </summary> /// <param name="name"></param> /// <returns></returns> public static IVideoWriter GetVideoWriter(string name) { IVideoWriter ret = null; var vws = GetAllVideoWriters(); foreach (var vw in vws) { if (vw.ShortName() == name) { ret = vw; } } foreach (var vw in vws) { if (vw != ret) { vw.Dispose(); } } return(ret); }
public VideoStretcher(IVideoWriter w) { W = w; }
public AudioStretcher(IVideoWriter w) { this.W = w; }
public static IEnumerable<IVideoWriter> GetAllVideoWriters() { var ret = new IVideoWriter[] { new AviWriter(), new JMDWriter(), new WavWriterV(), new FFmpegWriter(), new NutWriter(), new GifWriter(), new SynclessRecorder() }; return ret; }
private bool ReadTag() { uint tagType, dataSize, timeStamp, mediaInfo; if ((_fileLength - _fileOffset) < 11) { return false; } // Read tag header tagType = ReadUInt8(); dataSize = ReadUInt24(); timeStamp = ReadUInt24(); timeStamp |= ReadUInt8() << 24; ReadUInt24(); // Read tag data if (dataSize == 0) { return true; } if ((_fileLength - _fileOffset) < dataSize) { return false; } mediaInfo = ReadUInt8(); dataSize -= 1; byte[] data = ReadBytes((int)dataSize); if (tagType == 0x8 && this.audioOutputStream != null) { // Audio if (_audioWriter == null) { _audioWriter = this.GetAudioWriter(mediaInfo); this.AudioFormat = this._audioWriter.AudioFormat; } _audioWriter.WriteChunk(data, timeStamp); } else if ((tagType == 0x9) && ((mediaInfo >> 4) != 5) && this.videoOutputStream != null) { // Video if (_videoWriter == null) { _videoWriter = this.GetVideoWriter(mediaInfo); this.VideoFormat = this._videoWriter.VideoFormat; } _videoTimeStamps.Add(timeStamp); _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4)); } return true; }
private void CloseOutput(FractionUInt32? averageFrameRate, bool disposing) { if (_videoWriter != null) { _videoWriter.Finish(averageFrameRate ?? new FractionUInt32(25, 1)); if (disposing && (_videoWriter.Path != null)) { try { File.Delete(_videoWriter.Path); } catch { } } _videoWriter = null; } if (_audioWriter != null) { _audioWriter.Finish(); if (disposing && (_audioWriter.Path != null)) { try { File.Delete(_audioWriter.Path); } catch { } } _audioWriter = null; } if (_timeCodeWriter != null) { _timeCodeWriter.Finish(); if (disposing && (_timeCodeWriter.Path != null)) { try { File.Delete(_timeCodeWriter.Path); } catch { } } _timeCodeWriter = null; } }
private void StopAv() { if (_currAviWriter == null) { _dumpProxy = null; RewireSound(); return; } _currAviWriter.CloseFile(); _currAviWriter.Dispose(); _currAviWriter = null; GlobalWin.OSD.AddMessage("A/V capture stopped"); AVIStatusLabel.Image = Properties.Resources.Blank; AVIStatusLabel.ToolTipText = string.Empty; AVIStatusLabel.Visible = false; _aviSoundInput = null; _dumpProxy = null; // return to normal sound output RewireSound(); }
public LoggingVideoWriter(IVideoWriter videoWriter, ILogger logger) { _videoWriter = videoWriter ?? throw new ArgumentNullException(nameof(videoWriter)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public static string WriterDescription(this IVideoWriter w) { return(w.GetAttribute <VideoWriterAttribute>().Description); }
public void Stop() { lock (frameQueue_) lock (readyFrames_) { foreach (Shared.IMocapRecorder rec in cameras_) rec.StopRecording(); while (frameQueue_.Count > 0) { Bitmap bmp = ImageUtil.BitmapUtil.ToStrip(frameQueue_[0].CameraImages, frameQueue_[0].CameraImages[0].Size); readyFrames_.Add(bmp); frameQueue_.RemoveAt(0); } while (readyFrames_.Count > 0) { writer_.PushFrame(readyFrames_[0]); readyFrames_.RemoveAt(0); } writer_.Finish(); writer_ = null; } Program.RemoveThread(workingThread_); Program.RemoveThread(writingThread_); workingThread_.Abort(); writingThread_.Abort(); workingThread_ = null; writingThread_ = null; }
public static string LongName(this IVideoWriter w) { return(w.GetAttribute <VideoWriterAttribute>().Name); }
public VideoStretcher(IVideoWriter w) { this.w = w; }
private void Shutdown() { if (_currAviWriter != null) { _currAviWriter.CloseFile(); _currAviWriter = null; } }
public TwitchChatDownloader(IVideoRetriever videoRetriever, IVideosRetriever videosRetriever, IVideoWriter videoWriter) { _videoRetriever = videoRetriever ?? throw new ArgumentNullException(nameof(videoRetriever)); _videosRetriever = videosRetriever ?? throw new ArgumentNullException(nameof(videosRetriever)); _videoWriter = videoWriter ?? throw new ArgumentNullException(nameof(videoWriter)); }
/// <summary> /// start AV recording /// </summary> private void _RecordAv(string videowritername, string filename, bool unattended) { if (_currAviWriter != null) { return; } // select IVideoWriter to use IVideoWriter aw = null; if (unattended) { aw = VideoWriterInventory.GetVideoWriter(videowritername); } else { aw = VideoWriterChooserForm.DoVideoWriterChoserDlg(VideoWriterInventory.GetAllWriters(), this, out _avwriterResizew, out _avwriterResizeh, out _avwriterpad, out _dumpaudiosync); } if (aw == null) { GlobalWin.OSD.AddMessage( unattended ? string.Format("Couldn't start video writer \"{0}\"", videowritername) : "A/V capture canceled."); return; } try { if (_dumpaudiosync) { aw = new VideoStretcher(aw); } else { aw = new AudioStretcher(aw); } aw.SetMovieParameters(Global.Emulator.CoreComm.VsyncNum, Global.Emulator.CoreComm.VsyncDen); if (_avwriterResizew > 0 && _avwriterResizeh > 0) { aw.SetVideoParameters(_avwriterResizew, _avwriterResizeh); } else { aw.SetVideoParameters(Global.Emulator.VideoProvider().BufferWidth, Global.Emulator.VideoProvider().BufferHeight); } aw.SetAudioParameters(44100, 2, 16); // select codec token // do this before save dialog because ffmpeg won't know what extension it wants until it's been configured if (unattended) { aw.SetDefaultVideoCodecToken(); } else { var token = aw.AcquireVideoCodecToken(this); if (token == null) { GlobalWin.OSD.AddMessage("A/V capture canceled."); aw.Dispose(); return; } aw.SetVideoCodecToken(token); } // select file to save to if (unattended) { aw.OpenFile(filename); } else { string ext = aw.DesiredExtension(); string pathForOpenFile; //handle directories first if (ext == "<directory>") { var fbd = new FolderBrowserEx(); if (fbd.ShowDialog() == DialogResult.Cancel) { aw.Dispose(); return; } pathForOpenFile = fbd.SelectedPath; } else { var sfd = new SaveFileDialog(); if (Global.Game != null) { sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "." + ext; //dont use Path.ChangeExtension, it might wreck game names with dots in them sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.AvPathFragment, null); } else { sfd.FileName = "NULL"; sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.AvPathFragment, null); } sfd.Filter = string.Format("{0} (*.{0})|*.{0}|All Files|*.*", ext); var result = sfd.ShowHawkDialog(); if (result == DialogResult.Cancel) { aw.Dispose(); return; } pathForOpenFile = sfd.FileName; } aw.OpenFile(pathForOpenFile); } // commit the avi writing last, in case there were any errors earlier _currAviWriter = aw; GlobalWin.OSD.AddMessage("A/V capture started"); AVIStatusLabel.Image = Properties.Resources.AVI; AVIStatusLabel.ToolTipText = "A/V capture in progress"; AVIStatusLabel.Visible = true; } catch { GlobalWin.OSD.AddMessage("A/V capture failed!"); aw.Dispose(); throw; } if (_dumpaudiosync) { Global.Emulator.EndAsyncSound(); } else { _aviSoundInput = !Global.Emulator.StartAsyncSound() ? new MetaspuAsync(Global.Emulator.SyncSoundProvider, ESynchMethod.ESynchMethod_V) : Global.Emulator.SoundProvider; } _dumpProxy = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); RewireSound(); }
public VideoStretcher(IVideoWriter w) { this.w = w; }
private bool ReadTag() { uint tagType, dataSize, timeStamp, streamID, mediaInfo; byte[] data; if ((_fileLength - _fileOffset) < 11) { return false; } // Read tag header tagType = ReadUInt8(); dataSize = ReadUInt24(); timeStamp = ReadUInt24(); timeStamp |= ReadUInt8() << 24; streamID = ReadUInt24(); // Read tag data if (dataSize == 0) { return true; } if ((_fileLength - _fileOffset) < dataSize) { return false; } mediaInfo = ReadUInt8(); dataSize -= 1; data = ReadBytes((int)dataSize); if (tagType == 0x8) { // Audio if (_audioWriter == null) { _audioWriter = _extractAudio ? GetAudioWriter(mediaInfo) : new DummyAudioWriter(); _extractedAudio = !(_audioWriter is DummyAudioWriter); } _audioWriter.WriteChunk(data, timeStamp); } else if ((tagType == 0x9) && ((mediaInfo >> 4) != 5)) { // Video if (_videoWriter == null) { _videoWriter = _extractVideo ? GetVideoWriter(mediaInfo) : new DummyVideoWriter(); _extractedVideo = !(_videoWriter is DummyVideoWriter); } if (_timeCodeWriter == null) { string path = _outputPathBase + ".txt"; _timeCodeWriter = new TimeCodeWriter((_extractTimeCodes && CanWriteTo(path)) ? path : null); _extractedTimeCodes = _extractTimeCodes; } _videoTimeStamps.Add(timeStamp); _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4)); _timeCodeWriter.Write(timeStamp); } return true; }
private void CloseOutput(FractionUInt32? averageFrameRate) { if (_videoWriter != null) { _videoWriter.Finish(averageFrameRate ?? new FractionUInt32(25, 1)); _videoWriter = null; } if (_audioWriter != null) { _audioWriter.Dispose(); _audioWriter = null; } }