ffmpeg writer: cleanup

This commit is contained in:
goyuken 2014-07-30 01:35:48 +00:00
parent 3abd2da5c6
commit 11d2216c98
2 changed files with 38 additions and 32 deletions

View File

@ -77,31 +77,38 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
void OpenFileSegment() void OpenFileSegment()
{ {
ffmpeg = new Process(); try
{
ffmpeg = new Process();
#if WINDOWS #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 #else
ffmpeg.StartInfo.FileName = "ffmpeg"; // expecting native version to be in path ffmpeg.StartInfo.FileName = "ffmpeg"; // expecting native version to be in path
#endif #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.ErrorDataReceived += new DataReceivedEventHandler(StderrHandler);
ffmpeg.StartInfo.RedirectStandardError = true;
ffmpeg.StartInfo.RedirectStandardInput = true;
ffmpeg.StartInfo.UseShellExecute = false;
commandline = "ffmpeg " + ffmpeg.StartInfo.Arguments; stderr = new Queue<string>(consolebuffer);
ffmpeg.ErrorDataReceived += new DataReceivedEventHandler(StderrHandler); ffmpeg.Start();
}
stderr = new Queue<string>(consolebuffer); catch
{
ffmpeg.Start(); ffmpeg.Dispose();
ffmpeg = null;
throw;
}
ffmpeg.BeginErrorReadLine(); ffmpeg.BeginErrorReadLine();
muxer = new NutMuxer(width, height, fpsnum, fpsden, sampleRate, channels, ffmpeg.StandardInput.BaseStream); 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? // how long should we wait here?
ffmpeg.WaitForExit(20000); ffmpeg.WaitForExit(20000);
ffmpeg.Dispose();
ffmpeg = null; ffmpeg = null;
stderr = null; stderr = null;
commandline = null; commandline = null;
@ -269,7 +277,6 @@ namespace BizHawk.Client.EmuHawk
this.channels = channels; this.channels = channels;
} }
public override string ToString() public override string ToString()
{ {
return "FFmpeg writer"; return "FFmpeg writer";

View File

@ -15,6 +15,7 @@ namespace BizHawk.Client.EmuHawk
{ {
// this code isn't really any good for general purpose nut creation // this code isn't really any good for general purpose nut creation
#region binary write helpers
/// <summary> /// <summary>
/// variable length value, unsigned /// variable length value, unsigned
@ -100,6 +101,7 @@ namespace BizHawk.Client.EmuHawk
} }
stream.Write(b, 0, 8); stream.Write(b, 0, 8);
} }
/// <summary> /// <summary>
/// big endian 32 bit unsigned /// big endian 32 bit unsigned
/// </summary> /// </summary>
@ -115,6 +117,7 @@ namespace BizHawk.Client.EmuHawk
} }
stream.Write(b, 0, 4); stream.Write(b, 0, 4);
} }
/// <summary> /// <summary>
/// big endian 32 bit unsigned /// big endian 32 bit unsigned
/// </summary> /// </summary>
@ -131,6 +134,10 @@ namespace BizHawk.Client.EmuHawk
stream.Write(b, 0, 4); stream.Write(b, 0, 4);
} }
#endregion
#region CRC calculator
static readonly uint[] CRCtable = new uint[] static readonly uint[] CRCtable = new uint[]
{ {
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
@ -156,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
return crc; return crc;
} }
#endregion
/// <summary> /// <summary>
/// writes a single packet out, including checksums /// writes a single packet out, including checksums
@ -264,6 +271,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
#region fields
/// <summary> /// <summary>
/// stores basic AV parameters /// stores basic AV parameters
@ -320,6 +328,9 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
Queue<NutFrame> audioqueue; Queue<NutFrame> audioqueue;
#endregion
#region header writers
/// <summary> /// <summary>
/// write out the main header /// write out the main header
@ -409,6 +420,8 @@ namespace BizHawk.Client.EmuHawk
header.Flush(); header.Flush();
} }
#endregion
/// <summary> /// <summary>
/// stores a single frame with syncpoint, in mux-ready form /// stores a single frame with syncpoint, in mux-ready form
/// used because reordering of audio and video can be needed for proper interleave /// used because reordering of audio and video can be needed for proper interleave
@ -502,14 +515,6 @@ namespace BizHawk.Client.EmuHawk
return left >= right; return left >= right;
} }
static NutFrame()
{
//dbg = new StreamWriter(".\\nutframe.txt", false);
}
//static StreamWriter dbg;
/// <summary> /// <summary>
/// write out frame, with syncpoint and all headers /// write out frame, with syncpoint and all headers
/// </summary> /// </summary>
@ -519,10 +524,8 @@ namespace BizHawk.Client.EmuHawk
dest.Write(data, 0, data.Length); dest.Write(data, 0, data.Length);
//dbg.WriteLine(string.Format("{0},{1},{2}", pts, ptsnum, ptsden)); //dbg.WriteLine(string.Format("{0},{1},{2}", pts, ptsnum, ptsden));
} }
} }
/// <summary> /// <summary>
/// write a video frame to the stream /// write a video frame to the stream
/// </summary> /// </summary>
@ -540,9 +543,6 @@ namespace BizHawk.Client.EmuHawk
audioqueue.Dequeue().WriteData(output); audioqueue.Dequeue().WriteData(output);
} }
/// <summary> /// <summary>
/// write an audio frame to the stream /// write an audio frame to the stream
/// </summary> /// </summary>
@ -629,4 +629,3 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }