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();
			}

		}
Example #2
0
        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
            {
                FileName = Path.ChangeExtension(mSynclessConfigFile, ".avi")
            };

            sfd.InitialDirectory = Path.GetDirectoryName(sfd.FileName);
            if (sfd.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            using (var 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)
                    {
                        Position = 44
                    };
                    var br         = new BinaryReader(ms);
                    var sampledata = new List <short>();
                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        sampledata.Add(br.ReadInt16());
                    }

                    avw.AddSamples(sampledata.ToArray());
                }

                avw.CloseFile();
            }
        }