private void btnExport_Click(object sender, EventArgs e)
		{
			if(mFrameInfos.Count == 0) return;

			int width, height;
			using(var bmp = new Bitmap(mFrameInfos[0].pngPath))
			{
				width = bmp.Width;
				height = bmp.Height;
			}

			var sfd = new SaveFileDialog();
			sfd.FileName = Path.ChangeExtension(mSynclessConfigFile, ".avi");
			sfd.InitialDirectory = Path.GetDirectoryName(sfd.FileName);
			if (sfd.ShowDialog() == DialogResult.Cancel)
				return;

			using (AviWriter avw = new AviWriter())
			{
				avw.SetAudioParameters(44100, 2, 16); //hacky
				avw.SetMovieParameters(60, 1); //hacky
				avw.SetVideoParameters(width, height);
				var token = avw.AcquireVideoCodecToken(this);
				avw.SetVideoCodecToken(token);
				avw.OpenFile(sfd.FileName);
				foreach (var fi in mFrameInfos)
				{
					using (var bb = new BitmapBuffer(fi.pngPath, new BitmapLoadOptions()))
					{
						var bbvp = new BitmapBufferVideoProvider(bb);
						avw.AddFrame(bbvp);
					}
					//offset = 44 dec
					var wavBytes = File.ReadAllBytes(fi.wavPath);
					var ms = new MemoryStream(wavBytes);
					ms.Position = 44;
					var br = new BinaryReader(ms);
					List<short> sampledata = new List<short>();
					while (br.BaseStream.Position != br.BaseStream.Length)
					{
						sampledata.Add(br.ReadInt16());
					}
					avw.AddSamples(sampledata.ToArray());
				}
				avw.CloseFile();
			}

		}
Exemple #2
0
        private void AvFrameAdvance()
        {
            GlobalWin.DisplayManager.NeedsToPaint = true;
            if (_currAviWriter != null)
            {
                //TODO ZERO - this code is pretty jacked. we'll want to frugalize buffers better for speedier dumping, and we might want to rely on the GL layer for padding
                try
                {
                    //is this the best time to handle this? or deeper inside?
                    if (_currAviWriterFrameList != null)
                    {
                        if (!_currAviWriterFrameList.Contains(Global.Emulator.Frame))
                            goto HANDLE_AUTODUMP;
                    }

                    IVideoProvider output;
                    IDisposable disposableOutput = null;
                    if (_avwriterResizew > 0 && _avwriterResizeh > 0)
                    {
                        BitmapBuffer bbin = null;
                        Bitmap bmpin = null;
                        Bitmap bmpout = null;
                        try
                        {
                            if (Global.Config.AVI_CaptureOSD)
                            {
                                bbin = CaptureOSD();
                            }
                            else
                            {
                                bbin = new BitmapBuffer(Global.Emulator.VideoProvider().BufferWidth, Global.Emulator.VideoProvider().BufferHeight, Global.Emulator.VideoProvider().GetVideoBuffer());
                            }

                            bmpout = new Bitmap(_avwriterResizew, _avwriterResizeh, PixelFormat.Format32bppArgb);
                            bmpin = bbin.ToSysdrawingBitmap();
                            using (var g = Graphics.FromImage(bmpout))
                            {
                                if (_avwriterpad)
                                {
                                    g.Clear(Color.FromArgb(Global.Emulator.VideoProvider().BackgroundColor));
                                    g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2);
                                }
                                else
                                {
                                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
                                    g.DrawImage(bmpin, new Rectangle(0, 0, bmpout.Width, bmpout.Height));
                                }
                            }

                            output = new BmpVideoProvider(bmpout);
                            disposableOutput = (IDisposable)output;
                        }
                        finally
                        {
                            if (bbin != null) bbin.Dispose();
                            if (bmpin != null) bmpin.Dispose();
                        }
                    }
                    else
                    {
                        if (Global.Config.AVI_CaptureOSD)
                        {
                            output = new BitmapBufferVideoProvider(CaptureOSD());
                            disposableOutput = (IDisposable)output;
                        }
                        else
                            output = Global.Emulator.VideoProvider();
                    }

                    _currAviWriter.SetFrame(Global.Emulator.Frame);

                    short[] samp;
                    int nsamp;
                    if (_dumpaudiosync)
                    {
                        (_currAviWriter as VideoStretcher).DumpAV(output, Global.Emulator.SyncSoundProvider, out samp, out nsamp);
                    }
                    else
                    {
                        (_currAviWriter as AudioStretcher).DumpAV(output, _aviSoundInput, out samp, out nsamp);
                    }

                    if (disposableOutput != null)
                    {
                        disposableOutput.Dispose();
                    }

                    _dumpProxy.buffer.enqueue_samples(samp, nsamp);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Video dumping died:\n\n" + e);
                    AbortAv();
                }

            HANDLE_AUTODUMP:
                if (_autoDumpLength > 0)
                {
                    _autoDumpLength--;
                    if (_autoDumpLength == 0) // finish
                    {
                        StopAv();
                        if (_autoCloseOnDump)
                        {
                            _exit = true;
                        }
                    }
                }

                GlobalWin.DisplayManager.NeedsToPaint = true;
            }
        }
