diff --git a/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs b/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs index 385285f57e..c46f327cf2 100644 --- a/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs +++ b/BizHawk.Client.EmuHawk/AVOut/FFmpegWriter.cs @@ -77,31 +77,38 @@ namespace BizHawk.Client.EmuHawk /// void OpenFileSegment() { - ffmpeg = new Process(); + try + { + ffmpeg = new Process(); #if WINDOWS - ffmpeg.StartInfo.FileName = System.IO.Path.Combine(PathManager.GetBasePathAbsolute(), "dll", "ffmpeg.exe"); + ffmpeg.StartInfo.FileName = System.IO.Path.Combine(PathManager.GetBasePathAbsolute(), "dll", "ffmpeg.exe"); #else - ffmpeg.StartInfo.FileName = "ffmpeg"; // expecting native version to be in path + ffmpeg.StartInfo.FileName = "ffmpeg"; // expecting native version to be in path #endif - string filename = String.Format("{0}_{1,4:D4}{2}", baseName, segment, ext); + string filename = String.Format("{0}_{1,4:D4}{2}", baseName, segment, ext); + ffmpeg.StartInfo.Arguments = String.Format("-y -f nut -i - {1} \"{0}\"", filename, token.commandline); + ffmpeg.StartInfo.CreateNoWindow = true; - ffmpeg.StartInfo.Arguments = String.Format("-y -f nut -i - {1} \"{0}\"", filename, token.commandline); + // ffmpeg sends informative display to stderr, and nothing to stdout + ffmpeg.StartInfo.RedirectStandardError = true; + ffmpeg.StartInfo.RedirectStandardInput = true; + ffmpeg.StartInfo.UseShellExecute = false; - ffmpeg.StartInfo.CreateNoWindow = true; + commandline = "ffmpeg " + ffmpeg.StartInfo.Arguments; - // ffmpeg sends informative display to stderr, and nothing to stdout - ffmpeg.StartInfo.RedirectStandardError = true; - ffmpeg.StartInfo.RedirectStandardInput = true; - ffmpeg.StartInfo.UseShellExecute = false; + ffmpeg.ErrorDataReceived += new DataReceivedEventHandler(StderrHandler); - commandline = "ffmpeg " + ffmpeg.StartInfo.Arguments; + stderr = new Queue(consolebuffer); - ffmpeg.ErrorDataReceived += new DataReceivedEventHandler(StderrHandler); - - stderr = new Queue(consolebuffer); - - ffmpeg.Start(); + ffmpeg.Start(); + } + catch + { + ffmpeg.Dispose(); + ffmpeg = null; + throw; + } ffmpeg.BeginErrorReadLine(); muxer = new NutMuxer(width, height, fpsnum, fpsden, sampleRate, channels, ffmpeg.StandardInput.BaseStream); @@ -132,6 +139,7 @@ namespace BizHawk.Client.EmuHawk // how long should we wait here? ffmpeg.WaitForExit(20000); + ffmpeg.Dispose(); ffmpeg = null; stderr = null; commandline = null; @@ -269,7 +277,6 @@ namespace BizHawk.Client.EmuHawk this.channels = channels; } - public override string ToString() { return "FFmpeg writer"; diff --git a/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs b/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs index 09f26133c6..6e2441f302 100644 --- a/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs +++ b/BizHawk.Client.EmuHawk/AVOut/NutMuxer.cs @@ -15,6 +15,7 @@ namespace BizHawk.Client.EmuHawk { // this code isn't really any good for general purpose nut creation + #region binary write helpers /// /// variable length value, unsigned @@ -100,6 +101,7 @@ namespace BizHawk.Client.EmuHawk } stream.Write(b, 0, 8); } + /// /// big endian 32 bit unsigned /// @@ -115,6 +117,7 @@ namespace BizHawk.Client.EmuHawk } stream.Write(b, 0, 4); } + /// /// big endian 32 bit unsigned /// @@ -131,6 +134,10 @@ namespace BizHawk.Client.EmuHawk stream.Write(b, 0, 4); } + #endregion + + #region CRC calculator + static readonly uint[] CRCtable = new uint[] { 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, @@ -156,7 +163,7 @@ namespace BizHawk.Client.EmuHawk return crc; } - + #endregion /// /// writes a single packet out, including checksums @@ -264,6 +271,7 @@ namespace BizHawk.Client.EmuHawk } } + #region fields /// /// stores basic AV parameters @@ -320,6 +328,9 @@ namespace BizHawk.Client.EmuHawk /// Queue audioqueue; + #endregion + + #region header writers /// /// write out the main header @@ -409,6 +420,8 @@ namespace BizHawk.Client.EmuHawk header.Flush(); } + #endregion + /// /// stores a single frame with syncpoint, in mux-ready form /// used because reordering of audio and video can be needed for proper interleave @@ -502,14 +515,6 @@ namespace BizHawk.Client.EmuHawk return left >= right; } - - static NutFrame() - { - //dbg = new StreamWriter(".\\nutframe.txt", false); - } - - //static StreamWriter dbg; - /// /// write out frame, with syncpoint and all headers /// @@ -519,10 +524,8 @@ namespace BizHawk.Client.EmuHawk dest.Write(data, 0, data.Length); //dbg.WriteLine(string.Format("{0},{1},{2}", pts, ptsnum, ptsden)); } - } - /// /// write a video frame to the stream /// @@ -540,9 +543,6 @@ namespace BizHawk.Client.EmuHawk audioqueue.Dequeue().WriteData(output); } - - - /// /// write an audio frame to the stream /// @@ -629,4 +629,3 @@ namespace BizHawk.Client.EmuHawk } } } -