Exemple #1
0
		/// <summary>
		/// Saves the video.
		/// </summary>
		/// <param name="fileName">Name of the file.</param>
		/// <param name="profileFileName">Name of the profile file.</param>
		/// <param name="dr">Dr.</param>
		public static void SaveVideo(string fileName, string profileFileName, ulong framesPerSecond, SqlDataReader dr)
		{
			WMEncoder encoder = new WMEncoder();
			IWMEncProfile2 profile = WMEncProfile.LoadEncodingProfile(encoder, profileFileName);
			WMEncProfile.ReleaseEncoder(ref encoder);
			
			using(WmvWriter writer = new WmvWriter())
			{
				
				writer.Initialize((IWMProfile)profile.SaveToIWMProfile(), fileName);
				
				VideoInfoHeader viHeader = new VideoInfoHeader();
				writer.FindVideoInputFormat(0, MediaSubTypes.WMMEDIASUBTYPE_RGB24, ref viHeader, false);
				writer.Start();

				
				INSSBuffer sample = null;
				int bmcount = 0;
				Bitmap c = new Bitmap((int)viHeader.bmiHeader.biWidth, (int)viHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);;
				ulong fps = viHeader.AvgTimePerFrame / 100000;

				while(dr.Read())
				{
					Bitmap b = Image.FromStream(new MemoryStream(dr.GetValue(1) as byte[])) as Bitmap;
					
					using (Graphics g = Graphics.FromImage(c))
					{
						g.InterpolationMode = InterpolationMode.HighQualityBicubic;
						g.CompositingQuality = CompositingQuality.HighQuality;
						g.SmoothingMode = SmoothingMode.HighQuality;
						g.PixelOffsetMode = PixelOffsetMode.HighQuality;
						g.DrawImage(b, 0, 0, c.Width, c.Height);
					}

					try
					{	
						ulong time = ((ulong)bmcount++ * TimeSpan.TicksPerSecond)/fps;
						sample = writer.GetSampleFromBitmap(c);
						writer.Writer.WriteSample(0, time, (uint)WMT_STREAM_SAMPLE_TYPE.WM_SF_CLEANPOINT, sample);
					}
					finally
					{
						Marshal.ReleaseComObject(sample);
						sample = null;
						b = null;
						GC.Collect();
					}
				}
			}
		}
Exemple #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (writer != null)
         {
             try
             {
                 writer.Dispose();
                 writer = null;
                 frame.Dispose();
                 frame = null;
                 Marshal.FreeHGlobal(MarshalToPointer(viHeader));
             }
             catch (Exception)
             {
                 // error handle
                 throw;
             }
         }
     }
 }
Exemple #3
0
		/// <summary>
		/// Saves the video.
		/// </summary>
		/// <param name="fileName">Name of the file.</param>
		/// <param name="profileFileName">Name of the profile file.</param>
		/// <param name="framesPerSecond">Frames per second.</param>
		/// <param name="bitmaps">Bitmaps.</param>
        public WmvEncoder(string profileFileName, ulong framesPerSecond)
        {
            try
            {
                WMEncoder encoder = new WMEncoder();
                IWMEncProfile2 profile = WMEncProfile.LoadEncodingProfile(encoder, profileFileName);
                WMEncProfile.ReleaseEncoder(ref encoder);

                writer = new WmvWriter();
                writer.SetProfile((IWMProfile)profile.SaveToIWMProfile());

                viHeader = new VideoInfoHeader();
                bool bret = writer.FindVideoInputFormat(0, MediaSubTypes.WMMEDIASUBTYPE_RGB24, ref viHeader, false);
                if (!bret) throw new Exception("FindVideoInputFormat error"); ;
                frame = new Bitmap((int)viHeader.bmiHeader.biWidth, (int)viHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);

                fps = framesPerSecond;
            }
            catch (Exception)
            {
                // error handle
                throw;
            }
        }
Exemple #4
0
		/// <summary>
		/// Saves the video.
		/// </summary>
		/// <param name="fileName">Name of the file.</param>
		/// <param name="profileFileName">Name of the profile file.</param>
		/// <param name="files">Files.</param>
		public static void SaveVideo(string fileName, string profileFileName, ulong framesPerSecond, string [] files)
		{
			WMEncoder encoder = new WMEncoder();
			IWMEncProfile2 profile = WMEncProfile.LoadEncodingProfile(encoder, profileFileName);
			WMEncProfile.ReleaseEncoder(ref encoder);
			
			using(WmvWriter writer = new WmvWriter())
			{
				
				writer.Initialize((IWMProfile)profile.SaveToIWMProfile(), fileName);
				
				VideoInfoHeader viHeader = new VideoInfoHeader();
				writer.FindVideoInputFormat(0, MediaSubTypes.WMMEDIASUBTYPE_RGB24, ref viHeader, false);
				writer.Start();

				INSSBuffer sample = null;
				int bmcount = 0;
				Bitmap frame = new Bitmap((int)viHeader.bmiHeader.biWidth, (int)viHeader.bmiHeader.biHeight, PixelFormat.Format24bppRgb);;
				ulong fps = framesPerSecond;	
				
				for(int i = 0; i < files.Length; i++)
				{
					if(files[i] != null)
					{		
						Bitmap bmp = new Bitmap(files[i]);
						using (Graphics g = Graphics.FromImage(frame))
						{
							g.InterpolationMode = InterpolationMode.HighQualityBicubic;
							g.CompositingQuality = CompositingQuality.HighQuality;
							g.SmoothingMode = SmoothingMode.HighQuality;
							g.PixelOffsetMode = PixelOffsetMode.HighQuality;
							g.DrawImage(bmp, 0, 0, frame.Width, frame.Height);
							Console.Out.Write(".");
						}

						// Now render to the movie
						try
						{	
							ulong time = ((ulong)bmcount++ * TimeSpan.TicksPerSecond)/fps;
							sample = writer.GetSampleFromBitmap(frame);
							writer.Writer.WriteSample(0, time, (uint)WMT_STREAM_SAMPLE_TYPE.WM_SF_CLEANPOINT, sample);
						}
						finally
						{													
							Marshal.ReleaseComObject(sample);
							sample = null;
							bmp = null;
							GC.Collect();
						}
					}
				}
			}
		}