Exemple #3
0
		private void AvFrameAdvance()
		{
			GlobalWin.DisplayManager.NeedsToPaint = true;
			if (_currAviWriter != null)
			{
				var nsampnum = 44100 * (long)Global.Emulator.CoreComm.VsyncDen + _soundRemainder;
				var nsamp = nsampnum / Global.Emulator.CoreComm.VsyncNum;

				// exactly remember fractional parts of an audio sample
				_soundRemainder = nsampnum % Global.Emulator.CoreComm.VsyncNum;

				var temp = new short[nsamp * 2];
				_aviSoundInput.GetSamples(temp);
				_dumpProxy.buffer.enqueue_samples(temp, (int)nsamp);

				//TODO ZERO - this code is pretty jacked. we'll want to frugalize buffers better for speedier dumping, and we might want to rely on the GL layer for padding
				try
				{
					IVideoProvider output;
					IDisposable disposableOutput = null;
					if (_avwriterResizew > 0 && _avwriterResizeh > 0)
					{
						BitmapBuffer bbin = null;
						Bitmap bmpin = null;
						Bitmap bmpout = null;
						try
						{
							if (Global.Config.AVI_CaptureOSD)
							{
								bbin = CaptureOSD();
							}
							else
							{
								bbin = new BitmapBuffer(Global.Emulator.VideoProvider.BufferWidth, Global.Emulator.VideoProvider.BufferHeight, Global.Emulator.VideoProvider.GetVideoBuffer());
							}


							bmpout = new Bitmap(_avwriterResizew, _avwriterResizeh, PixelFormat.Format32bppArgb);
							bmpin = bbin.ToSysdrawingBitmap();
							using (var g = Graphics.FromImage(bmpout))
							{
								if (_avwriterpad)
								{
									g.Clear(Color.FromArgb(Global.Emulator.VideoProvider.BackgroundColor));
									g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2);
								}
								else
								{
									g.DrawImage(bmpin, new Rectangle(0, 0, bmpout.Width, bmpout.Height));
								}
							}

							output = new BmpVideoProvider(bmpout);
							disposableOutput = (IDisposable)output;
						}
						finally
						{
							if (bbin != null) bbin.Dispose();
							if (bmpin != null) bmpin.Dispose();
						}
					}
					else
					{
						if (Global.Config.AVI_CaptureOSD)
						{
							output = new BitmapBufferVideoProvider(CaptureOSD());
							disposableOutput = (IDisposable)output;
						}
						else
							output = Global.Emulator.VideoProvider;
					}

					_currAviWriter.SetFrame(Global.Emulator.Frame);
					_currAviWriter.AddFrame(output);

					if (disposableOutput != null)
					{
						disposableOutput.Dispose();
					}

					_currAviWriter.AddSamples(temp);
				}
				catch (Exception e)
				{
					MessageBox.Show("Video dumping died:\n\n" + e);
					AbortAv();
				}

				if (_autoDumpLength > 0)
				{
					_autoDumpLength--;
					if (_autoDumpLength == 0) // finish
					{
						StopAv();
						if (_autoCloseOnDump)
						{
							_exit = true;
						}
					}
				}

				GlobalWin.DisplayManager.NeedsToPaint = true;
			}
		}